MDL-37085 Substitute function print_section_add_menus() with core_course_renderer...
[moodle.git] / course / format / renderer.php
CommitLineData
1804b7c1
DP
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 * Base renderer for outputting course formats.
19 *
20 * @package core
21 * @copyright 2012 Dan Poltawski
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 2.3
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28
29/**
a8f02a34 30 * This is a convenience renderer which can be used by section based formats
3df72f8c 31 * to reduce code duplication. It is not necessary for all course formats to
a8f02a34 32 * use this and its likely to change in future releases.
1804b7c1
DP
33 *
34 * @package core
35 * @copyright 2012 Dan Poltawski
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 * @since Moodle 2.3
38 */
a8f02a34 39abstract class format_section_renderer_base extends plugin_renderer_base {
1804b7c1
DP
40
41 /**
42 * Generate the starting container html for a list of sections
43 * @return string HTML to output.
44 */
cbf44997 45 abstract protected function start_section_list();
1804b7c1
DP
46
47 /**
48 * Generate the closing container html for a list of sections
49 * @return string HTML to output.
50 */
cbf44997 51 abstract protected function end_section_list();
1804b7c1
DP
52
53 /**
54 * Generate the title for this section page
55 * @return string the page title
56 */
cbf44997 57 abstract protected function page_title();
1804b7c1 58
9f3015ec
RK
59 /**
60 * Generate the section title
61 *
62 * @param stdClass $section The course_section entry from DB
63 * @param stdClass $course The course entry from DB
64 * @return string HTML to output.
65 */
66 public function section_title($section, $course) {
67 $title = get_section_name($course, $section);
923451c5
MG
68 $url = course_get_url($course, $section->section, array('navigation' => true));
69 if ($url) {
70 $title = html_writer::link($url, $title);
9f3015ec
RK
71 }
72 return $title;
73 }
74
a830d866
DP
75 /**
76 * Generate the content to displayed on the right part of a section
a830d866 77 * before course modules are included
96e12851 78 *
a830d866
DP
79 * @param stdClass $section The course_section entry from DB
80 * @param stdClass $course The course entry from DB
81 * @param bool $onsectionpage true if being printed on a section page
82 * @return string HTML to output.
83 */
cbf44997 84 protected function section_right_content($section, $course, $onsectionpage) {
a830d866
DP
85 $o = $this->output->spacer();
86
87 if ($section->section != 0) {
88 $controls = $this->section_edit_controls($course, $section, $onsectionpage);
89 if (!empty($controls)) {
90 $o = implode('<br />', $controls);
91 }
92 }
93
94 return $o;
95 }
96
97 /**
98 * Generate the content to displayed on the left part of a section
a830d866 99 * before course modules are included
96e12851 100 *
a830d866
DP
101 * @param stdClass $section The course_section entry from DB
102 * @param stdClass $course The course entry from DB
103 * @param bool $onsectionpage true if being printed on a section page
104 * @return string HTML to output.
105 */
cbf44997 106 protected function section_left_content($section, $course, $onsectionpage) {
a830d866
DP
107 $o = $this->output->spacer();
108
109 if ($section->section != 0) {
110 // Only in the non-general sections.
081c8f7f 111 if (course_get_format($course)->is_section_current($section)) {
a830d866
DP
112 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
113 }
114 }
115
116 return $o;
117 }
118
1804b7c1
DP
119 /**
120 * Generate the display of the header part of a section before
121 * course modules are included
122 *
123 * @param stdClass $section The course_section entry from DB
124 * @param stdClass $course The course entry from DB
9f3015ec 125 * @param bool $onsectionpage true if being printed on a single-section page
b8514b6a 126 * @param int $sectionreturn The section to return to after an action
1804b7c1
DP
127 * @return string HTML to output.
128 */
923451c5 129 protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
1804b7c1
DP
130 global $PAGE;
131
132 $o = '';
133 $currenttext = '';
134 $sectionstyle = '';
1804b7c1 135
96e12851 136 if ($section->section != 0) {
1804b7c1
DP
137 // Only in the non-general sections.
138 if (!$section->visible) {
139 $sectionstyle = ' hidden';
081c8f7f 140 } else if (course_get_format($course)->is_section_current($section)) {
1804b7c1 141 $sectionstyle = ' current';
1804b7c1 142 }
1804b7c1
DP
143 }
144
145 $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
146 'class' => 'section main clearfix'.$sectionstyle));
a830d866
DP
147
148 $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
1804b7c1 149 $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
a830d866
DP
150
151 $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
1804b7c1
DP
152 $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
153 $o.= html_writer::start_tag('div', array('class' => 'content'));
154
5946d376
FM
155 // When not on a section page, we display the section titles except the general section if null
156 $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
157
158 // When on a section page, we only display the general section title, if title is not the default one
159 $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
160
161 if ($hasnamenotsecpg || $hasnamesecpg) {
9f3015ec 162 $o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
1804b7c1
DP
163 }
164
165 $o.= html_writer::start_tag('div', array('class' => 'summary'));
7cb8bfdb 166 $o.= $this->format_summary_text($section);
1804b7c1 167
7cb8bfdb 168 $context = context_course::instance($course->id);
1804b7c1 169 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
b8514b6a 170 $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
1804b7c1 171 $o.= html_writer::link($url,
aad982aa 172 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'),
38cdfab3 173 'class' => 'iconsmall edit', 'alt' => get_string('edit'))),
1804b7c1
DP
174 array('title' => get_string('editsummary')));
175 }
176 $o.= html_writer::end_tag('div');
177
ce4dfd27 178 $o .= $this->section_availability_message($section);
179
1804b7c1
DP
180 return $o;
181 }
182
183 /**
184 * Generate the display of the footer part of a section
185 *
186 * @return string HTML to output.
187 */
cbf44997 188 protected function section_footer() {
1804b7c1
DP
189 $o = html_writer::end_tag('div');
190 $o.= html_writer::end_tag('li');
191
192 return $o;
193 }
194
195 /**
196 * Generate the edit controls of a section
197 *
198 * @param stdClass $course The course entry from DB
199 * @param stdClass $section The course_section entry from DB
200 * @param bool $onsectionpage true if being printed on a section page
201 * @return array of links with edit controls
202 */
cbf44997 203 protected function section_edit_controls($course, $section, $onsectionpage = false) {
1804b7c1
DP
204 global $PAGE;
205
206 if (!$PAGE->user_is_editing()) {
207 return array();
208 }
209
643b1de8 210 $coursecontext = context_course::instance($course->id);
1804b7c1
DP
211
212 if ($onsectionpage) {
213 $baseurl = course_get_url($course, $section->section);
214 } else {
215 $baseurl = course_get_url($course);
216 }
217 $baseurl->param('sesskey', sesskey());
218
219 $controls = array();
220
221 $url = clone($baseurl);
643b1de8
FM
222 if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
223 if ($section->visible) { // Show the hide/show eye.
224 $strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
225 $url->param('hide', $section->section);
226 $controls[] = html_writer::link($url,
227 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
228 'class' => 'icon hide', 'alt' => $strhidefromothers)),
229 array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
230 } else {
231 $strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
232 $url->param('show', $section->section);
233 $controls[] = html_writer::link($url,
234 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
235 'class' => 'icon hide', 'alt' => $strshowfromothers)),
236 array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
237 }
1804b7c1
DP
238 }
239
ad778c84 240 if (!$onsectionpage && has_capability('moodle/course:movesections', $coursecontext)) {
1804b7c1
DP
241 $url = clone($baseurl);
242 if ($section->section > 1) { // Add a arrow to move section up.
243 $url->param('section', $section->section);
244 $url->param('move', -1);
245 $strmoveup = get_string('moveup');
246
247 $controls[] = html_writer::link($url,
06b7ed0a 248 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/up'),
1804b7c1
DP
249 'class' => 'icon up', 'alt' => $strmoveup)),
250 array('title' => $strmoveup, 'class' => 'moveup'));
251 }
252
253 $url = clone($baseurl);
254 if ($section->section < $course->numsections) { // Add a arrow to move section down.
255 $url->param('section', $section->section);
256 $url->param('move', 1);
257 $strmovedown = get_string('movedown');
258
259 $controls[] = html_writer::link($url,
06b7ed0a 260 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/down'),
1804b7c1
DP
261 'class' => 'icon down', 'alt' => $strmovedown)),
262 array('title' => $strmovedown, 'class' => 'movedown'));
263 }
264 }
265
266 return $controls;
267 }
268
269 /**
270 * Generate a summary of a section for display on the 'coruse index page'
271 *
272 * @param stdClass $section The course_section entry from DB
273 * @param stdClass $course The course entry from DB
eda43c7d 274 * @param array $mods (argument not used)
1804b7c1
DP
275 * @return string HTML to output.
276 */
d87debaa 277 protected function section_summary($section, $course, $mods) {
76055f5d
FM
278 $classattr = 'section main section-summary clearfix';
279 $linkclasses = '';
280
bcf7175f 281 // If section is hidden then display grey section link
76055f5d
FM
282 if (!$section->visible) {
283 $classattr .= ' hidden';
284 $linkclasses .= ' dimmed_text';
081c8f7f 285 } else if (course_get_format($course)->is_section_current($section)) {
76055f5d 286 $classattr .= ' current';
bcf7175f 287 }
1804b7c1
DP
288
289 $o = '';
76055f5d 290 $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr));
1804b7c1 291
76055f5d
FM
292 $o .= html_writer::tag('div', '', array('class' => 'left side'));
293 $o .= html_writer::tag('div', '', array('class' => 'right side'));
294 $o .= html_writer::start_tag('div', array('class' => 'content'));
295
e0735653 296 $title = get_section_name($course, $section);
bd43383d 297 if ($section->uservisible) {
e0735653 298 $title = html_writer::tag('a', $title,
bd43383d 299 array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
bd43383d 300 }
e0735653 301 $o .= $this->output->heading($title, 3, 'section-title');
1804b7c1
DP
302
303 $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
7cb8bfdb 304 $o.= $this->format_summary_text($section);
1804b7c1 305 $o.= html_writer::end_tag('div');
eda43c7d 306 $o.= $this->section_activity_summary($section, $course, null);
ce4dfd27 307
d87debaa 308 $o.= $this->section_availability_message($section);
ce4dfd27 309
76055f5d
FM
310 $o .= html_writer::end_tag('div');
311 $o .= html_writer::end_tag('li');
1804b7c1
DP
312
313 return $o;
314 }
315
d87debaa
DP
316 /**
317 * Generate a summary of the activites in a section
318 *
319 * @param stdClass $section The course_section entry from DB
7c05cd0e 320 * @param stdClass $course the course record from DB
eda43c7d 321 * @param array $mods (argument not used)
d87debaa
DP
322 * @return string HTML to output.
323 */
7c05cd0e 324 private function section_activity_summary($section, $course, $mods) {
eda43c7d
MG
325 $modinfo = get_fast_modinfo($course);
326 if (empty($modinfo->sections[$section->section])) {
d87debaa
DP
327 return '';
328 }
329
330 // Generate array with count of activities in this section:
331 $sectionmods = array();
7c05cd0e
AA
332 $total = 0;
333 $complete = 0;
0e5533b6
SH
334 $cancomplete = isloggedin() && !isguestuser();
335 $completioninfo = new completion_info($course);
eda43c7d
MG
336 foreach ($modinfo->sections[$section->section] as $cmid) {
337 $thismod = $modinfo->cms[$cmid];
d87debaa 338
00c41b40
DP
339 if ($thismod->modname == 'label') {
340 // Labels are special (not interesting for students)!
341 continue;
342 }
343
d87debaa
DP
344 if ($thismod->uservisible) {
345 if (isset($sectionmods[$thismod->modname])) {
eda43c7d 346 $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
d87debaa
DP
347 $sectionmods[$thismod->modname]['count']++;
348 } else {
eda43c7d 349 $sectionmods[$thismod->modname]['name'] = $thismod->modfullname;
d87debaa
DP
350 $sectionmods[$thismod->modname]['count'] = 1;
351 }
0e5533b6 352 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
7c05cd0e 353 $total++;
0e5533b6 354 $completiondata = $completioninfo->get_data($thismod, true);
7c05cd0e
AA
355 if ($completiondata->completionstate == COMPLETION_COMPLETE) {
356 $complete++;
357 }
358 }
d87debaa
DP
359 }
360 }
361
362 if (empty($sectionmods)) {
363 // No sections
364 return '';
365 }
366
367 // Output section activities summary:
368 $o = '';
369 $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
370 foreach ($sectionmods as $mod) {
371 $o.= html_writer::start_tag('span', array('class' => 'activity-count'));
372 $o.= $mod['name'].': '.$mod['count'];
373 $o.= html_writer::end_tag('span');
374 }
dce49c1c 375 $o.= html_writer::end_tag('div');
7c05cd0e
AA
376
377 // Output section completion data
0e5533b6
SH
378 if ($total > 0) {
379 $a = new stdClass;
380 $a->complete = $complete;
381 $a->total = $total;
382
dce49c1c 383 $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
0e5533b6 384 $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
dce49c1c 385 $o.= html_writer::end_tag('div');
7c05cd0e 386 }
dce49c1c 387
d87debaa
DP
388 return $o;
389 }
390
ce4dfd27 391 /**
392 * If section is not visible to current user, display the message about that
393 * ('Not available until...', that sort of thing). Otherwise, returns blank.
394 *
395 * @param stdClass $section The course_section entry from DB
396 * @return string HTML to output
397 */
398 protected function section_availability_message($section) {
399 $o = '';
5316007e 400 if (!$section->uservisible || $section->availableinfo) {
ce4dfd27 401 $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
402 if (!empty($section->availableinfo)) {
403 $o .= $section->availableinfo;
404 } else {
405 $o .= get_string('notavailable');
406 }
407 $o .= html_writer::end_tag('div');
408 }
409 return $o;
410 }
411
1804b7c1
DP
412 /**
413 * Show if something is on on the course clipboard (moving around)
414 *
415 * @param stdClass $course The course entry from DB
416 * @param int $sectionno The section number in the coruse which is being dsiplayed
417 * @return string HTML to output.
418 */
923451c5 419 protected function course_activity_clipboard($course, $sectionno = null) {
1804b7c1
DP
420 global $USER;
421
422 $o = '';
423 // If currently moving a file then show the current clipboard.
424 if (ismoving($course->id)) {
425 $url = new moodle_url('/course/mod.php',
426 array('sesskey' => sesskey(),
427 'cancelcopy' => true,
428 'sr' => $sectionno,
429 )
430 );
431
76055f5d 432 $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
1804b7c1
DP
433 $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
434 $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
76055f5d 435 $o.= html_writer::end_tag('div');
1804b7c1
DP
436 }
437
438 return $o;
439 }
440
441 /**
442 * Generate next/previous section links for naviation
443 *
444 * @param stdClass $course The course entry from DB
445 * @param array $sections The course_sections entries from the DB
446 * @param int $sectionno The section number in the coruse which is being dsiplayed
36be7e14 447 * @return array associative array with previous and next section link
1804b7c1 448 */
cbf44997 449 protected function get_nav_links($course, $sections, $sectionno) {
1804b7c1 450 // FIXME: This is really evil and should by using the navigation API.
b5cf83f0 451 $course = course_get_format($course)->get_course();
1804b7c1
DP
452 $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
453 or !$course->hiddensections;
454
455 $links = array('previous' => '', 'next' => '');
456 $back = $sectionno - 1;
457 while ($back > 0 and empty($links['previous'])) {
569747fa 458 if ($canviewhidden || $sections[$back]->uservisible) {
bcf7175f
RT
459 $params = array();
460 if (!$sections[$back]->visible) {
461 $params = array('class' => 'dimmed_text');
462 }
36be7e14
RT
463 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
464 $previouslink .= get_section_name($course, $sections[$back]);
bcf7175f 465 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
1804b7c1
DP
466 }
467 $back--;
468 }
469
470 $forward = $sectionno + 1;
471 while ($forward <= $course->numsections and empty($links['next'])) {
569747fa 472 if ($canviewhidden || $sections[$forward]->uservisible) {
bcf7175f
RT
473 $params = array();
474 if (!$sections[$forward]->visible) {
475 $params = array('class' => 'dimmed_text');
476 }
36be7e14
RT
477 $nextlink = get_section_name($course, $sections[$forward]);
478 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
bcf7175f 479 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
1804b7c1
DP
480 }
481 $forward++;
482 }
483
36be7e14 484 return $links;
1804b7c1
DP
485 }
486
487 /**
488 * Generate the header html of a stealth section
489 *
490 * @param int $sectionno The section number in the coruse which is being dsiplayed
491 * @return string HTML to output.
492 */
cbf44997 493 protected function stealth_section_header($sectionno) {
1804b7c1
DP
494 $o = '';
495 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden'));
496 $o.= html_writer::tag('div', '', array('class' => 'left side'));
497 $o.= html_writer::tag('div', '', array('class' => 'right side'));
498 $o.= html_writer::start_tag('div', array('class' => 'content'));
499 $o.= $this->output->heading(get_string('orphanedactivities'), 3, 'sectionname');
500 return $o;
501 }
502
503 /**
504 * Generate footer html of a stealth section
505 *
506 * @return string HTML to output.
507 */
cbf44997 508 protected function stealth_section_footer() {
1804b7c1
DP
509 $o = html_writer::end_tag('div');
510 $o.= html_writer::end_tag('li');
511 return $o;
512 }
513
514 /**
515 * Generate the html for a hidden section
516 *
517 * @param int $sectionno The section number in the coruse which is being dsiplayed
518 * @return string HTML to output.
519 */
cbf44997 520 protected function section_hidden($sectionno) {
1804b7c1
DP
521 $o = '';
522 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden'));
523 $o.= html_writer::tag('div', '', array('class' => 'left side'));
524 $o.= html_writer::tag('div', '', array('class' => 'right side'));
525 $o.= html_writer::start_tag('div', array('class' => 'content'));
526 $o.= get_string('notavailable');
527 $o.= html_writer::end_tag('div');
528 $o.= html_writer::end_tag('li');
529 return $o;
530 }
531
532 /**
533 * Output the html for a single section page .
534 *
535 * @param stdClass $course The course entry from DB
eda43c7d
MG
536 * @param array $sections (argument not used)
537 * @param array $mods (argument not used)
538 * @param array $modnames (argument not used)
539 * @param array $modnamesused (argument not used)
1804b7c1
DP
540 * @param int $displaysection The section number in the course which is being displayed
541 */
542 public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
543 global $PAGE;
544
eda43c7d 545 $modinfo = get_fast_modinfo($course);
b5cf83f0 546 $course = course_get_format($course)->get_course();
9a6aa5c1 547 $courserenderer = $this->page->get_renderer('core', 'course');
1804b7c1 548
eda43c7d
MG
549 // Can we view the section in question?
550 if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
0c053c53
ARN
551 // This section doesn't exist
552 print_error('unknowncoursesection', 'error', null, $course->fullname);
553 return;
554 }
555
eda43c7d 556 if (!$sectioninfo->uservisible) {
1804b7c1
DP
557 if (!$course->hiddensections) {
558 echo $this->start_section_list();
559 echo $this->section_hidden($displaysection);
560 echo $this->end_section_list();
1804b7c1
DP
561 }
562 // Can't view this section.
563 return;
564 }
565
76055f5d
FM
566 // Copy activity clipboard..
567 echo $this->course_activity_clipboard($course, $displaysection);
eda43c7d
MG
568 $thissection = $modinfo->get_section_info(0);
569 if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
243b7003 570 echo $this->start_section_list();
b8514b6a 571 echo $this->section_header($thissection, $course, true, $displaysection);
eda43c7d 572 print_section($course, $thissection, null, null, true, "100%", false, $displaysection);
9a6aa5c1 573 echo $courserenderer->course_section_add_cm_control($course, 0, $displaysection);
243b7003
DP
574 echo $this->section_footer();
575 echo $this->end_section_list();
576 }
577
c129f430
RT
578 // Start single-section div
579 echo html_writer::start_tag('div', array('class' => 'single-section'));
580
eda43c7d
MG
581 // The requested section page.
582 $thissection = $modinfo->get_section_info($displaysection);
583
36be7e14 584 // Title with section navigation links.
eda43c7d 585 $sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection);
36be7e14 586 $sectiontitle = '';
c129f430 587 $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
36be7e14
RT
588 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
589 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
bcf7175f
RT
590 // Title attributes
591 $titleattr = 'mdl-align title';
eda43c7d 592 if (!$thissection->visible) {
bcf7175f
RT
593 $titleattr .= ' dimmed_text';
594 }
eda43c7d 595 $sectiontitle .= html_writer::tag('div', get_section_name($course, $displaysection), array('class' => $titleattr));
36be7e14
RT
596 $sectiontitle .= html_writer::end_tag('div');
597 echo $sectiontitle;
598
1804b7c1
DP
599 // Now the list of sections..
600 echo $this->start_section_list();
601
b8514b6a 602 echo $this->section_header($thissection, $course, true, $displaysection);
c129f430
RT
603 // Show completion help icon.
604 $completioninfo = new completion_info($course);
605 echo $completioninfo->display_help_icon();
606
eda43c7d 607 print_section($course, $thissection, null, null, true, '100%', false, $displaysection);
9a6aa5c1 608 echo $courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
1804b7c1 609 echo $this->section_footer();
1804b7c1 610 echo $this->end_section_list();
36be7e14
RT
611
612 // Display section bottom navigation.
613 $courselink = html_writer::link(course_get_url($course), get_string('returntomaincoursepage'));
614 $sectionbottomnav = '';
615 $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
616 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
617 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
618 $sectionbottomnav .= html_writer::tag('div', $courselink, array('class' => 'mdl-align'));
619 $sectionbottomnav .= html_writer::end_tag('div');
620 echo $sectionbottomnav;
c129f430
RT
621
622 // close single-section div.
623 echo html_writer::end_tag('div');
1804b7c1
DP
624 }
625
626 /**
627 * Output the html for a multiple section page
628 *
629 * @param stdClass $course The course entry from DB
eda43c7d
MG
630 * @param array $sections (argument not used)
631 * @param array $mods (argument not used)
632 * @param array $modnames (argument not used)
633 * @param array $modnamesused (argument not used)
1804b7c1
DP
634 */
635 public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
636 global $PAGE;
637
eda43c7d 638 $modinfo = get_fast_modinfo($course);
b5cf83f0 639 $course = course_get_format($course)->get_course();
eda43c7d 640
1804b7c1 641 $context = context_course::instance($course->id);
9a6aa5c1 642 $courserenderer = $this->page->get_renderer('core', 'course');
1804b7c1
DP
643 // Title with completion help icon.
644 $completioninfo = new completion_info($course);
645 echo $completioninfo->display_help_icon();
803e36e1 646 echo $this->output->heading($this->page_title(), 2, 'accesshide');
1804b7c1
DP
647
648 // Copy activity clipboard..
923451c5 649 echo $this->course_activity_clipboard($course, 0);
1804b7c1
DP
650
651 // Now the list of sections..
652 echo $this->start_section_list();
653
eda43c7d
MG
654 foreach ($modinfo->get_section_info_all() as $section => $thissection) {
655 if ($section == 0) {
656 // 0-section is displayed a little different then the others
657 if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
658 echo $this->section_header($thissection, $course, false, 0);
659 print_section($course, $thissection, null, null, true, "100%", false, 0);
9a6aa5c1 660 echo $courserenderer->course_section_add_cm_control($course, 0);
eda43c7d
MG
661 echo $this->section_footer();
662 }
663 continue;
1804b7c1 664 }
eda43c7d
MG
665 if ($section > $course->numsections) {
666 // activities inside this section are 'orphaned', this section will be printed as 'stealth' below
667 continue;
1804b7c1 668 }
ce4dfd27 669 // Show the section if the user is permitted to access it, OR if it's not available
670 // but showavailability is turned on
671 $showsection = $thissection->uservisible ||
672 ($thissection->visible && !$thissection->available && $thissection->showavailability);
673 if (!$showsection) {
674 // Hidden section message is overridden by 'unavailable' control
675 // (showavailability option).
676 if (!$course->hiddensections && $thissection->available) {
1804b7c1
DP
677 echo $this->section_hidden($section);
678 }
679
1804b7c1
DP
680 continue;
681 }
682
683 if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
684 // Display section summary only.
eda43c7d 685 echo $this->section_summary($thissection, $course, null);
1804b7c1 686 } else {
923451c5 687 echo $this->section_header($thissection, $course, false, 0);
ce4dfd27 688 if ($thissection->uservisible) {
eda43c7d 689 print_section($course, $thissection, null, null, true, "100%", false, 0);
9a6aa5c1 690 echo $courserenderer->course_section_add_cm_control($course, $section);
1804b7c1
DP
691 }
692 echo $this->section_footer();
693 }
1804b7c1
DP
694 }
695
696 if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
697 // Print stealth sections if present.
eda43c7d
MG
698 foreach ($modinfo->get_section_info_all() as $section => $thissection) {
699 if ($section <= $course->numsections or empty($modinfo->sections[$section])) {
700 // this is not stealth section or it is empty
1804b7c1
DP
701 continue;
702 }
703 echo $this->stealth_section_header($section);
eda43c7d 704 print_section($course, $thissection, null, null, true, "100%", false, 0);
1804b7c1
DP
705 echo $this->stealth_section_footer();
706 }
1abf1253 707
575826c7
ARN
708 echo $this->end_section_list();
709
54495fe4 710 echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
3a35a9ff
DP
711
712 // Increase number of sections.
713 $straddsection = get_string('increasesections', 'moodle');
714 $url = new moodle_url('/course/changenumsections.php',
715 array('courseid' => $course->id,
716 'increase' => true,
717 'sesskey' => sesskey()));
718 $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
719 echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
720
721 if ($course->numsections > 0) {
722 // Reduce number of sections sections.
723 $strremovesection = get_string('reducesections', 'moodle');
724 $url = new moodle_url('/course/changenumsections.php',
725 array('courseid' => $course->id,
726 'increase' => false,
727 'sesskey' => sesskey()));
728 $icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
729 echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
730 }
731
1abf1253 732 echo html_writer::end_tag('div');
575826c7
ARN
733 } else {
734 echo $this->end_section_list();
1804b7c1
DP
735 }
736
1804b7c1 737 }
7cb8bfdb
DP
738
739 /**
740 * Generate html for a section summary text
741 *
742 * @param stdClass $section The course_section entry from DB
743 * @return string HTML to output.
744 */
745 protected function format_summary_text($section) {
746 $context = context_course::instance($section->course);
747 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
748 $context->id, 'course', 'section', $section->id);
749
750 $options = new stdClass();
751 $options->noclean = true;
752 $options->overflowdiv = true;
753 return format_text($summarytext, $section->summaryformat, $options);
754 }
2ea6533a
DP
755
756 /**
081c8f7f
MG
757 * Is the section passed in the current section?
758 *
759 * @deprecated since 2.4
760 * @see format_base::is_section_current()
2ea6533a
DP
761 *
762 * @param stdClass $course The course entry from DB
763 * @param stdClass $section The course_section entry from the DB
764 * @return bool true if the section is current
765 */
081c8f7f
MG
766 protected final function is_section_current($section, $course) {
767 debugging('Function format_section_renderer_base::is_section_current() is deprecated. '.
768 'Use course_get_format($course)->is_section_current($section) instead', DEBUG_DEVELOPER);
769 return course_get_format($course)->is_section_current($section);
2ea6533a 770 }
1804b7c1 771}