MDL-32767 - course: Add a summary of activities

When in single-page summary mode
This commit is contained in:
Dan Poltawski 2012-05-30 16:25:43 +08:00
parent f8dfdb524b
commit d87debaa3e
2 changed files with 51 additions and 3 deletions

View file

@ -267,9 +267,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @param array $mods course modules indexed by id (from get_all_mods)
* @return string HTML to output.
*/
protected function section_summary($section, $course) {
protected function section_summary($section, $course, $mods) {
// If section is hidden then display grey section link
$classattr = 'section-summary clearfix';
If (!$section->visible) {
@ -288,14 +289,60 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$o.= html_writer::start_tag('div', array('class' => 'summarytext'));
$o.= $this->format_summary_text($section);
$o.= html_writer::end_tag('div');
$o.= $this->section_activity_summary($section, $mods);
$o .= $this->section_availability_message($section);
$o.= $this->section_availability_message($section);
$o.= html_writer::end_tag('li');
return $o;
}
/**
* Generate a summary of the activites in a section
*
* @param stdClass $section The course_section entry from DB
* @param array $mods course modules indexed by id (from get_all_mods)
* @return string HTML to output.
*/
private function section_activity_summary($section, $mods) {
if (empty($section->sequence)) {
return '';
}
// Generate array with count of activities in this section:
$sectionmods = array();
$modsequence = explode(',', $section->sequence);
foreach ($modsequence as $cmid) {
$thismod = $mods[$cmid];
if ($thismod->uservisible) {
if (isset($sectionmods[$thismod->modname])) {
$sectionmods[$thismod->modname]['count']++;
} else {
$sectionmods[$thismod->modname]['name'] = $thismod->modplural;
$sectionmods[$thismod->modname]['count'] = 1;
}
}
}
if (empty($sectionmods)) {
// No sections
return '';
}
// Output section activities summary:
$o = '';
$o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
foreach ($sectionmods as $mod) {
$o.= html_writer::start_tag('span', array('class' => 'activity-count'));
$o.= $mod['name'].': '.$mod['count'];
$o.= html_writer::end_tag('span');
}
$o.= html_writer::end_tag('div');
return $o;
}
/**
* If section is not visible to current user, display the message about that
* ('Not available until...', that sort of thing). Otherwise, returns blank.
@ -604,7 +651,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->section_summary($thissection, $course);
echo $this->section_summary($thissection, $course, $mods);
} else {
echo $this->section_header($thissection, $course, false);
if ($thissection->uservisible) {

View file

@ -11,6 +11,7 @@
.course-content .section-summary { border: 1px solid #DDD; margin-top: 5px; list-style: none; }
.course-content .section-summary .section-title { margin: 2px 5px 2px 5px; }
.course-content .section-summary .summarytext { margin: 2px 5px 2px 5px; }
.course-content .section-summary .section-summary-activities .activity-count {margin-right: 10px;}
.course-content .single-section { margin-top: 1em; }
.course-content .single-section .section-navigation { display: block; padding: 0.5em; margin-bottom: -0.5em; }
.course-content .single-section .section-navigation .title { font-weight: bold; font-size: 108%; }