From 25c1c730c4b84d5216f5e244abf42b5760aeb95a Mon Sep 17 00:00:00 2001 From: james-cnz <5689414+james-cnz@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:38:25 +1200 Subject: [PATCH] Moodle 4.5 subsections WIP 5 --- .../output/courseformat/content/section.php | 31 ++++--------------- .../courseformat/content/section/header.php | 31 +++++-------------- lib.php | 8 +++-- 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/classes/output/courseformat/content/section.php b/classes/output/courseformat/content/section.php index 41be6ae..70a37ca 100644 --- a/classes/output/courseformat/content/section.php +++ b/classes/output/courseformat/content/section.php @@ -62,34 +62,15 @@ public function __construct(course_format $format, \section_info $section) { * @return \stdClass data context for a mustache template */ public function export_for_template(\renderer_base $output): \stdClass { - global $PAGE; - - $format = $this->format; - $course = $format->get_course(); $section = $this->section; $sectionextra = $this->fmtsectionextra; - $summary = new $this->summaryclass($format, $section); - - $data = (object)[ - 'num' => $section->section ?? '0', - 'id' => $section->id, - 'sectionreturnid' => $section->section, // CHANGED. - 'insertafter' => false, - 'summary' => $summary->export_for_template($output), - 'highlightedlabel' => $format->get_section_highlighted_name(), - 'sitehome' => $course->id == SITEID, - 'editing' => $PAGE->user_is_editing(), - 'levelsan' => $sectionextra->levelsan, - ]; - - $haspartials = []; - $haspartials['availability'] = $this->add_availability_data($data, $output); - $haspartials['visibility'] = $this->add_visibility_data($data, $output); - $haspartials['editor'] = $this->add_editor_data($data, $output); - $haspartials['header'] = $this->add_header_data($data, $output); - $haspartials['cm'] = $this->add_cm_data($data, $output); - $this->add_format_data($data, $haspartials, $output); + $data = parent::export_for_template($output); + + $data->sectionreturnid = $section->section; //TODO: Unset? + $data->sectionreturnnum = $section->section; + unset($data->displayonesection); + $data->levelsan = $sectionextra->levelsan; return $data; } diff --git a/classes/output/courseformat/content/section/header.php b/classes/output/courseformat/content/section/header.php index 80e7a6f..5f2cf4c 100644 --- a/classes/output/courseformat/content/section/header.php +++ b/classes/output/courseformat/content/section/header.php @@ -58,46 +58,29 @@ public function __construct(\format_multitopic $format, \section_info $section) * @return \stdClass data context for a mustache template */ public function export_for_template(\renderer_base $output): \stdClass { - global $CFG; + global $CFG; // ADDED. $format = $this->format; $section = $this->section; $sectionextra = $this->fmtsectionextra; $course = $format->get_course(); - $data = (object)[ - 'num' => $section->section, - 'id' => $section->id, - ]; + $data = parent::export_for_template($output); + + unset($data->displayonesection); $data->title = $output->section_title_without_link($section, $course); - if ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) { // CHANGED link condition. + if ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC && empty($section->component)) { $data->title = $output->section_title($section, $course); } - // REMOVED stealth sections. - - // ADDED. $data->fmticon = $sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC ? 'icon fa fa-folder-o fa-fw' : 'icon fa fa-list fa-fw'; - // END ADDED. - - if (!$section->visible) { - $data->ishidden = true; - } - - if ($course->id == SITEID) { - $data->sitehome = true; - } - - $data->editing = $format->show_editor(); - - // REMOVED index page. - $data->name = get_section_name($course, $section); + $data->sectionbulk = ($CFG->version >= 2023021000) && empty($section->component); - $data->sectionbulk = ($CFG->version >= 2023021000); + $data->headinglevel = (!empty($section->component) && $format->get_sectionid() != $section->id) ? 4 : 3; return $data; } diff --git a/lib.php b/lib.php index fe1f6ac..2f6668b 100644 --- a/lib.php +++ b/lib.php @@ -211,7 +211,7 @@ final public function fmt_get_sections_extra($needall = true): array { $thissectionextra = new \format_multitopic\section_info_extra($thissection); if (!empty($thissection->component)) { - $thissectionextra->levelsan = FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC + 1; + $thissectionextra->levelsan = 0; $fmtsectionsextra[$thissection->id] = $thissectionextra; continue; } @@ -768,6 +768,10 @@ public function get_view_url($section, $options = []) { // REMOVED convert sectioninfo to number. if ($section !== null) { // CHANGED. $sectionextra = $this->fmt_get_section_extra($section, MUST_EXIST); // ADDED. + if (!empty($sectionextra->sectionbase->component) && $sectionextra->sectionbase->component == "mod_subsection") { + $modinfo = get_fast_modinfo($course); + $sectionextra = $this->fmt_get_section_extra((object)['id' => $modinfo->get_instances_of('subsection')[$sectionextra->sectionbase->itemid]->section]); + } // CHANGED. $pageid = ($sectionextra->levelsan != FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ? $sectionextra->id : $sectionextra->parentid; @@ -779,7 +783,7 @@ public function get_view_url($section, $options = []) { return null; } $url->set_anchor('sectionid-' . $sectionextra->id . '-title'); - } else if ($sectionextra->levelsan > FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) { + } else if (!empty($sectionextra->sectionbase->component)) { $url = new moodle_url( '/course/section.php', ['id' => $sectionextra->id]); } // END CHANGED.