Differences Between: [Versions 400 and 402] [Versions 401 and 402]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Contains the default section controls output class. 19 * 20 * @package format_topics 21 * @copyright 2020 Ferran Recio <ferran@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace format_topics\output\courseformat\content\section; 26 27 use core_courseformat\output\local\content\section\controlmenu as controlmenu_base; 28 use moodle_url; 29 30 /** 31 * Base class to render a course section menu. 32 * 33 * @package format_topics 34 * @copyright 2020 Ferran Recio <ferran@moodle.com> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class controlmenu extends controlmenu_base { 38 39 /** @var \core_courseformat\base the course format class */ 40 protected $format; 41 42 /** @var \section_info the course section class */ 43 protected $section; 44 45 /** 46 * Generate the edit control items of a section. 47 * 48 * This method must remain public until the final deprecation of section_edit_control_items. 49 * 50 * @return array of edit control items 51 */ 52 public function section_control_items() { 53 54 $format = $this->format; 55 $section = $this->section; 56 $coursecontext = $format->get_context(); 57 58 $controls = []; 59 if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) { 60 $controls['highlight'] = $this->get_highlight_control(); 61 } 62 63 $parentcontrols = parent::section_control_items(); 64 65 // If the edit key exists, we are going to insert our controls after it. 66 if (array_key_exists("edit", $parentcontrols)) { 67 $merged = []; 68 // We can't use splice because we are using associative arrays. 69 // Step through the array and merge the arrays. 70 foreach ($parentcontrols as $key => $action) { 71 $merged[$key] = $action; 72 if ($key == "edit") { 73 // If we have come to the edit key, merge these controls here. 74 $merged = array_merge($merged, $controls); 75 } 76 } 77 78 return $merged; 79 } else { 80 return array_merge($controls, $parentcontrols); 81 } 82 } 83 84 /** 85 * Return the course url. 86 * 87 * @return moodle_url 88 */ 89 protected function get_course_url(): moodle_url { 90 $format = $this->format; 91 $section = $this->section; 92 $course = $format->get_course(); 93 $sectionreturn = $format->get_section_number(); 94 95 if ($sectionreturn) { 96 $url = course_get_url($course, $section->section); 97 } else { 98 $url = course_get_url($course); 99 } 100 $url->param('sesskey', sesskey()); 101 return $url; 102 } 103 104 /** 105 * Return the specific section highlight action. 106 * 107 * @return array the action element. 108 */ 109 protected function get_highlight_control(): array { 110 $format = $this->format; 111 $section = $this->section; 112 $course = $format->get_course(); 113 $url = $this->get_course_url(); 114 115 $highlightoff = get_string('highlightoff'); 116 $highlighton = get_string('highlight'); 117 118 if ($course->marker == $section->section) { // Show the "light globe" on/off. 119 $url->param('marker', 0); 120 $result = [ 121 'url' => $url, 122 'icon' => 'i/marked', 123 'name' => $highlightoff, 124 'pixattr' => ['class' => ''], 125 'attr' => [ 126 'class' => 'editing_highlight', 127 'data-action' => 'sectionUnhighlight', 128 'data-id' => $section->id, 129 'data-swapname' => $highlighton, 130 'data-swapicon' => 'i/marker', 131 ], 132 ]; 133 } else { 134 $url->param('marker', $section->section); 135 $result = [ 136 'url' => $url, 137 'icon' => 'i/marker', 138 'name' => $highlighton, 139 'pixattr' => ['class' => ''], 140 'attr' => [ 141 'class' => 'editing_highlight', 142 'data-action' => 'sectionHighlight', 143 'data-id' => $section->id, 144 'data-swapname' => $highlightoff, 145 'data-swapicon' => 'i/marked', 146 ], 147 ]; 148 } 149 return $result; 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body