MDL-32767 - course: Add a summary of activities
authorDan Poltawski <dan@moodle.com>
Wed, 30 May 2012 08:25:43 +0000 (16:25 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 12 Jun 2012 05:13:52 +0000 (13:13 +0800)
When in single-page summary mode

course/format/renderer.php
theme/base/style/course.css

index f0dd91f..e8d1418 100644 (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) {
index 5a5fc1a..abf5031 100644 (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%; }