Skip to content
Snippets Groups Projects
Commit fda65f0d authored by Matt Petro's avatar Matt Petro
Browse files

UWMOODLE-306 block course_overview_uwmoodle: Coding style fixes

parent 6a58f0eb
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,8 @@
* @author 2013 Matt Petro
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/blocks/course_overview_uwmoodle/locallib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
......@@ -133,7 +135,7 @@ class block_course_overview_uwmoodle extends block_base {
return true;
}
/**news
/**
* Fetch current term from CHUB. Throw exception on CHUB error.
*
* @return string|false term_code or false if none found.
......@@ -171,7 +173,7 @@ class block_course_overview_uwmoodle extends block_base {
return true;
}
/**news
/**
* locations where block can be displayed
*
* @return array
......
<?php
/**
* Course overview block for UW Moodle
*
* per-instance configuration
*
* @author 2013 Matt Petro
*/
defined('MOODLE_INTERNAL') || die;
class block_course_overview_uwmoodle_edit_form extends block_edit_form {
protected function specific_definition($mform) {
......@@ -7,6 +17,7 @@ class block_course_overview_uwmoodle_edit_form extends block_edit_form {
// Section header title according to language file.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
// Should the ongoing courses be merged into the term menu?
$mform->addElement('advcheckbox', 'config_combineongoing', get_string('combineongoing', 'block_course_overview_uwmoodle'), null, null, array(0, 1));
$mform->setDefault('config_nontermseparate', 0);
}
......
......@@ -22,6 +22,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Adapted for course_overview_uwmoodle
*
* @author 2013 Matt Petro
*/
defined('MOODLE_INTERNAL') || die;
/**
* Display overview for courses
*
......@@ -145,6 +153,12 @@ function block_course_overview_uwmoodle_group_courses_by_term($courses) {
return $terms;
}
/**
* Sort term array by ascending date
*
* @param array $terms keys are term_codes
* @return boolean
*/
function block_course_overview_uwmoodle_sort_term_array(&$terms) {
// Sort the terms with ongoing (code = 0) first, then in decreasing order
......
......@@ -21,6 +21,13 @@
* @copyright 2012 Adam Olley <adam.olley@netspot.com.au>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Adapted for course_overview_uwmoodle
*
* @author 2013 Matt Petro
*/
defined('MOODLE_INTERNAL') || die;
/**
......@@ -31,15 +38,52 @@ defined('MOODLE_INTERNAL') || die;
*/
class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
/**
* Generate course_block containing term courses
*
* @param array $terms array of the form $termcode => array of courses
* @param array $overviews list of course overviews
* @param string $selectedterm active termcode
* @return string
*/
public function course_block($terms, $overviews, $selectedterm) {
$html = '';
$html .= $this->begin_course_block(get_string('courses', 'block_course_overview_uwmoodle'), 'uwmm_mycourses_block');
$termcodes = array_keys($terms);
$html .= html_writer::start_tag('div', array('class' => 'lhs'));
$html .= $this->term_list($termcodes, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= html_writer::start_tag('div', array('class' => 'rhs'));
$html .= $this->course_overview_allterms($terms, $overviews, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= $this->end_course_block();
return $html;
}
/**
* Construct contents of course_overview block
* Generate course_block containing non-term courses
*
* @param array $courses list of courses in sorted order
* @param array $terms array of the form $termcode => array of courses
* @param array $overviews list of course overviews
* @return string html to be displayed in course_overview block
* @return string
*/
public function course_overview_allterms($terms, $overviews, $selectedterm) {
public function other_course_block($courses, $overviews) {
$html = '';
$html .= $this->begin_course_block(get_string('ongoingcourses', 'block_course_overview_uwmoodle'), 'uwmm_othercourses_block', 'ongoingcourses');
$html .= $this->course_overview($courses, $overviews, block_course_overview_uwmoodle::TERM_OTHER);
$html .= $this->end_course_block();
return $html;
}
/**
* Generate list of all courses in all terms
*
* @param array $terms array of the form $termcode => array of courses
* @param array $overviews list of course overviews
* @param string $selectedterm active termcode
* @return string
*/
protected function course_overview_allterms($terms, $overviews, $selectedterm) {
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'courselistcontainer', 'id' => 'uwmm_terms_content'));
......@@ -66,7 +110,15 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
return $html;
}
public function course_overview($courses, $overviews, $termcode) {
/**
* Generate output for a list of courses in a single term
*
* @param array $courses array of courses
* @param array $overviews list of course overviews
* @param string $termcode termcode for courses
* @return string
*/
protected function course_overview($courses, $overviews, $termcode) {
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'courselistcontainer'));
if (empty($courses)) {
......@@ -102,7 +154,14 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
return $html;
}
public function term_list($termcodes, $selectedterm) {
/**
* Generate terms menu
*
* @param array $termcodes array of termcodes
* @param string $selectedterm active termcode
* @return string
*/
protected function term_list($termcodes, $selectedterm) {
$thisurl = $this->page->url;
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'termscontainer'));
......@@ -122,7 +181,15 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
return $html;
}
public function begin_course_block($title, $id='', $helpidentifier='') {
/**
* Begin output of course_block
*
* @param string $title header text
* @param string $id css optional id for div
* @param string $helpidentifier optional help identifier
* @return string
*/
protected function begin_course_block($title, $id='', $helpidentifier='') {
$html = '';
$attributes = array('class' => 'courseblock clearfix');
if (!empty($id)) {
......@@ -140,95 +207,18 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
return $html;
}
public function end_course_block() {
$html = '';
$html .= html_writer::end_tag('div');
$html .= html_writer::end_tag('div');
return $html;
}
public function course_block($terms, $overviews, $selectedterm) {
/**
* End output of course_block.
*
* @return string
*/
protected function end_course_block() {
$html = '';
$html .= $this->begin_course_block(get_string('courses', 'block_course_overview_uwmoodle'), 'uwmm_mycourses_block');
$termcodes = array_keys($terms);
$html .= html_writer::start_tag('div', array('class' => 'lhs'));
$html .= $this->term_list($termcodes, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= html_writer::start_tag('div', array('class' => 'rhs'));
$html .= $this->course_overview_allterms($terms, $overviews, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= $this->end_course_block();
return $html;
}
public function other_course_block($courses, $overviews) {
$html = '';
$html .= $this->begin_course_block(get_string('ongoingcourses', 'block_course_overview_uwmoodle'), 'uwmm_othercourses_block', 'ongoingcourses');
$html .= $this->course_overview($courses, $overviews, block_course_overview_uwmoodle::TERM_OTHER);
$html .= $this->end_course_block();
return $html;
}
/**
* Render term selection box above the list of courses
*
* @param array $terms
* @param string $selectedterm
* @return string html to be displayed in course_overview block
*/
public function course_header($terms, $selectedterm) {
$output = '';
$thisterm = block_course_overview_uwmoodle_get_term_name($selectedterm);
$options = array();
$url = new moodle_url('/my/index.php');
$output .= $this->output->box_start('notice');
$output .= html_writer::start_tag('ul', array('class'=>'termlist'));
$output .= html_writer::start_tag('li');
$output .= get_string('selectterm', 'block_course_overview_uwmoodle');
$output .= html_writer::end_tag('li');
// sort by term date, ascending
ksort($terms, SORT_NUMERIC);
$firstitem = true;
foreach ($terms as $termcode => $courses) {
if ($termcode == block_course_overview_uwmoodle::TERM_OTHER) {
// non-term courses are shown regardless
continue;
}
$termname = block_course_overview_uwmoodle_get_term_name($termcode);
$output .= html_writer::start_tag('li');
if (!$firstitem) {
$output .= ' | ';
} else {
$firstitem = false;
}
if ($termcode == $selectedterm) {
$output .= html_writer::tag('span', $this->rarrow().$termname, array('class'=>'selectedterm'));
} else {
$output .= html_writer::tag('a', $termname, array('href' => $url->out(false, array('term'=>$termcode))));
}
$output .= html_writer::end_tag('li');
//$options[$termcode] = block_course_overview_uwmoodle_get_term_name($termcode);
}
//ksort($options, SORT_NUMERIC);
$output .= html_writer::end_tag('ul');
//$output .= $this->output->heading(get_string('mycoursesinterm', 'block_course_overview_uwmoodle', $thisterm), 2, 'sectiontitle');
$output .= $this->output->box_end();
//$url = new moodle_url('/my/index.php');
//$select = new single_select($url, 'term', $options, '', array('' => 'choosedots'));
//$select->set_label(get_string('selectterm', 'block_course_overview_uwmoodle'));
//$output .= $this->output->render($select);
return $output;
}
/**
* Render block footer
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment