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

Improved the interface for the new courseoverview block.

parent 7fa28f62
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
/** /**
* Course overview block for UW Moodle * Course overview block for UW Moodle
* *
* This block improves on the course_summary block by presenting courses sorted by term. * This block improves on the default course_summary block by filtering courses by term.
* It also allows showing/hiding of terms and course news summaries.
* *
* The block is dependent on the UW enrollment plugins and is largely coped from the existing course_overview block. * The block is dependent on the UW enrollment plugins and is largely coped from the existing course_overview block.
* I've left copyright statements for the original authors on most files. * I've left copyright statements for the original authors on most files.
...@@ -28,6 +27,7 @@ ...@@ -28,6 +27,7 @@
*/ */
require_once($CFG->dirroot.'/blocks/course_overview_uwmoodle/locallib.php'); require_once($CFG->dirroot.'/blocks/course_overview_uwmoodle/locallib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
class block_course_overview_uwmoodle extends block_base { class block_course_overview_uwmoodle extends block_base {
/** /**
...@@ -55,13 +55,11 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -55,13 +55,11 @@ class block_course_overview_uwmoodle extends block_base {
$this->content = new stdClass(); $this->content = new stdClass();
$this->content->text = ''; $this->content->text = '';
$this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ...";;
$content = array();$this->content->text .=
profile_load_custom_fields($USER); profile_load_custom_fields($USER);
$courses = block_course_overview_uwmoodle_get_sorted_courses();
// Get user's courses and sort by term
$courses = block_course_overview_uwmoodle_get_sorted_courses();
$terms = block_course_overview_uwmoodle_group_courses_by_term($courses); $terms = block_course_overview_uwmoodle_group_courses_by_term($courses);
$currentterm = block_course_overview_uwmoodle_get_current_term(); $currentterm = block_course_overview_uwmoodle_get_current_term();
...@@ -73,11 +71,15 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -73,11 +71,15 @@ class block_course_overview_uwmoodle extends block_base {
if (!isset($terms[self::TERM_OTHER])) { if (!isset($terms[self::TERM_OTHER])) {
$terms[self::TERM_OTHER] = array(); $terms[self::TERM_OTHER] = array();
} }
// If selectedterm is not valid, select currentterm
if (!isset($terms[$selectedterm])) { if (!isset($terms[$selectedterm])) {
$selectedterm = $currentterm; $selectedterm = $currentterm;
} }
// Always display non-term courses in addition to selected term.
$displayedcourses = $terms[self::TERM_OTHER] + $terms[$selectedterm]; $displayedcourses = $terms[self::TERM_OTHER] + $terms[$selectedterm];
// Get course overviews
$overviews = block_course_overview_uwmoodle_get_overviews($displayedcourses); $overviews = block_course_overview_uwmoodle_get_overviews($displayedcourses);
$renderer = $this->page->get_renderer('block_course_overview_uwmoodle'); $renderer = $this->page->get_renderer('block_course_overview_uwmoodle');
...@@ -88,11 +90,12 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -88,11 +90,12 @@ class block_course_overview_uwmoodle extends block_base {
} }
$this->content->text .= $renderer->course_header($terms, $selectedterm); $this->content->text .= $renderer->course_header($terms, $selectedterm);
$this->content->text .= $renderer->course_overview($terms[$selectedterm], $overviews); $this->content->text .= $renderer->course_block($selectedterm, $terms[$selectedterm], $overviews);
if (!empty($terms[self::TERM_OTHER])) { if (!empty($terms[self::TERM_OTHER])) {
$this->content->text .= $renderer->other_header(); $this->content->text .= $renderer->other_course_block($terms[self::TERM_OTHER], $overviews);
$this->content->text .= $renderer->course_overview($terms[self::TERM_OTHER], $overviews);
} }
$this->content->footer = $renderer->footer();
return $this->content; return $this->content;
} }
...@@ -116,23 +119,15 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -116,23 +119,15 @@ class block_course_overview_uwmoodle extends block_base {
return false; return false;
} }
if ($currentterm === $oldcurrentterm) { if ($currentterm && $currentterm != $oldcurrentterm) {
// no change, so return // store new term
return true; mtrace('new current term: '.$currentterm);
set_config('currentterm', $currentterm, 'block_course_overview_uwmoodle');
} }
mtrace('new current term: '.$currentterm);
// New term, so clear user preferences for both current and previous term
if ($oldcurrentterm) {
$DB->delete_records('user_preferences', array('name'=> 'block_course_overview_uwmoodle-show-term-'.$oldcurrentterm));
}
$DB->delete_records('user_preferences', array('name'=> 'block_course_overview_uwmoodle-show-term-'.$currentterm));
set_config('currentterm', $currentterm, 'block_course_overview_uwmoodle');
return true; return true;
} }
/** /**news
* Fetch current term from CHUB. Throw exception on CHUB error. * Fetch current term from CHUB. Throw exception on CHUB error.
* *
* @return string|false term_code or false if none found. * @return string|false term_code or false if none found.
...@@ -170,7 +165,7 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -170,7 +165,7 @@ class block_course_overview_uwmoodle extends block_base {
return true; return true;
} }
/** /**news
* locations where block can be displayed * locations where block can be displayed
* *
* @return array * @return array
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'UW Moodle course overview'; $string['pluginname'] = 'UW Moodle course overview';
$string['mycoursesinterm'] = 'My courses in term:'; $string['mycoursesinterm'] = '{$a} courses';
$string['othercourses'] = 'Other courses'; $string['nocourses'] = 'You are not enrolled in any courses for this term';
$string['nocourses'] = 'You are not enrolled in any courses for this term.'; $string['ongoingcourses'] = 'Ongoing courses';
$string['selectterm'] = 'Select a term: ';
$string['activityoverview'] = 'You have {$a}s that need attention'; $string['activityoverview'] = 'You have {$a}s that need attention';
$string['alwaysshowall'] = 'Always Show All'; $string['alwaysshowall'] = 'Always Show All';
......
...@@ -86,7 +86,7 @@ function block_course_overview_uwmoodle_get_child_shortnames($courseid) { ...@@ -86,7 +86,7 @@ function block_course_overview_uwmoodle_get_child_shortnames($courseid) {
* @return array list of sorted courses grouped by term. * @return array list of sorted courses grouped by term.
*/ */
function block_course_overview_uwmoodle_get_sorted_courses() { function block_course_overview_uwmoodle_get_sorted_courses() {
global $USER, $DB; global $USER;
$courses = enrol_get_my_courses('id, shortname, fullname, modinfo, sectioncache', 'fullname', 0); $courses = enrol_get_my_courses('id, shortname, fullname, modinfo, sectioncache', 'fullname', 0);
$site = get_site(); $site = get_site();
...@@ -103,7 +103,20 @@ function block_course_overview_uwmoodle_get_sorted_courses() { ...@@ -103,7 +103,20 @@ function block_course_overview_uwmoodle_get_sorted_courses() {
} }
} }
// Find the termcode for each course return $courses;
}
/**
* Organize courses into terms, maintaining existing sorting inside each term
*
* @param array $courses user courses
* @return array
*/
function block_course_overview_uwmoodle_group_courses_by_term($courses) {
global $DB;
// Find the termcodes for each course
$courseterms = array();
if (!empty($courses)) { if (!empty($courses)) {
$courseids = array(); $courseids = array();
foreach ($courses as $course) { foreach ($courses as $course) {
...@@ -113,26 +126,17 @@ function block_course_overview_uwmoodle_get_sorted_courses() { ...@@ -113,26 +126,17 @@ function block_course_overview_uwmoodle_get_sorted_courses() {
$select = "enrol='wisc' AND courseid $insql"; $select = "enrol='wisc' AND courseid $insql";
$enrols = $DB->get_records_select('enrol', $select, $inparams, '', 'id,courseid,customchar1'); $enrols = $DB->get_records_select('enrol', $select, $inparams, '', 'id,courseid,customchar1');
foreach ($enrols as $enrol) { foreach ($enrols as $enrol) {
if (empty($courses[$enrol->courseid]->term) || $courses[$enrol->courseid]->term < $enrol->customchar1) { $courseterms[$enrol->courseid][$enrol->customchar1] = true;
$courses[$enrol->courseid]->term = $enrol->customchar1;
}
} }
} }
return $courses;
}
/** // Sort the courses by termcode. Note that one course can be in multiple terms.
* Group courses by term
*
* @param array $courses user courses
* @return array
*/
function block_course_overview_uwmoodle_group_courses_by_term($courses) {
// Organize courses into terms, maintaining existing sorting inside each term
$terms = array(); $terms = array();
foreach ($courses as $course) { foreach ($courses as $course) {
if (!empty($course->term)) { if (!empty($courseterms[$course->id])) {
$terms[$course->term][$course->id] = $course; foreach ($courseterms[$course->id] as $termcode => $unused) {
$terms[$termcode][$course->id] = $course;
}
} else { } else {
$terms[block_course_overview_uwmoodle::TERM_OTHER][$course->id] = $course; $terms[block_course_overview_uwmoodle::TERM_OTHER][$course->id] = $course;
} }
......
...@@ -45,7 +45,7 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base { ...@@ -45,7 +45,7 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
$html .= html_writer::start_tag('div', array('id' => 'course_list_uwmoodle')); $html .= html_writer::start_tag('div', array('id' => 'course_list_uwmoodle'));
if (empty($courses)) { if (empty($courses)) {
$html .= $this->output->box_start('coursebox'); $html .= $this->output->box_start('coursebox');
$html .= get_string('nocourses','block_course_overview_uwmoodle'); $html .= '<h2>'.get_string('nocourses','block_course_overview_uwmoodle').'</h2>';
$html .= $this->output->box_end(); $html .= $this->output->box_end();
} else { } else {
foreach ($courses as $key => $course) { foreach ($courses as $key => $course) {
...@@ -76,32 +76,110 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base { ...@@ -76,32 +76,110 @@ class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
return $html; return $html;
} }
public function begin_course_block($title) {
$html = $this->output->box_start('block');
$html .= $this->output->box_start('header');
$html .= $this->output->box_start('title');
$html .= $this->output->heading($title, 2, 'sectiontitle');
$html .= $this->output->box_end();
$html .= $this->output->box_end();
$html .= $this->output->box_start('content');
return $html;
}
public function end_course_block() {
$html = '';
$html .= $this->output->box_end();
$html .= $this->output->box_end();
return $html;
}
public function course_block($selectedterm, $courses, $overviews) {
$termstr = block_course_overview_uwmoodle_get_term_name($selectedterm);
$title = get_string('mycoursesinterm', 'block_course_overview_uwmoodle', $termstr);
$html = $this->begin_course_block($title);
$html .= $this->course_overview($courses, $overviews);
$html .= $this->end_course_block();
return $html;
}
public function other_course_block($courses, $overviews) {
$html = $this->begin_course_block(get_string('ongoingcourses', 'block_course_overview_uwmoodle'));
$html .= $this->course_overview($courses, $overviews);
$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) { public function course_header($terms, $selectedterm) {
$output = $this->output->box_start('notice'); $output = '';
$thisterm = block_course_overview_uwmoodle_get_term_name($selectedterm);
$options = array(); $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) { foreach ($terms as $termcode => $courses) {
if ($termcode == block_course_overview_uwmoodle::TERM_OTHER) { if ($termcode == block_course_overview_uwmoodle::TERM_OTHER) {
// non-term courses are shown regardless // non-term courses are shown regardless
continue; continue;
} }
$options[$termcode] = block_course_overview_uwmoodle_get_term_name($termcode); $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);
$url = new moodle_url('/my/index.php'); //ksort($options, SORT_NUMERIC);
$select = new single_select($url, 'term', $options, $selectedterm, array());
$select->set_label(get_string('mycoursesinterm', 'block_course_overview_uwmoodle'));
$output .= $this->output->render($select);
$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(); $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; return $output;
} }
public function other_header() { /**
$output = $this->output->box_start('notice'); * Render block footer
$output .= $this->output->heading(get_string('othercourses', 'block_course_overview_uwmoodle'), 2, 'sectiontitle'); *
$output .= $this->output->box_end(); * @return string html to be displayed in course_overview block
*/
public function footer() {
global $CFG;
$output = html_writer::tag('a', get_string("fulllistofcourses"), array('href' => "$CFG->wwwroot/course/index.php"));
$output .= ' ...';
return $output; return $output;
} }
......
...@@ -10,9 +10,33 @@ ...@@ -10,9 +10,33 @@
margin: 5px 0; margin: 5px 0;
} }
.block_course_overview_uwmoodle .block {
margin-bottom: 10px;
}
.block_course_overview_uwmoodle .coursebox { .block_course_overview_uwmoodle .coursebox {
padding: 15px; padding: 5px 15px 5px 15px;
width: auto; width: auto;
margin: 15px 0;
}
.block_course_overview_uwmoodle .termlist {
list-style-type:none;
margin:20px 0 0 0;
padding:0;
font-size:120%;
}
.block_course_overview_uwmoodle .termlist li {
display:inline;
}
.block_course_overview_uwmoodle .termlist .selectedterm {
/*color: #0000aa;*/
font-weight: bold;
font-size:100%;
/*border: 1px solid #000000;*/
padding: 5px;
} }
.block_course_overview_uwmoodle .profilepicture { .block_course_overview_uwmoodle .profilepicture {
...@@ -39,22 +63,22 @@ ...@@ -39,22 +63,22 @@
.block_course_overview_uwmoodle .content h2.title { .block_course_overview_uwmoodle .content h2.title {
float: left; float: left;
margin: 0 0 .5em 0; margin: 0;
position: relative; position: relative;
} }
.block_course_overview_uwmoodle .activity_info {
margin: 0.5em 0 0 1em;
}
.block_course_overview_uwmoodle .content h2.sectiontitle { .block_course_overview_uwmoodle .content h2.sectiontitle {
color: #444444; /*color: #444444;*/
margin: 2em 0 0; /*margin: 2em 0 0;*/
} }
.block_course_overview_uwmoodle .content label { .block_course_overview_uwmoodle .content label {
color: #444444; color: #444444;
font-size: 120%;
font-weight: bold;
} }
.collapsibleregioncaption { .collapsibleregioncaption {
cursor: pointer; cursor: pointer;
} }
font-size: 123.1%;
.dir-rtl .block_course_overview_uwmoodle .content h2.title { .dir-rtl .block_course_overview_uwmoodle .content h2.title {
float:right; float:right;
} }
...@@ -93,30 +117,7 @@ font-size: 123.1%; ...@@ -93,30 +117,7 @@ font-size: 123.1%;
.editing .block_course_overview_uwmoodle .movedownspacer { .editing .block_course_overview_uwmoodle .movedownspacer {
float: left; float: left;
width: 14px; width: 14px;
}.block_course_overview_uwmoodle_uwmoodle .treeitem {
background-position: 0 40%;
background-repeat: no-repeat;
padding-left: 18px;
text-align: left;
} }
.block_course_overview_uwmoodle_uwmoodle .treeitem.term {background-image: url([[pix:t/expanded]]);}
.block_course_overview_uwmoodle_uwmoodle li.collapsed .treeitem.term {background-image: url([[pix:t/collapsed]]);}
.block_course_overview_uwmoodle_uwmoodle .treeitem.coursenews {background-image: url([[pix:t/switch_minus]]);}
.block_course_overview_uwmoodle_uwmoodle li.collapsed .treeitem.coursenews {background-image: url([[pix:t/switch_plus]]);}
.block_course_overview_uwmoodle_uwmoodle li.collapsed ul {display: none;}
.block_course_overview_uwmoodle_uwmoodle li ul {margin: 0;padding-left:16px;}
.block_course_overview_uwmoodle_uwmoodle .coursebox h3 {margin-left:10px;}
.block_course_overview_uwmoodle_uwmoodle h3 {font-size:1.1em;}
/*.block_course_overview_uwmoodle_uwmoodle .miscterm .term {font-weight:bold;}*/
.block_course_overview_uwmoodle_uwmoodle .term {color:#000;font-weight:normal;}
.block_course_overview_uwmoodle_uwmoodle .shownews {float:right;color:#333;font-weight:normal;margin-right:1em;font-size:91%;}
.block_course_overview_uwmoodle_uwmoodle a:focus,
.block_course_overview_uwmoodle_uwmoodle a:hover,
.block_course_overview_uwmoodle_uwmoodle a:active {outline:none;}
.block_course_overview_uwmoodle_uwmoodle ul.treelist {list-style:none outside none;}
.block_course_overview_uwmoodle_uwmoodle .courselist {margin:0;padding:0;}
.block_course_overview_uwmoodle_uwmoodle ul {margin:0 1em 0 0;}
.dir-rtl.editing .block_course_overview_uwmoodle .movedownspacer { .dir-rtl.editing .block_course_overview_uwmoodle .movedownspacer {
float:right; float:right;
} }
......
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