From cc84ae58094ad56f59f13f0d92a43630d36eec7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Thu, 11 Jul 2024 13:32:53 +0200 Subject: [PATCH] MDL-81766 mod_subsection: Add 'get_delegated_section_info' to manager Add a new 'get_delegated_section_info' to the manager class so it can be reused. --- mod/subsection/classes/manager.php | 21 +++++++++++++++++++++ mod/subsection/view.php | 15 +-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/mod/subsection/classes/manager.php b/mod/subsection/classes/manager.php index 3e6271e00ec..612d6e53e7a 100644 --- a/mod/subsection/classes/manager.php +++ b/mod/subsection/classes/manager.php @@ -19,8 +19,10 @@ namespace mod_subsection; use cm_info; use context_module; use completion_info; +use core_courseformat\formatactions; use mod_subsection\event\course_module_viewed; use moodle_page; +use section_info; use stdClass; /** @@ -180,4 +182,23 @@ class manager { $completion = new completion_info($course); $completion->set_module_viewed($this->cm); } + + /** + * Get the delegated section info. + * + * @return section_info the delegated section info + */ + public function get_delegated_section_info(): section_info { + $delegatedsection = $this->cm->get_delegated_section_info(); + if (!$delegatedsection) { + // Some restorations can produce a situation where the section is not found. + // In that case, we create a new one. + $delegatedsection = formatactions::section($this->cm->course)->create_delegated( + self::PLUGINNAME, + $this->cm->id, + (object) ['name' => $this->instance->name], + ); + } + return $delegatedsection; + } } diff --git a/mod/subsection/view.php b/mod/subsection/view.php index 82f97a7bede..aa1fa788b57 100644 --- a/mod/subsection/view.php +++ b/mod/subsection/view.php @@ -39,19 +39,6 @@ require_login($course, true, $cm); $modulecontext = $manager->get_context(); $manager->set_module_viewed($course); +$delegatesection = $manager->get_delegated_section_info(); -$modinfo = get_fast_modinfo($course); - -$delegatesection = $modinfo->get_section_info_by_component(manager::PLUGINNAME, $moduleinstance->id); -if (!$delegatesection) { - // Some restorations can produce a situation where the section is not found. - // In that case, we create a new one. - formatactions::section($course)->create_delegated( - manager::PLUGINNAME, - $id, - (object) [ - 'name' => $moduleinstance->name, - ] - ); -} redirect(new moodle_url('/course/section.php', ['id' => $delegatesection->id]));