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.
This commit is contained in:
Mikel Martín
2024-07-23 16:33:00 +02:00
committed by ferranrecio
parent 195812b34b
commit cc84ae5809
2 changed files with 22 additions and 14 deletions
+21
View File
@@ -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;
}
}
+1 -14
View File
@@ -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]));