Skip to content

Commit

Permalink
Use section anchors in links when editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jul 24, 2024
1 parent b489d2b commit 197752f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------
Expand Down
24 changes: 18 additions & 6 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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'];
Expand All @@ -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);
}
Expand Down

0 comments on commit 197752f

Please sign in to comment.