diff --git a/course/format/renderer.php b/course/format/renderer.php index 74baa080b44..26f28c213b2 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -271,7 +271,7 @@ 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_fast_modinfo()->get_cms()) + * @param array $mods (argument not used) * @return string HTML to output. */ protected function section_summary($section, $course, $mods) { @@ -303,7 +303,7 @@ 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, $course, $mods); + $o.= $this->section_activity_summary($section, $course, null); $o.= $this->section_availability_message($section); @@ -318,11 +318,12 @@ abstract class format_section_renderer_base extends plugin_renderer_base { * * @param stdClass $section The course_section entry from DB * @param stdClass $course the course record from DB - * @param array $mods course modules indexed by id (from get_fast_modinfo()->get_cms()) + * @param array $mods (argument not used) * @return string HTML to output. */ private function section_activity_summary($section, $course, $mods) { - if (empty($section->sequence)) { + $modinfo = get_fast_modinfo($course); + if (empty($modinfo->sections[$section->section])) { return ''; } @@ -332,9 +333,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base { $complete = 0; $cancomplete = isloggedin() && !isguestuser(); $completioninfo = new completion_info($course); - $modsequence = explode(',', $section->sequence); - foreach ($modsequence as $cmid) { - $thismod = $mods[$cmid]; + foreach ($modinfo->sections[$section->section] as $cmid) { + $thismod = $modinfo->cms[$cmid]; if ($thismod->modname == 'label') { // Labels are special (not interesting for students)! @@ -343,9 +343,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base { if ($thismod->uservisible) { if (isset($sectionmods[$thismod->modname])) { + $sectionmods[$thismod->modname]['name'] = $thismod->modplural; $sectionmods[$thismod->modname]['count']++; } else { - $sectionmods[$thismod->modname]['name'] = $thismod->modplural; + $sectionmods[$thismod->modname]['name'] = $thismod->modfullname; $sectionmods[$thismod->modname]['count'] = 1; } if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) { @@ -531,26 +532,25 @@ abstract class format_section_renderer_base extends plugin_renderer_base { * Output the html for a single section page . * * @param stdClass $course The course entry from DB - * @param array $sections The course_sections entries from the DB - * @param array $mods used for print_section() - * @param array $modnames used for print_section() - * @param array $modnamesused used for print_section() + * @param array $sections (argument not used) + * @param array $mods (argument not used) + * @param array $modnames (argument not used) + * @param array $modnamesused (argument not used) * @param int $displaysection The section number in the course which is being displayed */ public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) { global $PAGE; - // Can we view the section in question? - $context = context_course::instance($course->id); - $canviewhidden = has_capability('moodle/course:viewhiddensections', $context); + $modinfo = get_fast_modinfo($course); - if (!isset($sections[$displaysection])) { + // Can we view the section in question? + if (!($sectioninfo = $modinfo->get_section_info($displaysection))) { // This section doesn't exist print_error('unknowncoursesection', 'error', null, $course->fullname); return; } - if (!$sections[$displaysection]->visible && !$canviewhidden) { + if (!$sectioninfo->uservisible) { if (!$course->hiddensections) { echo $this->start_section_list(); echo $this->section_hidden($displaysection); @@ -562,15 +562,13 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // Copy activity clipboard.. echo $this->course_activity_clipboard($course, $displaysection); - - // General section if non-empty. - $thissection = $sections[0]; - if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) { + $thissection = $modinfo->get_section_info(0); + if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) { echo $this->start_section_list(); echo $this->section_header($thissection, $course, true, $displaysection); - print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection); + print_section($course, $thissection, null, null, true, "100%", false, $displaysection); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, $modnames, false, false, $displaysection); + print_section_add_menus($course, 0, null, false, false, $displaysection); } echo $this->section_footer(); echo $this->end_section_list(); @@ -579,34 +577,35 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // Start single-section div echo html_writer::start_tag('div', array('class' => 'single-section')); + // The requested section page. + $thissection = $modinfo->get_section_info($displaysection); + // Title with section navigation links. - $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection); + $sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection); $sectiontitle = ''; $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock')); $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left')); $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right')); // Title attributes $titleattr = 'mdl-align title'; - if (!$sections[$displaysection]->visible) { + if (!$thissection->visible) { $titleattr .= ' dimmed_text'; } - $sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr)); + $sectiontitle .= html_writer::tag('div', get_section_name($course, $displaysection), array('class' => $titleattr)); $sectiontitle .= html_writer::end_tag('div'); echo $sectiontitle; // Now the list of sections.. echo $this->start_section_list(); - // The requested section page. - $thissection = $sections[$displaysection]; echo $this->section_header($thissection, $course, true, $displaysection); // Show completion help icon. $completioninfo = new completion_info($course); echo $completioninfo->display_help_icon(); - print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection); + print_section($course, $thissection, null, null, true, '100%', false, $displaysection); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection); + print_section_add_menus($course, $displaysection, null, false, false, $displaysection); } echo $this->section_footer(); echo $this->end_section_list(); @@ -629,14 +628,16 @@ abstract class format_section_renderer_base extends plugin_renderer_base { * Output the html for a multiple section page * * @param stdClass $course The course entry from DB - * @param array $sections The course_sections entries from the DB - * @param array $mods used for print_section() - * @param array $modnames used for print_section() - * @param array $modnamesused used for print_section() + * @param array $sections (argument not used) + * @param array $mods (argument not used) + * @param array $modnames (argument not used) + * @param array $modnamesused (argument not used) */ public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) { global $PAGE; + $modinfo = get_fast_modinfo($course); + $context = context_course::instance($course->id); // Title with completion help icon. $completioninfo = new completion_info($course); @@ -649,32 +650,22 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // Now the list of sections.. echo $this->start_section_list(); - // General section if non-empty. - $thissection = $sections[0]; - unset($sections[0]); - if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) { - echo $this->section_header($thissection, $course, false, 0); - print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0); - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, $modnames, false, false, 0); + foreach ($modinfo->get_section_info_all() as $section => $thissection) { + if ($section == 0) { + // 0-section is displayed a little different then the others + if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) { + echo $this->section_header($thissection, $course, false, 0); + print_section($course, $thissection, null, null, true, "100%", false, 0); + if ($PAGE->user_is_editing()) { + print_section_add_menus($course, 0, null, false, false, 0); + } + echo $this->section_footer(); + } + continue; } - echo $this->section_footer(); - } - - $canviewhidden = has_capability('moodle/course:viewhiddensections', $context); - for ($section = 1; $section <= $course->numsections; $section++) { - if (!empty($sections[$section])) { - $thissection = $sections[$section]; - } else { - // This will create a course section if it doesn't exist.. - $thissection = get_course_section($section, $course->id); - - // The returned section is only a bare database object rather than - // a section_info object - we will need at least the uservisible - // field in it. - $thissection->uservisible = true; - $thissection->availableinfo = null; - $thissection->showavailability = 0; + if ($section > $course->numsections) { + // activities inside this section are 'orphaned', this section will be printed as 'stealth' below + continue; } // Show the section if the user is permitted to access it, OR if it's not available // but showavailability is turned on @@ -687,36 +678,33 @@ abstract class format_section_renderer_base extends plugin_renderer_base { echo $this->section_hidden($section); } - unset($sections[$section]); continue; } if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) { // Display section summary only. - echo $this->section_summary($thissection, $course, $mods); + echo $this->section_summary($thissection, $course, null); } else { echo $this->section_header($thissection, $course, false, 0); if ($thissection->uservisible) { - print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0); + print_section($course, $thissection, null, null, true, "100%", false, 0); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $section, $modnames, false, false, 0); + print_section_add_menus($course, $section, null, false, false, 0); } } echo $this->section_footer(); } - - unset($sections[$section]); } if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) { // Print stealth sections if present. - $modinfo = get_fast_modinfo($course); - foreach ($sections as $section => $thissection) { - if (empty($modinfo->sections[$section])) { + foreach ($modinfo->get_section_info_all() as $section => $thissection) { + if ($section <= $course->numsections or empty($modinfo->sections[$section])) { + // this is not stealth section or it is empty continue; } echo $this->stealth_section_header($section); - print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection); + print_section($course, $thissection, null, null, true, "100%", false, 0); echo $this->stealth_section_footer(); } diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 51acd387461..e69ac91d532 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -44,12 +44,20 @@ if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) course_set_marker($course->id, $marker); } +// make sure all sections are created +$modinfo = get_fast_modinfo($course); +for ($sectionnum = 0; $sectionnum <= $course->numsections; $sectionnum++) { + if (!$modinfo->get_section_info($sectionnum)) { + get_course_section($sectionnum, $course->id); + } +} + $renderer = $PAGE->get_renderer('format_topics'); if (!empty($displaysection)) { - $renderer->print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection); + $renderer->print_single_section_page($course, null, null, null, null, $displaysection); } else { - $renderer->print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused); + $renderer->print_multiple_section_page($course, null, null, null, null); } // Include course format js module diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 2f0eb51f4d9..b35a327e790 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -37,12 +37,20 @@ if ($week = optional_param('week', 0, PARAM_INT)) { } // End backwards-compatible aliasing.. +// make sure all sections are created +$modinfo = get_fast_modinfo($course); +for ($sectionnum = 0; $sectionnum <= $course->numsections; $sectionnum++) { + if (!$modinfo->get_section_info($sectionnum)) { + get_course_section($sectionnum, $course->id); + } +} + $renderer = $PAGE->get_renderer('format_weeks'); if (!empty($displaysection)) { - $renderer->print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection); + $renderer->print_single_section_page($course, null, null, null, null, $displaysection); } else { - $renderer->print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused); + $renderer->print_multiple_section_page($course, null, null, null, null); } $PAGE->requires->js('/course/format/weeks/format.js'); diff --git a/course/lib.php b/course/lib.php index 1a246a20ab4..3f3cbe5b9f6 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1332,9 +1332,9 @@ function get_print_section_cm_text(cm_info $cm, $course) { * Prints a section full of activity modules * * @param stdClass $course The course - * @param stdClass $section The section - * @param array $mods The modules in the section - * @param array $modnamesused An array containing the list of modules and their names + * @param stdClass|section_info $section The section object containing properties id and section + * @param array $mods (argument not used) + * @param array $modnamesused (argument not used) * @param bool $absolute All links are absolute * @param string $width Width of the container * @param bool $hidecompletion Hide completion status @@ -1353,7 +1353,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, static $strmovehere; static $strmovefull; static $strunreadpostsone; - static $modulenames; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); @@ -1364,7 +1363,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); } - $modulenames = array(); $initialised = true; } @@ -1372,62 +1370,37 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $completioninfo = new completion_info($course); //Accessibility: replace table with list