From 5087a1f2a7572e6b84f18482c6f17be2998c4002 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:18:29 +0000 Subject: [PATCH] Fix 'Orphaned Section still appear in Index Drawer' - #146. --- Changes.md | 1 + lib.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Changes.md b/Changes.md index d967942..5ae3381 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ Version 402.1.2 - TBR ---------------------------- +1. Fix 'Orphaned Section still appear in Index Drawer' - #146. Version 402.1.1 - 14/08/2023 ---------------------------- diff --git a/lib.php b/lib.php index ea5a824..f710d04 100644 --- a/lib.php +++ b/lib.php @@ -235,6 +235,28 @@ public function get_topcoll_section_name($course, $section, $additional) { return $o; } + /** + * Returns if an specific section is visible to the current user. + * + * Formats can overrride this method to implement any special section logic. + * + * @param section_info $section the section modinfo + * @return bool; + */ + public function is_section_visible(section_info $section): bool { + if ($section->section > $this->get_last_section_number()) { + // Stealth section. + global $PAGE; + $context = context_course::instance($this->course->id); + if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) { + $modinfo = get_fast_modinfo($this->course); + // If the stealth section has modules then is visible. + return (!empty($modinfo->sections[$section->section])); + } + } + return parent::is_section_visible($section); + } + public function get_section_dates($section, $course = null, $tcsettings = null) { if (empty($tcsettings) && empty($course)) { return $this->format_topcoll_get_section_dates($section, $this->get_course());