1 |
efrain |
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_sectionnum();
|
|
|
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 |
$sectionreturn = $format->get_sectionnum();
|
|
|
114 |
$url = $this->get_course_url();
|
|
|
115 |
if (!is_null($sectionreturn)) {
|
|
|
116 |
$url->param('sectionid', $format->get_sectionid());
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
$highlightoff = get_string('highlightoff');
|
|
|
120 |
$highlighton = get_string('highlight');
|
|
|
121 |
|
|
|
122 |
if ($course->marker == $section->section) { // Show the "light globe" on/off.
|
|
|
123 |
$url->param('marker', 0);
|
|
|
124 |
$result = [
|
|
|
125 |
'url' => $url,
|
|
|
126 |
'icon' => 'i/marked',
|
|
|
127 |
'name' => $highlightoff,
|
|
|
128 |
'pixattr' => ['class' => ''],
|
|
|
129 |
'attr' => [
|
|
|
130 |
'class' => 'editing_highlight',
|
|
|
131 |
'data-action' => 'sectionUnhighlight',
|
|
|
132 |
'data-sectionreturn' => $sectionreturn,
|
|
|
133 |
'data-id' => $section->id,
|
|
|
134 |
'data-swapname' => $highlighton,
|
|
|
135 |
'data-swapicon' => 'i/marker',
|
|
|
136 |
],
|
|
|
137 |
];
|
|
|
138 |
} else {
|
|
|
139 |
$url->param('marker', $section->section);
|
|
|
140 |
$result = [
|
|
|
141 |
'url' => $url,
|
|
|
142 |
'icon' => 'i/marker',
|
|
|
143 |
'name' => $highlighton,
|
|
|
144 |
'pixattr' => ['class' => ''],
|
|
|
145 |
'attr' => [
|
|
|
146 |
'class' => 'editing_highlight',
|
|
|
147 |
'data-action' => 'sectionHighlight',
|
|
|
148 |
'data-sectionreturn' => $sectionreturn,
|
|
|
149 |
'data-id' => $section->id,
|
|
|
150 |
'data-swapname' => $highlightoff,
|
|
|
151 |
'data-swapicon' => 'i/marked',
|
|
|
152 |
],
|
|
|
153 |
];
|
|
|
154 |
}
|
|
|
155 |
return $result;
|
|
|
156 |
}
|
|
|
157 |
}
|