diff --git a/Changes.md b/Changes.md index 90d5e1d..f7a9fd6 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,14 @@ Version Information =================== +Version 404.1.1 - 22/09/2024 +---------------------------- +1. Show section zero if the section has meaningful content. +2. Fix single section page navigation. +3. Compromise with the Course Index that it will always refer to the main course page and the format + implement its own single page access and navigation. +4. Fix single section page navigation visibility. + Version 404.1.0 - 01/07/2024 ---------------------------- 1. Fix 'Error with Orphaned Sections when editing' - #151. diff --git a/classes/output/courseformat/content/sectionnavigation.php b/classes/output/courseformat/content/sectionnavigation.php index 2ef537d..059ff9c 100644 --- a/classes/output/courseformat/content/sectionnavigation.php +++ b/classes/output/courseformat/content/sectionnavigation.php @@ -68,26 +68,26 @@ public function export_for_template(\renderer_base $output): \stdClass { $back = $this->sectionno - 1; while ($back > 0 && empty($data->previousurl)) { - if ($canviewhidden || $sections[$back]->uservisible) { + if ($canviewhidden || $format->is_section_visible($back)) { if (!$sections[$back]->visible) { $data->previoushidden = true; } $data->previousname = get_section_name($course, $sections[$back]); - $data->previousurl = course_get_url($course, $back, ['navigation' => true]); + $data->previousurl = $format->get_view_url($back, ['navigation' => false]); $data->hasprevious = true; } $back--; } $forward = $this->sectionno + 1; - $numsections = course_get_format($course)->get_last_section_number(); + $numsections = $format->get_last_section_number(); while ($forward <= $numsections && empty($data->nexturl)) { - if ($canviewhidden || $sections[$forward]->uservisible) { + if ($canviewhidden || $format->is_section_visible($forward)) { if (!$sections[$forward]->visible) { $data->nexthidden = true; } $data->nextname = get_section_name($course, $sections[$forward]); - $data->nexturl = course_get_url($course, $forward, ['navigation' => true]); + $data->nexturl = $format->get_view_url($forward, ['navigation' => false]); $data->hasnext = true; } $forward++; diff --git a/classes/output/courseformat/content/sectionselector.php b/classes/output/courseformat/content/sectionselector.php index 1e8608b..4d42b85 100644 --- a/classes/output/courseformat/content/sectionselector.php +++ b/classes/output/courseformat/content/sectionselector.php @@ -64,9 +64,11 @@ public function export_for_template(\renderer_base $output): \stdClass { $numsections = $format->get_last_section_number(); while ($section <= $numsections) { $thissection = $modinfo->get_section_info($section); - $url = course_get_url($course, $section, ['navigation' => true]); - if ($thissection->uservisible && $url && $section != $data->currentsection) { - $sectionmenu[$url->out(false)] = get_section_name($course, $section); + $url = $format->get_view_url($section, ['navigation' => false]); + if ($url && $section != $data->currentsection) { + if ($format->is_section_visible($thissection)) { + $sectionmenu[$url->out(false)] = get_section_name($course, $section); + } } $section++; } @@ -76,6 +78,7 @@ public function export_for_template(\renderer_base $output): \stdClass { $select->formid = 'sectionmenu'; $data->selector = $output->render($select); + return $data; } } diff --git a/lib.php b/lib.php index 64725e8..f53b6b3 100644 --- a/lib.php +++ b/lib.php @@ -270,26 +270,29 @@ public function is_section_visible(section_info $section): bool { } $shown = parent::is_section_visible($section); if (($shown) && ($section->sectionnum == 0)) { - // Don't show section zero if no modules or all modules unavailable to user. - $showmovehere = ismoving($this->course->id); - if (!$showmovehere) { - global $PAGE; - $context = context_course::instance($this->course->id); - if (!($PAGE->user_is_editing() && has_capability('moodle/course:update', $context))) { - $modshown = false; - $modinfo = get_fast_modinfo($this->course); - - if (!empty($modinfo->sections[$section->section])) { - foreach ($modinfo->sections[$section->section] as $modnumber) { - $mod = $modinfo->cms[$modnumber]; - if ($mod->is_visible_on_course_page()) { - // At least one is. - $modshown = true; - break; + // Show section zero if summary has content, otherwise check modules. + if (empty(strip_tags($section->summary))) { + // Don't show section zero if no modules or all modules unavailable to user. + $showmovehere = ismoving($this->course->id); + if (!$showmovehere) { + global $PAGE; + $context = context_course::instance($this->course->id); + if (!($PAGE->user_is_editing() && has_capability('moodle/course:update', $context))) { + $modshown = false; + $modinfo = get_fast_modinfo($this->course); + + if (!empty($modinfo->sections[$section->section])) { + foreach ($modinfo->sections[$section->section] as $modnumber) { + $mod = $modinfo->cms[$modnumber]; + if ($mod->is_visible_on_course_page()) { + // At least one is. + $modshown = true; + break; + } } } + $shown = $modshown; } - $shown = $modshown; } } } @@ -417,11 +420,9 @@ public function get_view_url($section, $options = []) { $sectionno = $section; } if ((!empty($options['navigation'])) && $sectionno !== null) { - // Display section on separate page. - $sectioninfo = $this->get_section($sectionno); - return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]); - } - if ($this->uses_sections() && $sectionno !== null) { + // Unlike core, navigate to section on course page. + $url->set_anchor('section-'.$sectionno); + } else if ($this->uses_sections() && $sectionno !== null) { if ($this->coursedisplay == COURSE_DISPLAY_MULTIPAGE) { $url->param('section', $sectionno); } else { diff --git a/version.php b/version.php index 7b7104e..3795c62 100644 --- a/version.php +++ b/version.php @@ -30,9 +30,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024032802; +$plugin->version = 2024032803; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2024042200.00; // 4.4 (Build: 20240422). $plugin->supported = [404, 404]; $plugin->component = 'format_topcoll'; -$plugin->release = '404.1.0'; +$plugin->release = '404.1.1';