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 |
namespace core_courseformat\output;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
global $CFG;
|
|
|
22 |
require_once($CFG->dirroot . '/course/renderer.php');
|
|
|
23 |
|
|
|
24 |
use cm_info;
|
|
|
25 |
use coding_exception;
|
|
|
26 |
use core_course_renderer;
|
|
|
27 |
use core_courseformat\base as course_format;
|
|
|
28 |
use html_writer;
|
|
|
29 |
use moodle_page;
|
|
|
30 |
use renderable;
|
|
|
31 |
use section_info;
|
|
|
32 |
use stdClass;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Contains the default section course format output class.
|
|
|
36 |
*
|
|
|
37 |
* @package core_courseformat
|
|
|
38 |
* @copyright 2020 Ferran Recio <ferran@moodle.com>
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
|
|
41 |
abstract class section_renderer extends core_course_renderer {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Constructor method, calls the parent constructor.
|
|
|
45 |
*
|
|
|
46 |
* @param moodle_page $page
|
|
|
47 |
* @param string $target one of rendering target constants
|
|
|
48 |
*/
|
|
|
49 |
public function __construct(moodle_page $page, $target) {
|
|
|
50 |
parent::__construct($page, $target);
|
|
|
51 |
|
|
|
52 |
// Ensure capabilities for section editing controls match those defined in course/view.php to ensure that they work
|
|
|
53 |
// when called via an AJAX request.
|
|
|
54 |
if (course_get_format($page->course)->uses_sections()) {
|
|
|
55 |
$page->set_other_editing_capability('moodle/course:sectionvisibility');
|
|
|
56 |
$page->set_other_editing_capability('moodle/course:movesections');
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Renders the provided widget and returns the HTML to display it.
|
|
|
62 |
*
|
|
|
63 |
* Course format templates uses a similar subfolder structure to the renderable classes.
|
|
|
64 |
* This method find out the specific template for a course widget. That's the reason why
|
|
|
65 |
* this render method is different from the normal plugin renderer one.
|
|
|
66 |
*
|
|
|
67 |
* course format templatables can be rendered using the core_course/local/* templates.
|
|
|
68 |
* Format plugins are free to override the default template location using render_xxx methods as usual.
|
|
|
69 |
*
|
|
|
70 |
* @param renderable $widget instance with renderable interface
|
|
|
71 |
* @return string the widget HTML
|
|
|
72 |
*/
|
|
|
73 |
public function render(renderable $widget) {
|
|
|
74 |
global $CFG;
|
|
|
75 |
$fullpath = str_replace('\\', '/', get_class($widget));
|
|
|
76 |
$classparts = explode('/', $fullpath);
|
|
|
77 |
// Strip namespaces.
|
|
|
78 |
$classname = array_pop($classparts);
|
|
|
79 |
// Remove _renderable suffixes.
|
|
|
80 |
$classname = preg_replace('/_renderable$/', '', $classname);
|
|
|
81 |
|
|
|
82 |
$rendermethod = 'render_' . $classname;
|
|
|
83 |
if (method_exists($this, $rendermethod)) {
|
|
|
84 |
return $this->$rendermethod($widget);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
// If nothing works, let the parent class decide.
|
|
|
88 |
return parent::render($widget);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page
|
|
|
93 |
*
|
|
|
94 |
* @param stdClass $section The course_section entry from DB
|
|
|
95 |
* @param stdClass $course The course entry from DB
|
|
|
96 |
* @return string HTML to output.
|
|
|
97 |
*/
|
|
|
98 |
public function section_title($section, $course) {
|
|
|
99 |
$title = get_section_name($course, $section);
|
|
|
100 |
$url = course_get_url($course, $section->section, array('navigation' => true));
|
|
|
101 |
if ($url) {
|
|
|
102 |
$title = html_writer::link($url, $title);
|
|
|
103 |
}
|
|
|
104 |
return $title;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Generate the section title to be displayed on the section page, without a link
|
|
|
109 |
*
|
|
|
110 |
* @param stdClass $section The course_section entry from DB
|
|
|
111 |
* @param stdClass $course The course entry from DB
|
|
|
112 |
* @return string HTML to output.
|
|
|
113 |
*/
|
|
|
114 |
public function section_title_without_link($section, $course) {
|
|
|
115 |
return get_section_name($course, $section);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* Get the updated rendered version of a cm list item.
|
|
|
120 |
*
|
|
|
121 |
* This method is used when an activity is duplicated or copied in on the client side without refreshing the page.
|
|
|
122 |
* Note that the previous method is used every time an activity is rendered, independent of it is the initial page
|
|
|
123 |
* loading or an Ajax update. In this case, course_section_updated_cm_item will only be used when the course editor
|
|
|
124 |
* requires to get an updated cm item HTML to perform partial page refresh. It will be used for suporting the course
|
|
|
125 |
* editor webservices.
|
|
|
126 |
*
|
|
|
127 |
* By default, the template used for update a cm_item is the same as when it renders initially, but format plugins are
|
|
|
128 |
* free to override this methos to provide extra affects or so.
|
|
|
129 |
*
|
|
|
130 |
* @param course_format $format the course format
|
|
|
131 |
* @param section_info $section the section info
|
|
|
132 |
* @param cm_info $cm the course module ionfo
|
|
|
133 |
* @param array $displayoptions optional extra display options
|
|
|
134 |
* @return string the rendered element
|
|
|
135 |
*/
|
|
|
136 |
public function course_section_updated_cm_item(
|
|
|
137 |
course_format $format,
|
|
|
138 |
section_info $section,
|
|
|
139 |
cm_info $cm,
|
|
|
140 |
array $displayoptions = []
|
|
|
141 |
) {
|
|
|
142 |
|
|
|
143 |
$cmitemclass = $format->get_output_classname('content\\section\\cmitem');
|
|
|
144 |
$cmitem = new $cmitemclass($format, $section, $cm, $displayoptions);
|
|
|
145 |
return $this->render($cmitem);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
|
|
149 |
* Get the updated rendered version of a section.
|
|
|
150 |
*
|
|
|
151 |
* This method will only be used when the course editor requires to get an updated cm item HTML
|
|
|
152 |
* to perform partial page refresh. It will be used for supporting the course editor webservices.
|
|
|
153 |
*
|
|
|
154 |
* By default, the template used for update a section is the same as when it renders initially,
|
|
|
155 |
* but format plugins are free to override this method to provide extra effects or so.
|
|
|
156 |
*
|
|
|
157 |
* @param course_format $format the course format
|
|
|
158 |
* @param section_info $section the section info
|
|
|
159 |
* @return string the rendered element
|
|
|
160 |
*/
|
|
|
161 |
public function course_section_updated(
|
|
|
162 |
course_format $format,
|
|
|
163 |
section_info $section
|
|
|
164 |
): string {
|
|
|
165 |
$sectionclass = $format->get_output_classname('content\\section');
|
|
|
166 |
$output = new $sectionclass($format, $section);
|
|
|
167 |
return $this->render($output);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
/**
|
|
|
171 |
* Get the course index drawer with placeholder.
|
|
|
172 |
*
|
|
|
173 |
* The default course index is loaded after the page is ready. Format plugins can override
|
|
|
174 |
* this method to provide an alternative course index.
|
|
|
175 |
*
|
|
|
176 |
* If the format is not compatible with the course index, this method will return an empty string.
|
|
|
177 |
*
|
|
|
178 |
* @param course_format $format the course format
|
|
|
179 |
* @return String the course index HTML.
|
|
|
180 |
*/
|
|
|
181 |
public function course_index_drawer(course_format $format): ?String {
|
|
|
182 |
if ($format->uses_course_index()) {
|
|
|
183 |
include_course_editor($format);
|
|
|
184 |
return $this->render_from_template('core_courseformat/local/courseindex/drawer', []);
|
|
|
185 |
}
|
|
|
186 |
return '';
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/**
|
|
|
190 |
* Render the enable bulk editing button.
|
|
|
191 |
* @param course_format $format the course format
|
|
|
192 |
* @return string|null the enable bulk button HTML (or null if no bulk available).
|
|
|
193 |
*/
|
|
|
194 |
public function bulk_editing_button(course_format $format): ?string {
|
|
|
195 |
if (!$format->show_editor() || !$format->supports_components()) {
|
|
|
196 |
return null;
|
|
|
197 |
}
|
|
|
198 |
$widgetclass = $format->get_output_classname('content\\bulkedittoggler');
|
|
|
199 |
$widget = new $widgetclass($format);
|
|
|
200 |
return $this->render($widget);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
205 |
*/
|
|
|
206 |
protected function section_edit_control_menu($controls, $course, $section) {
|
|
|
207 |
|
|
|
208 |
throw new coding_exception('section_edit_control_menu() can not be used anymore. Please use ' .
|
|
|
209 |
'core_courseformat\\output\\local\\content\\section to render a section. In case you need to modify those controls ' .
|
|
|
210 |
'override core_courseformat\\output\\local\\content\\section\\controlmenu in your format plugin.');
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
/**
|
|
|
214 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
215 |
*/
|
|
|
216 |
protected function section_right_content($section, $course, $onsectionpage) {
|
|
|
217 |
|
|
|
218 |
throw new coding_exception('section_right_content() can not be used anymore. Please use ' .
|
|
|
219 |
'core_courseformat\\output\\local\\content\\section to render a section.');
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
224 |
*/
|
|
|
225 |
protected function section_left_content($section, $course, $onsectionpage) {
|
|
|
226 |
|
|
|
227 |
throw new coding_exception('section_left_content() can not be used anymore. Please use ' .
|
|
|
228 |
'core_courseformat\\output\\local\\content\\section to render a section.');
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
/**
|
|
|
232 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
233 |
*/
|
|
|
234 |
protected function section_header($section, $course, $onsectionpage, $sectionreturn = null) {
|
|
|
235 |
|
|
|
236 |
throw new coding_exception('section_header() can not be used any more. Please use ' .
|
|
|
237 |
'core_courseformat\\output\\local\\content\\section to render a section ' .
|
|
|
238 |
'or core_courseformat\output\\local\\content\\section\\header ' .
|
|
|
239 |
'to print only the header.');
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
/**
|
|
|
243 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
244 |
*/
|
|
|
245 |
protected function section_footer() {
|
|
|
246 |
|
|
|
247 |
throw new coding_exception('section_footer() can not be used any more. Please use ' .
|
|
|
248 |
'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
|
|
|
249 |
'core_courseformat\\output\\local\\content to render the full course');
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
/**
|
|
|
253 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
254 |
*/
|
|
|
255 |
protected function start_section_list() {
|
|
|
256 |
|
|
|
257 |
throw new coding_exception('start_section_list() can not be used any more. Please use ' .
|
|
|
258 |
'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
|
|
|
259 |
'core_courseformat\\output\\local\\content to render the full course');
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
/**
|
|
|
263 |
* @deprecated since 4.0 - use core_course output components instead.y
|
|
|
264 |
*/
|
|
|
265 |
protected function end_section_list() {
|
|
|
266 |
|
|
|
267 |
throw new coding_exception('end_section_list() can not be used any more. Please use ' .
|
|
|
268 |
'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
|
|
|
269 |
'core_courseformat\\output\\local\\content to render the full course');
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
/**
|
|
|
273 |
* Old method to print section edit controls. Do not use it!
|
|
|
274 |
*
|
|
|
275 |
* @deprecated since Moodle 3.0 MDL-48947 - Use core_courseformat\output\section_renderer::section_edit_control_items() instead
|
|
|
276 |
*/
|
|
|
277 |
protected function section_edit_controls() {
|
|
|
278 |
throw new coding_exception('section_edit_controls() can not be used anymore. Please use ' .
|
|
|
279 |
'section_edit_control_items() instead.');
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
/**
|
|
|
283 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
284 |
*/
|
|
|
285 |
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
|
|
|
286 |
|
|
|
287 |
throw new coding_exception('section_edit_control_items() can not be used any more. Please use or extend' .
|
|
|
288 |
'core_courseformat\output\\local\\content\\section\\controlmenu instead (like topics format does).');
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
/**
|
|
|
292 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
293 |
*/
|
|
|
294 |
protected function section_summary($section, $course, $mods) {
|
|
|
295 |
|
|
|
296 |
throw new coding_exception('section_summary() can not be used any more. Please use ' .
|
|
|
297 |
'core_courseformat\output\\local\\content\\section to render sections. If you need to modify those summary, extend ' .
|
|
|
298 |
'core_courseformat\output\\local\\content\\section\\summary in your format plugin.');
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
/**
|
|
|
302 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
303 |
*/
|
|
|
304 |
protected function section_activity_summary($section, $course, $mods) {
|
|
|
305 |
|
|
|
306 |
throw new coding_exception('section_activity_summary() can not be used any more. Please use ' .
|
|
|
307 |
'core_courseformat\output\\local\\content\\section to render sections. ' .
|
|
|
308 |
'If you need to modify those information, extend ' .
|
|
|
309 |
'core_courseformat\output\\local\\content\\section\\cmsummary in your format plugin.');
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
/**
|
|
|
313 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
314 |
*/
|
|
|
315 |
protected function section_availability_message($section, $canviewhidden) {
|
|
|
316 |
|
|
|
317 |
throw new coding_exception('section_availability_message() can not be used any more. Please use ' .
|
|
|
318 |
'core_courseformat\output\\local\\content\\section to render sections. If you need to modify this element, extend ' .
|
|
|
319 |
'core_courseformat\output\\local\\content\\section\\availability in your format plugin.');
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
/**
|
|
|
323 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
324 |
*/
|
|
|
325 |
public function section_availability($section) {
|
|
|
326 |
throw new coding_exception('section_availability() can not be used any more. Please use ' .
|
|
|
327 |
'core_courseformat\output\\local\\content\\section to render sections. If you need to modify this element, extend ' .
|
|
|
328 |
'core_courseformat\output\\local\\content\\section\\availability in your format plugin.');
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
333 |
*/
|
|
|
334 |
protected function course_activity_clipboard($course, $sectionno = null) {
|
|
|
335 |
throw new coding_exception('Non ajax course edition using course_activity_clipboard is not supported anymore.');
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
/**
|
|
|
339 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
340 |
*/
|
|
|
341 |
protected function get_nav_links($course, $sections, $sectionno) {
|
|
|
342 |
|
|
|
343 |
throw new coding_exception('get_nav_links() can not be used any more. Please use ' .
|
|
|
344 |
'core_courseformat\\output\\local\\content to render a course. If you need to modify this element, extend ' .
|
|
|
345 |
'core_courseformat\\output\\local\\content\\sectionnavigation in your format plugin.');
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
/**
|
|
|
349 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
350 |
*/
|
|
|
351 |
protected function stealth_section_header($sectionno) {
|
|
|
352 |
|
|
|
353 |
throw new coding_exception('stealth_section_header() can not be used any more. Please use ' .
|
|
|
354 |
'core_courseformat\output\\local\\content\\section to render sections.');
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
/**
|
|
|
358 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
359 |
*/
|
|
|
360 |
protected function stealth_section_footer() {
|
|
|
361 |
|
|
|
362 |
throw new coding_exception('stealth_section_footer() can not be used any more. Please use ' .
|
|
|
363 |
'core_courseformat\output\\local\\content\\section to render sections.');
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
/**
|
|
|
367 |
* Generate the html for a hidden section
|
|
|
368 |
*
|
|
|
369 |
* @param int $sectionno The section number in the course which is being displayed
|
|
|
370 |
* @param int|stdClass $courseorid The course to get the section name for (object or just course id)
|
|
|
371 |
* @return string HTML to output.
|
|
|
372 |
*/
|
|
|
373 |
protected function section_hidden($sectionno, $courseorid = null) {
|
|
|
374 |
if ($courseorid) {
|
|
|
375 |
$sectionname = get_section_name($courseorid, $sectionno);
|
|
|
376 |
$strnotavailable = get_string('notavailablecourse', '', $sectionname);
|
|
|
377 |
} else {
|
|
|
378 |
$strnotavailable = get_string('notavailable');
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
$o = '';
|
|
|
382 |
$o .= html_writer::start_tag('li', [
|
|
|
383 |
'id' => 'section-' . $sectionno,
|
|
|
384 |
'class' => 'section main clearfix hidden',
|
|
|
385 |
'data-sectionid' => $sectionno
|
|
|
386 |
]);
|
|
|
387 |
$o .= html_writer::tag('div', '', array('class' => 'left side'));
|
|
|
388 |
$o .= html_writer::tag('div', '', array('class' => 'right side'));
|
|
|
389 |
$o .= html_writer::start_tag('div', array('class' => 'content'));
|
|
|
390 |
$o .= html_writer::tag('div', $strnotavailable);
|
|
|
391 |
$o .= html_writer::end_tag('div');
|
|
|
392 |
$o .= html_writer::end_tag('li');
|
|
|
393 |
return $o;
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
/**
|
|
|
397 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
398 |
*/
|
|
|
399 |
protected function section_nav_selection($course, $sections, $displaysection) {
|
|
|
400 |
|
|
|
401 |
throw new coding_exception('section_nav_selection() can not be used anymore. Please use ' .
|
|
|
402 |
'core_courseformat\\output\\local\\content to render a course. If you need to modify this element, extend ' .
|
|
|
403 |
'core_courseformat\\output\\local\\content\\sectionnavigation or ' .
|
|
|
404 |
'core_courseformat\\output\\local\\content\\sectionselector in your format plugin.');
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
/**
|
|
|
408 |
* @deprecated since 4.0
|
|
|
409 |
*/
|
|
|
410 |
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
|
|
|
411 |
|
|
|
412 |
throw new coding_exception('Method print_single_section_page can not be used anymore. Please use' .
|
|
|
413 |
'core_courseformat\\output\\local\\content instead ' .
|
|
|
414 |
'or override render_content method to use a different template');
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
/**
|
|
|
418 |
* @deprecated since 4.0
|
|
|
419 |
*/
|
|
|
420 |
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
|
|
|
421 |
|
|
|
422 |
throw new coding_exception('Method print_multiple_section_page can not be used anymore. Please use' .
|
|
|
423 |
'core_courseformat\\output\\local\\content instead ' .
|
|
|
424 |
'or override render_content method to use a diferent template');
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
429 |
*/
|
|
|
430 |
protected function change_number_sections($course, $sectionreturn = null) {
|
|
|
431 |
|
|
|
432 |
throw new coding_exception('Method change_number_sections can not be used anymore. Please use' .
|
|
|
433 |
'core_courseformat\\output\\local\\content\\addsection instead');
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
/**
|
|
|
437 |
* @deprecated since 4.0 - use core_course output components instead.
|
|
|
438 |
*/
|
|
|
439 |
protected function format_summary_text($section) {
|
|
|
440 |
|
|
|
441 |
throw new coding_exception('Method format_summary_text can not be used anymore. Please use' .
|
|
|
442 |
'core_courseformat\output\\local\\content\\section\\summary::format_summary_text instead');
|
|
|
443 |
}
|
|
|
444 |
}
|