From 197752f07cb90215bb042bfee6ee5e4b35c74a86 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:07:16 +0100 Subject: [PATCH] Use section anchors in links when editing. --- Changes.md | 1 + lib.php | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Changes.md b/Changes.md index d1e175ae..59e90319 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ History Version 404.1.1 - TBR ---------------------------- +1. Use section anchors in links when editing. Version 404.1.0 - 11/04/2024 ---------------------------- diff --git a/lib.php b/lib.php index b247db8a..c7b52cb1 100755 --- a/lib.php +++ b/lib.php @@ -59,7 +59,13 @@ protected function __construct($format, $courseid) { $currentsettings = $this->get_settings(); if (!empty($currentsettings['popup'])) { if ($currentsettings['popup'] == 2) { - $this->coursedisplay = COURSE_DISPLAY_SINGLEPAGE; + global $PAGE; + $context = context_course::instance($courseid); + if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) { + $this->coursedisplay = COURSE_DISPLAY_MULTIPAGE; + } else { + $this->coursedisplay = COURSE_DISPLAY_SINGLEPAGE; + } } } } @@ -324,8 +330,8 @@ public function ajax_section_move() { * @return null|moodle_url */ public function get_view_url($section, $options = []) { + global $PAGE; $course = $this->get_course(); - $url = new moodle_url('/course/view.php', ['id' => $course->id]); if (array_key_exists('sr', $options)) { $sectionno = $options['sr']; @@ -334,11 +340,17 @@ public function get_view_url($section, $options = []) { } else { $sectionno = $section; } - if (!empty($options['navigation']) && $sectionno !== null) { - // Display section on separate page. - $sectioninfo = $this->get_section($sectionno); - return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]); + + $context = context_course::instance($course->id); + if (!($PAGE->user_is_editing() && has_capability('moodle/course:update', $context))) { + if (!empty($options['navigation']) && $sectionno !== null) { + // Display section on separate page when not editing. + $sectioninfo = $this->get_section($sectionno); + return new moodle_url('/course/section.php', ['id' => $sectioninfo->id]); + } } + + $url = new moodle_url('/course/view.php', ['id' => $course->id]); if ($this->uses_sections() && $sectionno !== null) { $url->set_anchor('section-'.$sectionno); }