diff --git a/Changes.md b/Changes.md index ee4c3f1..b609f99 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ Version 401.1.2 - TBR ---------------------------- +1. Fix 'Orphaned Section still appear in Index Drawer' - #146. Version 401.1.1 - 14/08/2023 ---------------------------- diff --git a/lib.php b/lib.php index ffb1c2e..1256aa5 100644 --- a/lib.php +++ b/lib.php @@ -230,6 +230,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());