MDL-33307 format_weeks - highlight current week
[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
a830d866
DP
59 /**
60 * Generate the content to displayed on the right part of a section
a830d866 61 * before course modules are included
96e12851 62 *
a830d866
DP
63 * @param stdClass $section The course_section entry from DB
64 * @param stdClass $course The course entry from DB
65 * @param bool $onsectionpage true if being printed on a section page
66 * @return string HTML to output.
67 */
cbf44997 68 protected function section_right_content($section, $course, $onsectionpage) {
a830d866
DP
69 $o = $this->output->spacer();
70
71 if ($section->section != 0) {
72 $controls = $this->section_edit_controls($course, $section, $onsectionpage);
73 if (!empty($controls)) {
74 $o = implode('<br />', $controls);
75 }
76 }
77
78 return $o;
79 }
80
81 /**
82 * Generate the content to displayed on the left part of a section
a830d866 83 * before course modules are included
96e12851 84 *
a830d866
DP
85 * @param stdClass $section The course_section entry from DB
86 * @param stdClass $course The course entry from DB
87 * @param bool $onsectionpage true if being printed on a section page
88 * @return string HTML to output.
89 */
cbf44997 90 protected function section_left_content($section, $course, $onsectionpage) {
a830d866
DP
91 $o = $this->output->spacer();
92
93 if ($section->section != 0) {
94 // Only in the non-general sections.
2ea6533a 95 if ($this->is_section_current($section, $course)) {
a830d866
DP
96 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
97 }
98 }
99
100 return $o;
101 }
102
1804b7c1
DP
103 /**
104 * Generate the display of the header part of a section before
105 * course modules are included
106 *
107 * @param stdClass $section The course_section entry from DB
108 * @param stdClass $course The course entry from DB
109 * @param bool $onsectionpage true if being printed on a section page
110 * @return string HTML to output.
111 */
cbf44997 112 protected function section_header($section, $course, $onsectionpage) {
1804b7c1
DP
113 global $PAGE;
114
115 $o = '';
116 $currenttext = '';
117 $sectionstyle = '';
1804b7c1
DP
118 $linktitle = false;
119
96e12851 120 if ($section->section != 0) {
1804b7c1
DP
121 // Only in the non-general sections.
122 if (!$section->visible) {
123 $sectionstyle = ' hidden';
2ea6533a 124 } else if ($this->is_section_current($section, $course)) {
1804b7c1 125 $sectionstyle = ' current';
1804b7c1
DP
126 }
127 $linktitle = ($course->coursedisplay == COURSE_DISPLAY_MULTIPAGE);
128 }
129
130 $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
131 'class' => 'section main clearfix'.$sectionstyle));
a830d866
DP
132
133 $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
1804b7c1 134 $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
a830d866
DP
135
136 $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
1804b7c1
DP
137 $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
138 $o.= html_writer::start_tag('div', array('class' => 'content'));
139
140 if (!$onsectionpage) {
141 $title = get_section_name($course, $section);
142 if ($linktitle) {
143 $title = html_writer::link(course_get_url($course, $section->section), $title);
144 }
145 $o.= $this->output->heading($title, 3, 'sectionname');
146 }
147
148 $o.= html_writer::start_tag('div', array('class' => 'summary'));
7cb8bfdb 149 $o.= $this->format_summary_text($section);
1804b7c1 150
7cb8bfdb 151 $context = context_course::instance($course->id);
1804b7c1
DP
152 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
153 $url = new moodle_url('/course/editsection.php', array('id'=>$section->id));
154
155 if ($onsectionpage) {
156 $url->param('sectionreturn', 1);
157 }
158
159 $o.= html_writer::link($url,
160 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'class' => 'iconsmall edit')),
161 array('title' => get_string('editsummary')));
162 }
163 $o.= html_writer::end_tag('div');
164
ce4dfd27 165 $o .= $this->section_availability_message($section);
166
1804b7c1
DP
167 return $o;
168 }
169
170 /**
171 * Generate the display of the footer part of a section
172 *
173 * @return string HTML to output.
174 */
cbf44997 175 protected function section_footer() {
1804b7c1
DP
176 $o = html_writer::end_tag('div');
177 $o.= html_writer::end_tag('li');
178
179 return $o;
180 }
181
182 /**
183 * Generate the edit controls of a section
184 *
185 * @param stdClass $course The course entry from DB
186 * @param stdClass $section The course_section entry from DB
187 * @param bool $onsectionpage true if being printed on a section page
188 * @return array of links with edit controls
189 */
cbf44997 190 protected function section_edit_controls($course, $section, $onsectionpage = false) {
1804b7c1
DP
191 global $PAGE;
192
193 if (!$PAGE->user_is_editing()) {
194 return array();
195 }
196
197 if (!has_capability('moodle/course:update', context_course::instance($course->id))) {
198 return array();
199 }
200
201 if ($onsectionpage) {
202 $baseurl = course_get_url($course, $section->section);
203 } else {
204 $baseurl = course_get_url($course);
205 }
206 $baseurl->param('sesskey', sesskey());
207
208 $controls = array();
209
210 $url = clone($baseurl);
211 if ($section->visible) { // Show the hide/show eye.
212 $strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
213 $url->param('hide', $section->section);
214 $controls[] = html_writer::link($url,
215 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
216 'class' => 'icon hide', 'alt' => $strhidefromothers)),
217 array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
218 } else {
219 $strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
220 $url->param('show', $section->section);
221 $controls[] = html_writer::link($url,
222 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
223 'class' => 'icon hide', 'alt' => $strshowfromothers)),
224 array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
225 }
226
227 if (!$onsectionpage) {
228 $url = clone($baseurl);
229 if ($section->section > 1) { // Add a arrow to move section up.
230 $url->param('section', $section->section);
231 $url->param('move', -1);
232 $strmoveup = get_string('moveup');
233
234 $controls[] = html_writer::link($url,
235 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/up'),
236 'class' => 'icon up', 'alt' => $strmoveup)),
237 array('title' => $strmoveup, 'class' => 'moveup'));
238 }
239
240 $url = clone($baseurl);
241 if ($section->section < $course->numsections) { // Add a arrow to move section down.
242 $url->param('section', $section->section);
243 $url->param('move', 1);
244 $strmovedown = get_string('movedown');
245
246 $controls[] = html_writer::link($url,
247 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/down'),
248 'class' => 'icon down', 'alt' => $strmovedown)),
249 array('title' => $strmovedown, 'class' => 'movedown'));
250 }
251 }
252
253 return $controls;
254 }
255
256 /**
257 * Generate a summary of a section for display on the 'coruse index page'
258 *
259 * @param stdClass $section The course_section entry from DB
260 * @param stdClass $course The course entry from DB
261 * @return string HTML to output.
262 */
cbf44997 263 protected function section_summary($section, $course) {
bcf7175f
RT
264 // If section is hidden then display grey section link
265 $classattr = 'section-summary clearfix';
266 If (!$section->visible) {
267 $classattr .= ' dimmed_text';
268 }
1804b7c1
DP
269
270 $o = '';
a60cc6e1 271 $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
bcf7175f 272 'class' => $classattr));
1804b7c1
DP
273
274 $title = get_section_name($course, $section);
1804b7c1
DP
275 $o.= html_writer::start_tag('a', array('href' => course_get_url($course, $section->section)));
276 $o.= $this->output->heading($title, 3, 'header section-title');
277 $o.= html_writer::end_tag('a');
278
279 $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
7cb8bfdb 280 $o.= $this->format_summary_text($section);
1804b7c1 281 $o.= html_writer::end_tag('div');
ce4dfd27 282
283 $o .= $this->section_availability_message($section);
284
1804b7c1
DP
285 $o.= html_writer::end_tag('li');
286
287 return $o;
288 }
289
ce4dfd27 290 /**
291 * If section is not visible to current user, display the message about that
292 * ('Not available until...', that sort of thing). Otherwise, returns blank.
293 *
294 * @param stdClass $section The course_section entry from DB
295 * @return string HTML to output
296 */
297 protected function section_availability_message($section) {
298 $o = '';
5316007e 299 if (!$section->uservisible || $section->availableinfo) {
ce4dfd27 300 $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
301 if (!empty($section->availableinfo)) {
302 $o .= $section->availableinfo;
303 } else {
304 $o .= get_string('notavailable');
305 }
306 $o .= html_writer::end_tag('div');
307 }
308 return $o;
309 }
310
1804b7c1
DP
311 /**
312 * Show if something is on on the course clipboard (moving around)
313 *
314 * @param stdClass $course The course entry from DB
315 * @param int $sectionno The section number in the coruse which is being dsiplayed
316 * @return string HTML to output.
317 */
cbf44997 318 protected function course_activity_clipboard($course, $sectionno = 0) {
1804b7c1
DP
319 global $USER;
320
321 $o = '';
322 // If currently moving a file then show the current clipboard.
323 if (ismoving($course->id)) {
324 $url = new moodle_url('/course/mod.php',
325 array('sesskey' => sesskey(),
326 'cancelcopy' => true,
327 'sr' => $sectionno,
328 )
329 );
330
331 $strcancel= get_string('cancel');
332
333 $o.= html_writer::start_tag('li', array('class' => 'clipboard'));
334 $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
335 $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
336 $o.= html_writer::end_tag('li');
337 }
338
339 return $o;
340 }
341
342 /**
343 * Generate next/previous section links for naviation
344 *
345 * @param stdClass $course The course entry from DB
346 * @param array $sections The course_sections entries from the DB
347 * @param int $sectionno The section number in the coruse which is being dsiplayed
36be7e14 348 * @return array associative array with previous and next section link
1804b7c1 349 */
cbf44997 350 protected function get_nav_links($course, $sections, $sectionno) {
1804b7c1
DP
351 // FIXME: This is really evil and should by using the navigation API.
352 $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
353 or !$course->hiddensections;
354
355 $links = array('previous' => '', 'next' => '');
356 $back = $sectionno - 1;
357 while ($back > 0 and empty($links['previous'])) {
358 if ($canviewhidden || $sections[$back]->visible) {
bcf7175f
RT
359 $params = array();
360 if (!$sections[$back]->visible) {
361 $params = array('class' => 'dimmed_text');
362 }
36be7e14
RT
363 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
364 $previouslink .= get_section_name($course, $sections[$back]);
bcf7175f 365 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
1804b7c1
DP
366 }
367 $back--;
368 }
369
370 $forward = $sectionno + 1;
371 while ($forward <= $course->numsections and empty($links['next'])) {
372 if ($canviewhidden || $sections[$forward]->visible) {
bcf7175f
RT
373 $params = array();
374 if (!$sections[$forward]->visible) {
375 $params = array('class' => 'dimmed_text');
376 }
36be7e14
RT
377 $nextlink = get_section_name($course, $sections[$forward]);
378 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
bcf7175f 379 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
1804b7c1
DP
380 }
381 $forward++;
382 }
383
36be7e14 384 return $links;
1804b7c1
DP
385 }
386
387 /**
388 * Generate the header html of a stealth section
389 *
390 * @param int $sectionno The section number in the coruse which is being dsiplayed
391 * @return string HTML to output.
392 */
cbf44997 393 protected function stealth_section_header($sectionno) {
1804b7c1
DP
394 $o = '';
395 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden'));
396 $o.= html_writer::tag('div', '', array('class' => 'left side'));
397 $o.= html_writer::tag('div', '', array('class' => 'right side'));
398 $o.= html_writer::start_tag('div', array('class' => 'content'));
399 $o.= $this->output->heading(get_string('orphanedactivities'), 3, 'sectionname');
400 return $o;
401 }
402
403 /**
404 * Generate footer html of a stealth section
405 *
406 * @return string HTML to output.
407 */
cbf44997 408 protected function stealth_section_footer() {
1804b7c1
DP
409 $o = html_writer::end_tag('div');
410 $o.= html_writer::end_tag('li');
411 return $o;
412 }
413
414 /**
415 * Generate the html for a hidden section
416 *
417 * @param int $sectionno The section number in the coruse which is being dsiplayed
418 * @return string HTML to output.
419 */
cbf44997 420 protected function section_hidden($sectionno) {
1804b7c1
DP
421 $o = '';
422 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden'));
423 $o.= html_writer::tag('div', '', array('class' => 'left side'));
424 $o.= html_writer::tag('div', '', array('class' => 'right side'));
425 $o.= html_writer::start_tag('div', array('class' => 'content'));
426 $o.= get_string('notavailable');
427 $o.= html_writer::end_tag('div');
428 $o.= html_writer::end_tag('li');
429 return $o;
430 }
431
432 /**
433 * Output the html for a single section page .
434 *
435 * @param stdClass $course The course entry from DB
436 * @param array $sections The course_sections entries from the DB
437 * @param array $mods used for print_section()
438 * @param array $modnames used for print_section()
439 * @param array $modnamesused used for print_section()
440 * @param int $displaysection The section number in the course which is being displayed
441 */
442 public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
443 global $PAGE;
444
1804b7c1
DP
445 // Can we view the section in question?
446 $context = context_course::instance($course->id);
447 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
448
0c053c53
ARN
449 if (!isset($sections[$displaysection])) {
450 // This section doesn't exist
451 print_error('unknowncoursesection', 'error', null, $course->fullname);
452 return;
453 }
454
1804b7c1
DP
455 if (!$sections[$displaysection]->visible && !$canviewhidden) {
456 if (!$course->hiddensections) {
457 echo $this->start_section_list();
458 echo $this->section_hidden($displaysection);
459 echo $this->end_section_list();
1804b7c1
DP
460 }
461 // Can't view this section.
462 return;
463 }
464
243b7003
DP
465 // General section if non-empty.
466 $thissection = $sections[0];
467 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
468 echo $this->start_section_list();
469 echo $this->section_header($thissection, $course, true);
470 print_section($course, $thissection, $mods, $modnamesused, true);
471 if ($PAGE->user_is_editing()) {
472 print_section_add_menus($course, 0, $modnames);
473 }
474 echo $this->section_footer();
475 echo $this->end_section_list();
476 }
477
c129f430
RT
478 // Start single-section div
479 echo html_writer::start_tag('div', array('class' => 'single-section'));
480
36be7e14 481 // Title with section navigation links.
243b7003 482 $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
36be7e14 483 $sectiontitle = '';
c129f430 484 $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
36be7e14
RT
485 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
486 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
bcf7175f
RT
487 // Title attributes
488 $titleattr = 'mdl-align title';
489 if (!$sections[$displaysection]->visible) {
490 $titleattr .= ' dimmed_text';
491 }
492 $sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
36be7e14
RT
493 $sectiontitle .= html_writer::end_tag('div');
494 echo $sectiontitle;
495
1804b7c1
DP
496 // Copy activity clipboard..
497 echo $this->course_activity_clipboard($course, $displaysection);
498
499 // Now the list of sections..
500 echo $this->start_section_list();
501
1804b7c1
DP
502 // The requested section page.
503 $thissection = $sections[$displaysection];
504 echo $this->section_header($thissection, $course, true);
c129f430
RT
505 // Show completion help icon.
506 $completioninfo = new completion_info($course);
507 echo $completioninfo->display_help_icon();
508
1804b7c1
DP
509 print_section($course, $thissection, $mods, $modnamesused, true);
510 if ($PAGE->user_is_editing()) {
511 print_section_add_menus($course, $displaysection, $modnames);
512 }
513 echo $this->section_footer();
1804b7c1 514 echo $this->end_section_list();
36be7e14
RT
515
516 // Display section bottom navigation.
517 $courselink = html_writer::link(course_get_url($course), get_string('returntomaincoursepage'));
518 $sectionbottomnav = '';
519 $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
520 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
521 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
522 $sectionbottomnav .= html_writer::tag('div', $courselink, array('class' => 'mdl-align'));
523 $sectionbottomnav .= html_writer::end_tag('div');
524 echo $sectionbottomnav;
c129f430
RT
525
526 // close single-section div.
527 echo html_writer::end_tag('div');
1804b7c1
DP
528 }
529
530 /**
531 * Output the html for a multiple section page
532 *
533 * @param stdClass $course The course entry from DB
534 * @param array $sections The course_sections entries from the DB
535 * @param array $mods used for print_section()
536 * @param array $modnames used for print_section()
537 * @param array $modnamesused used for print_section()
538 */
539 public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
540 global $PAGE;
541
542 $context = context_course::instance($course->id);
543 // Title with completion help icon.
544 $completioninfo = new completion_info($course);
545 echo $completioninfo->display_help_icon();
803e36e1 546 echo $this->output->heading($this->page_title(), 2, 'accesshide');
1804b7c1
DP
547
548 // Copy activity clipboard..
549 echo $this->course_activity_clipboard($course);
550
551 // Now the list of sections..
552 echo $this->start_section_list();
553
554 // General section if non-empty.
555 $thissection = $sections[0];
556 unset($sections[0]);
557 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
558 echo $this->section_header($thissection, $course, true);
559 print_section($course, $thissection, $mods, $modnamesused, true);
560 if ($PAGE->user_is_editing()) {
561 print_section_add_menus($course, 0, $modnames);
562 }
563 echo $this->section_footer();
564 }
565
566 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
567 for ($section = 1; $section <= $course->numsections; $section++) {
568 if (!empty($sections[$section])) {
569 $thissection = $sections[$section];
570 } else {
571 // This will create a course section if it doesn't exist..
572 $thissection = get_course_section($section, $course->id);
52f14061 573
574 // The returned section is only a bare database object rather than
575 // a section_info object - we will need at least the uservisible
576 // field in it.
577 $thissection->uservisible = true;
57a42a24 578 $thissection->availableinfo = null;
579 $thissection->showavailability = 0;
1804b7c1 580 }
ce4dfd27 581 // Show the section if the user is permitted to access it, OR if it's not available
582 // but showavailability is turned on
583 $showsection = $thissection->uservisible ||
584 ($thissection->visible && !$thissection->available && $thissection->showavailability);
585 if (!$showsection) {
586 // Hidden section message is overridden by 'unavailable' control
587 // (showavailability option).
588 if (!$course->hiddensections && $thissection->available) {
1804b7c1
DP
589 echo $this->section_hidden($section);
590 }
591
592 unset($sections[$section]);
593 continue;
594 }
595
596 if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
597 // Display section summary only.
598 echo $this->section_summary($thissection, $course);
599 } else {
600 echo $this->section_header($thissection, $course, false);
ce4dfd27 601 if ($thissection->uservisible) {
602 print_section($course, $thissection, $mods, $modnamesused);
603 if ($PAGE->user_is_editing()) {
604 print_section_add_menus($course, $section, $modnames);
605 }
1804b7c1
DP
606 }
607 echo $this->section_footer();
608 }
609
610 unset($sections[$section]);
611 }
612
613 if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
614 // Print stealth sections if present.
615 $modinfo = get_fast_modinfo($course);
616 foreach ($sections as $section => $thissection) {
617 if (empty($modinfo->sections[$section])) {
618 continue;
619 }
620 echo $this->stealth_section_header($section);
621 print_section($course, $thissection, $mods, $modnamesused);
622 echo $this->stealth_section_footer();
623 }
1abf1253 624
575826c7
ARN
625 echo $this->end_section_list();
626
3a35a9ff
DP
627 echo html_writer::start_tag('div', array('class' => 'mdl-right'));
628
629 // Increase number of sections.
630 $straddsection = get_string('increasesections', 'moodle');
631 $url = new moodle_url('/course/changenumsections.php',
632 array('courseid' => $course->id,
633 'increase' => true,
634 'sesskey' => sesskey()));
635 $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
636 echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
637
638 if ($course->numsections > 0) {
639 // Reduce number of sections sections.
640 $strremovesection = get_string('reducesections', 'moodle');
641 $url = new moodle_url('/course/changenumsections.php',
642 array('courseid' => $course->id,
643 'increase' => false,
644 'sesskey' => sesskey()));
645 $icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
646 echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
647 }
648
1abf1253 649 echo html_writer::end_tag('div');
575826c7
ARN
650 } else {
651 echo $this->end_section_list();
1804b7c1
DP
652 }
653
1804b7c1 654 }
7cb8bfdb
DP
655
656 /**
657 * Generate html for a section summary text
658 *
659 * @param stdClass $section The course_section entry from DB
660 * @return string HTML to output.
661 */
662 protected function format_summary_text($section) {
663 $context = context_course::instance($section->course);
664 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
665 $context->id, 'course', 'section', $section->id);
666
667 $options = new stdClass();
668 $options->noclean = true;
669 $options->overflowdiv = true;
670 return format_text($summarytext, $section->summaryformat, $options);
671 }
2ea6533a
DP
672
673 /**
674 * Is the section passed in the current section? (Note this isn't strictly
675 * a renderering method, but neater here).
676 *
677 * @param stdClass $course The course entry from DB
678 * @param stdClass $section The course_section entry from the DB
679 * @return bool true if the section is current
680 */
681 protected function is_section_current($section, $course) {
682 return ($course->marker == $section->section);
683 }
1804b7c1 684}