MDL-84045 core_courseformat: Restore section return functionality

This commit is contained in:
james-cnz
2026-02-19 22:35:28 +13:00
committed by James C
parent 2f9c784b34
commit f2ab1fd1d0
5 changed files with 30 additions and 58 deletions
+19 -19
View File
@@ -903,32 +903,32 @@ abstract class base {
* 'expanded' (bool) if true the section will be shown expanded, true by default
* @return null|moodle_url
*/
public function get_view_url($section, $options = array()) {
public function get_view_url($section, $options = []) {
$course = $this->get_course();
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$section = (is_object($section) || is_null($section)) ? $section : $this->get_section($section, IGNORE_MISSING);
// Determine page.
if (array_key_exists('sr', $options)) {
$sectionno = $options['sr'];
} else if (is_object($section)) {
$sectionno = $section->section;
$pagesection = !is_null($options['sr']) ? $this->get_section($options['sr'], IGNORE_MISSING) : null;
} else if ($options['navigation'] ?? false) {
$pagesection = $section;
} else {
$sectionno = $section;
$pagesection = null;
}
if ((!empty($options['navigation']) || array_key_exists('sr', $options)) && $sectionno !== null) {
// Display section on separate page.
$sectioninfo = $this->get_section($sectionno);
return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]);
// Base URL.
if (is_null($pagesection)) {
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
} else {
$url = new moodle_url('/course/section.php', ['id' => $pagesection->id]);
}
if ($this->uses_sections() && $sectionno !== null) {
// The url includes the parameter to expand the section by default.
if (!array_key_exists('expanded', $options)) {
$options['expanded'] = true;
// Add details.
if ($this->uses_sections() && $section && ($section->id != $pagesection?->id)) {
if ($options['expanded'] ?? true) {
$url->param('expandsection', $section->section);
}
if ($options['expanded']) {
// This parameter is being set by default.
$url->param('expandsection', $sectionno);
}
$url->set_anchor('section-'.$sectionno);
$url->set_anchor('section-' . $section->section);
}
return $url;
@@ -120,12 +120,11 @@ class delegatedcontrolmenu extends basecontrolmenu {
return null;
}
$sectionreturn = $this->format->get_sectionnum();
$returnparams = !is_null($sectionreturn) ? ['sr' => $sectionreturn] : [];
$url = new url(
'/course/editsection.php',
[
'id' => $this->section->id,
'sr' => $this->section->sectionnum,
]
array_merge(['id' => $this->section->id], $returnparams)
);
return new link_secondary(
@@ -136,12 +136,11 @@ class controlmenu extends basecontrolmenu {
return null;
}
$sectionreturn = $this->format->get_sectionnum();
$returnparams = !is_null($sectionreturn) ? ['sr' => $sectionreturn] : [];
$url = new url(
'/course/editsection.php',
[
'id' => $this->section->id,
'sr' => $this->section->sectionnum,
]
array_merge(['id' => $this->section->id], $returnparams)
);
return new link_secondary(
+2 -15
View File
@@ -110,21 +110,8 @@ class format_topics extends core_courseformat\base {
* @return moodle_url
*/
public function get_view_url($section, $options = []) {
$course = $this->get_course();
if (array_key_exists('sr', $options) && !is_null($options['sr'])) {
$sectionno = $options['sr'];
} else if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ((!empty($options['navigation']) || array_key_exists('sr', $options)) && $sectionno !== null) {
// Display section on separate page.
$sectioninfo = $this->get_section($sectionno);
return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]);
}
return new moodle_url('/course/view.php', ['id' => $course->id]);
$options['expanded'] = false;
return parent::get_view_url($section, $options);
}
/**
+3 -16
View File
@@ -126,22 +126,9 @@ class format_weeks extends core_courseformat\base {
* 'sr' (int) used by course formats to specify to which section to return
* @return moodle_url
*/
public function get_view_url($section, $options = array()) {
$course = $this->get_course();
if (array_key_exists('sr', $options) && !is_null($options['sr'])) {
$sectionno = $options['sr'];
} else if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ((!empty($options['navigation']) || array_key_exists('sr', $options)) && $sectionno !== null) {
// Display section on separate page.
$sectioninfo = $this->get_section($sectionno);
return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]);
}
return new moodle_url('/course/view.php', ['id' => $course->id]);
public function get_view_url($section, $options = []) {
$options['expanded'] = false;
return parent::get_view_url($section, $options);
}
/**