Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions changenumsections.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
$courseformatoptions = course_get_format($course)->get_format_options();
$anchortotabstree = get_config('format_onetopic', 'anchortotabstree');

$PAGE->set_url('/course/format/onetopic/changenumsections.php', ['courseid' => $courseid]);
// Authorisation checks.
Expand Down Expand Up @@ -64,7 +65,7 @@
$numsections = 0;

if (!$returnurl) {
$returnurl = course_get_url($course);
$returnurl = course_get_url($course, null, ['anchortotabstree' => $anchortotabstree]);
}
}

Expand All @@ -85,7 +86,7 @@
'numsections' => $courseformatoptions['numsections'], ]);
}
if (!$returnurl) {
$returnurl = course_get_url($course);
$returnurl = course_get_url($course, null, ['anchortotabstree' => $anchortotabstree]);
}
} else if (course_get_format($course)->uses_sections() && $insertsection !== null) {
if ($insertsection) {
Expand All @@ -105,17 +106,14 @@
if (!$returnurl) {
$returnurl = course_get_url(
$course,
$sections[0]->section,
($sectionreturn !== null) ? ['sr' => $sectionreturn] : []
$sections[0],
array_merge(
($sectionreturn !== null) ? ['sr' => $sectionreturn] : [],
['anchortotabstree' => $anchortotabstree]
)
);
}
}

$anchortotabstree = get_config('format_onetopic', 'anchortotabstree');

if ($anchortotabstree) {
$returnurl->set_anchor('tabs-tree-start');
}

// Redirect to where we were..
redirect($returnurl);
7 changes: 2 additions & 5 deletions classes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private function get_tabs(course_modinfo $modinfo, \core\output\renderer_base $o
$sections = $modinfo->get_section_info_all();
$numsections = count($sections);
$enablecustomstyles = get_config('format_onetopic', 'enablecustomstyles');
$anchortotabstree = get_config('format_onetopic', 'anchortotabstree');

// Init custom tabs.
$localsection = 0;
Expand Down Expand Up @@ -416,11 +417,7 @@ private function get_tabs(course_modinfo $modinfo, \core\output\renderer_base $o
}
}

if ($localsection == 0) {
$url = new \core\url('/course/view.php', ['id' => $course->id, 'section' => 0]);
} else {
$url = course_get_url($course, $localsection);
}
$url = course_get_url($course, $localsection, ['anchortotabstree' => $anchortotabstree]);

$specialclass = 'tab_position_' . $localsection . ' tab_level_' . $level;
if ($course->marker == $localsection) {
Expand Down
45 changes: 45 additions & 0 deletions classes/output/courseformat/content/cm/delegatedcontrolmenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace format_onetopic\output\courseformat\content\cm;

use core\output\action_menu\link;
use core_courseformat\output\local\content\cm\delegatedcontrolmenu as delegatedcontrolmenubase;

/**
* Class to render delegated section controls.
*
* @package format_onetopic
* @copyright 2026 James Calder and Otago Polytechnic
* @copyright based on work by 2024 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delegatedcontrolmenu extends delegatedcontrolmenubase {
/**
* Retrieves the permalink item for the section control menu.
*
* @return link|null The menu item if applicable, otherwise null.
*/
protected function get_section_permalink_item(): ?link {
$link = parent::get_section_permalink_item();

if ($link) {
$link->url = $this->format->get_view_url($this->section, ['permalink' => true]);
}

return $link;
}
}
10 changes: 3 additions & 7 deletions classes/output/courseformat/content/section/controlmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,9 @@ public function section_control_items() {

// Create the permalink according to the Onetopic format.
if (array_key_exists("permalink", $parentcontrols)) {
$sectionlink = new url(
'/course/view.php',
[
'id' => $course->id,
'sectionid' => $section->id,
],
'tabs-tree-start'
$sectionlink = $format->get_view_url(
$section,
['permalink' => true, 'anchortotabstree' => true]
);

$parentcontrols['permalink'] = new link_secondary(
Expand Down
6 changes: 2 additions & 4 deletions classes/output/courseformat/content/sectionselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function export_for_template(renderer_base $output): stdClass {

$anchortotabstree = get_config('format_onetopic', 'anchortotabstree');

$anchor = $anchortotabstree ? '#tabs-tree-start' : '';

// Add the section selector.
$sectionmenu = [];
$section = ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) ? 1 : 0;
Expand All @@ -65,9 +63,9 @@ public function export_for_template(renderer_base $output): stdClass {
$formatoptions = course_get_format($course)->get_format_options($thissection);
$prefix = is_array($formatoptions) && $formatoptions['level'] > 0 ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '';

$url = course_get_url($course, $section);
$url = course_get_url($course, $section, ['anchortotabstree' => $anchortotabstree]);
if ($thissection->uservisible && $url) {
$sectionmenu[$url->out(false) . $anchor] = $prefix . get_section_name($course, $section);
$sectionmenu[$url->out(false)] = $prefix . get_section_name($course, $section);
}
$section++;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function get_list(bool $assubtabs = false): array {
}

$newtab = new \stdClass();
$newtab->link = $tab->link . ($anchortotabstree ? '#tabs-tree-start' : '');
$newtab->link = $tab->link;
$newtab->title = $tab->title;
$newtab->text = $tab->content;
$newtab->active = $tab->selected;
Expand Down
48 changes: 31 additions & 17 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,35 +420,49 @@ public function page_title(): string {
/**
* The URL to use for the specified course (with section).
*
* @param int|stdClass $section Section object from database or just field course_sections.section
* @param section_info|stdClass|int|null $section Section object from database or just field course_sections.section
* if omitted the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section has no separate page, the function returns null
* @param array $options options for view URL. At the moment we use:
* 'sr' (int) used by multipage formats to specify to which section to return
* 'permalink' (bool) if true, URL uses section IDs instead of section numbers
* 'anchortotabstree' (bool) if true, URL contains anchor for the tabs
* @return null|\core\url
*/
public function get_view_url($section, $options = []) {
public function get_view_url($section, $options = []): \core\url {

$course = $this->get_course();
$url = new \core\url('/course/view.php', ['id' => $course->id]);
$section = (is_null($section) || $section instanceof section_info) ?
$section
: $this->get_section($section, IGNORE_MISSING);
$permalink = $options['permalink'] ?? false;

$sr = null;
if (array_key_exists('sr', $options)) {
$sr = $options['sr'];
}
if (is_object($section)) {
$sectionno = $section->section;
$pagesection = $this->get_section($options['sr'], IGNORE_MISSING);
} else {
$sectionno = $section;
$pagesection = $section;
if ($pagesection && $pagesection->get_component_instance() && $pagesection->displaymode != 'summary') {
$pagesection = $pagesection->get_component_instance()->get_parent_section();
}
}
if ($sectionno !== null) {
if ($sr !== null) {
if ($sr) {
$sectionno = $sr;
}

$url = new \core\url('/course/view.php', ['id' => $course->id]);
if ($pagesection) {
if ($permalink) {
$url->param('sectionid', $pagesection->id);
} else {
$url->param('section', $pagesection->section);
}
$url->param('section', $sectionno);
}
if ($section && $pagesection?->id != $section->id) {
if ($permalink) {
$url->set_anchor("sectionid-{$section->id}-title");
} else {
$url->set_anchor("section-{$section->section}");
}
} else if ($options['anchortotabstree'] ?? false) {
$url->set_anchor('tabs-tree-start');
}

return $url;
}

Expand Down
Loading