From 5eafda657ec3d1d96f1f27145f7ec9cae2999cd0 Mon Sep 17 00:00:00 2001 From: James C <5689414+james-cnz@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:53:35 +1300 Subject: [PATCH] Moodle 4.5 subsections WIP 13 --- classes/output/courseformat/content.php | 2 +- .../output/courseformat/content/section.php | 19 ++++++------------- locallib.php | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index ef859e0..ac17c1c 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -361,7 +361,7 @@ private function get_sections_to_display(\course_modinfo $modinfo): array { if (!empty($thissectionextra->sectionbase->component)) { continue; } - $pageid = ($thissectionextra->levelsan != FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ? + $pageid = ($thissectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ? $thissectionextra->id : $thissectionextra->parentid; $onpage = ($pageid == $format->get_sectionid()); if ($onpage || $format->show_editor()) { diff --git a/classes/output/courseformat/content/section.php b/classes/output/courseformat/content/section.php index f5a8def..3f0628e 100644 --- a/classes/output/courseformat/content/section.php +++ b/classes/output/courseformat/content/section.php @@ -79,20 +79,14 @@ public function export_for_template(\renderer_base $output): \stdClass { * @return bool if the cm has name data */ protected function add_header_data(\stdClass &$data, \renderer_base $output): bool { - if (!empty($this->hidetitle)) { - return false; + $result = parent::add_header_data($data, $output); + if (!$result || !empty($section->component)) { + return $result; } - $section = $this->section; - $format = $this->format; - - $header = new $this->headerclass($format, $section); - $headerdata = $header->export_for_template($output); - - if ($section->id == $format->get_sectionid() && !empty($section->component)) { - $data->singleheader = $headerdata; - } else { - $data->header = $headerdata; + if (isset($data->singleheader) && !isset($data->header)) { + $data->header = $data->singleheader; + unset($data->singleheader); } return true; } @@ -160,7 +154,6 @@ protected function add_editor_data(\stdClass &$data, \renderer_base $output): bo $controlmenu = new $this->controlmenuclass($this->format, $this->section); $data->controlmenu = $controlmenu->export_for_template($output); } - return true; } diff --git a/locallib.php b/locallib.php index 4e34f4c..4232620 100644 --- a/locallib.php +++ b/locallib.php @@ -398,7 +398,7 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std $sections[$id]->level = ($sectionextra->levelsan >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC && $sectionextra->levelsan != $originlevel) ? FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC // Don't change topic level. - : $sectionextra->levelsan + $levelchange; + : max($sectionextra->levelsan + $levelchange, 0); } // Append rest of array. @@ -407,7 +407,7 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std $sections[$id] = new \stdClass; $sections[$id]->id = $id; $sections[$id]->visible = $sectionextra->visiblesan; - $sections[$id]->level = $sectionextra->levelsan; + $sections[$id]->level = max($sectionextra->levelsan, 0); } }