MDL-34444 - actually display the title, just don't link it..
[moodle.git] / course / format / renderer.php
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/>.
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  */
26 defined('MOODLE_INTERNAL') || die();
29 /**
30  * This is a convenience renderer which can be used by section based formats
31  * to reduce code duplication. It is not necessary for all course formats to
32  * use this and its likely to change in future releases.
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  */
39 abstract class format_section_renderer_base extends plugin_renderer_base {
41     /**
42      * Generate the starting container html for a list of sections
43      * @return string HTML to output.
44      */
45     abstract protected function start_section_list();
47     /**
48      * Generate the closing container html for a list of sections
49      * @return string HTML to output.
50      */
51     abstract protected function end_section_list();
53     /**
54      * Generate the title for this section page
55      * @return string the page title
56      */
57     abstract protected function page_title();
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);
68         if ($section->section != 0 && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
69             $title = html_writer::link(course_get_url($course, $section->section), $title);
70         }
71         return $title;
72     }
74     /**
75      * Generate the content to displayed on the right part of a section
76      * before course modules are included
77      *
78      * @param stdClass $section The course_section entry from DB
79      * @param stdClass $course The course entry from DB
80      * @param bool $onsectionpage true if being printed on a section page
81      * @return string HTML to output.
82      */
83     protected function section_right_content($section, $course, $onsectionpage) {
84         $o = $this->output->spacer();
86         if ($section->section != 0) {
87             $controls = $this->section_edit_controls($course, $section, $onsectionpage);
88             if (!empty($controls)) {
89                 $o = implode('<br />', $controls);
90             }
91         }
93         return $o;
94     }
96     /**
97      * Generate the content to displayed on the left part of a section
98      * before course modules are included
99      *
100      * @param stdClass $section The course_section entry from DB
101      * @param stdClass $course The course entry from DB
102      * @param bool $onsectionpage true if being printed on a section page
103      * @return string HTML to output.
104      */
105     protected function section_left_content($section, $course, $onsectionpage) {
106         $o = $this->output->spacer();
108         if ($section->section != 0) {
109             // Only in the non-general sections.
110             if ($this->is_section_current($section, $course)) {
111                 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
112             }
113         }
115         return $o;
116     }
118     /**
119      * Generate the display of the header part of a section before
120      * course modules are included
121      *
122      * @param stdClass $section The course_section entry from DB
123      * @param stdClass $course The course entry from DB
124      * @param bool $onsectionpage true if being printed on a single-section page
125      * @param int $sectionreturn The section to return to after an action
126      * @return string HTML to output.
127      */
128     protected function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
129         global $PAGE;
131         $o = '';
132         $currenttext = '';
133         $sectionstyle = '';
135         if ($section->section != 0) {
136             // Only in the non-general sections.
137             if (!$section->visible) {
138                 $sectionstyle = ' hidden';
139             } else if ($this->is_section_current($section, $course)) {
140                 $sectionstyle = ' current';
141             }
142         }
144         $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
145             'class' => 'section main clearfix'.$sectionstyle));
147         $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
148         $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
150         $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
151         $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
152         $o.= html_writer::start_tag('div', array('class' => 'content'));
154         // When not on a section page, we display the section titles except the general section if null
155         $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
157         // When on a section page, we only display the general section title, if title is not the default one
158         $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
160         if ($hasnamenotsecpg || $hasnamesecpg) {
161             $o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
162         }
164         $o.= html_writer::start_tag('div', array('class' => 'summary'));
165         $o.= $this->format_summary_text($section);
167         $context = context_course::instance($course->id);
168         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
169             $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
170             $o.= html_writer::link($url,
171                 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'class' => 'iconsmall edit')),
172                 array('title' => get_string('editsummary')));
173         }
174         $o.= html_writer::end_tag('div');
176         $o .= $this->section_availability_message($section);
178         return $o;
179     }
181     /**
182      * Generate the display of the footer part of a section
183      *
184      * @return string HTML to output.
185      */
186     protected function section_footer() {
187         $o = html_writer::end_tag('div');
188         $o.= html_writer::end_tag('li');
190         return $o;
191     }
193     /**
194      * Generate the edit controls of a section
195      *
196      * @param stdClass $course The course entry from DB
197      * @param stdClass $section The course_section entry from DB
198      * @param bool $onsectionpage true if being printed on a section page
199      * @return array of links with edit controls
200      */
201     protected function section_edit_controls($course, $section, $onsectionpage = false) {
202         global $PAGE;
204         if (!$PAGE->user_is_editing()) {
205             return array();
206         }
208         if (!has_capability('moodle/course:update', context_course::instance($course->id))) {
209             return array();
210         }
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());
219         $controls = array();
221         $url = clone($baseurl);
222         if ($section->visible) { // Show the hide/show eye.
223             $strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
224             $url->param('hide', $section->section);
225             $controls[] = html_writer::link($url,
226                 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
227                 'class' => 'icon hide', 'alt' => $strhidefromothers)),
228                 array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
229         } else {
230             $strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
231             $url->param('show',  $section->section);
232             $controls[] = html_writer::link($url,
233                 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
234                 'class' => 'icon hide', 'alt' => $strshowfromothers)),
235                 array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
236         }
238         if (!$onsectionpage) {
239             $url = clone($baseurl);
240             if ($section->section > 1) { // Add a arrow to move section up.
241                 $url->param('section', $section->section);
242                 $url->param('move', -1);
243                 $strmoveup = get_string('moveup');
245                 $controls[] = html_writer::link($url,
246                     html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/up'),
247                     'class' => 'icon up', 'alt' => $strmoveup)),
248                     array('title' => $strmoveup, 'class' => 'moveup'));
249             }
251             $url = clone($baseurl);
252             if ($section->section < $course->numsections) { // Add a arrow to move section down.
253                 $url->param('section', $section->section);
254                 $url->param('move', 1);
255                 $strmovedown =  get_string('movedown');
257                 $controls[] = html_writer::link($url,
258                     html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/down'),
259                     'class' => 'icon down', 'alt' => $strmovedown)),
260                     array('title' => $strmovedown, 'class' => 'movedown'));
261             }
262         }
264         return $controls;
265     }
267     /**
268      * Generate a summary of a section for display on the 'coruse index page'
269      *
270      * @param stdClass $section The course_section entry from DB
271      * @param stdClass $course The course entry from DB
272      * @param array    $mods course modules indexed by id (from get_all_mods)
273      * @return string HTML to output.
274      */
275     protected function section_summary($section, $course, $mods) {
276         $classattr = 'section main section-summary clearfix';
277         $linkclasses = '';
279         // If section is hidden then display grey section link
280         if (!$section->visible) {
281             $classattr .= ' hidden';
282             $linkclasses .= ' dimmed_text';
283         } else if ($this->is_section_current($section, $course)) {
284             $classattr .= ' current';
285         }
287         $o = '';
288         $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr));
290         $o .= html_writer::tag('div', '', array('class' => 'left side'));
291         $o .= html_writer::tag('div', '', array('class' => 'right side'));
292         $o .= html_writer::start_tag('div', array('class' => 'content'));
294         $title = get_section_name($course, $section);
295         if ($section->uservisible) {
296             $title = html_writer::tag('a', $title,
297                     array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
298         }
299         $o .= $this->output->heading($title, 3, 'section-title');
301         $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
302         $o.= $this->format_summary_text($section);
303         $o.= html_writer::end_tag('div');
304         $o.= $this->section_activity_summary($section, $course, $mods);
306         $o.= $this->section_availability_message($section);
308         $o .= html_writer::end_tag('div');
309         $o .= html_writer::end_tag('li');
311         return $o;
312     }
314     /**
315      * Generate a summary of the activites in a section
316      *
317      * @param stdClass $section The course_section entry from DB
318      * @param stdClass $course the course record from DB
319      * @param array    $mods course modules indexed by id (from get_all_mods)
320      * @return string HTML to output.
321      */
322     private function section_activity_summary($section, $course, $mods) {
323         if (empty($section->sequence)) {
324             return '';
325         }
327         // Generate array with count of activities in this section:
328         $sectionmods = array();
329         $total = 0;
330         $complete = 0;
331         $cancomplete = isloggedin() && !isguestuser();
332         $completioninfo = new completion_info($course);
333         $modsequence = explode(',', $section->sequence);
334         foreach ($modsequence as $cmid) {
335             $thismod = $mods[$cmid];
337             if ($thismod->modname == 'label') {
338                 // Labels are special (not interesting for students)!
339                 continue;
340             }
342             if ($thismod->uservisible) {
343                 if (isset($sectionmods[$thismod->modname])) {
344                     $sectionmods[$thismod->modname]['count']++;
345                 } else {
346                     $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
347                     $sectionmods[$thismod->modname]['count'] = 1;
348                 }
349                 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
350                     $total++;
351                     $completiondata = $completioninfo->get_data($thismod, true);
352                     if ($completiondata->completionstate == COMPLETION_COMPLETE) {
353                         $complete++;
354                     }
355                 }
356             }
357         }
359         if (empty($sectionmods)) {
360             // No sections
361             return '';
362         }
364         // Output section activities summary:
365         $o = '';
366         $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
367         foreach ($sectionmods as $mod) {
368             $o.= html_writer::start_tag('span', array('class' => 'activity-count'));
369             $o.= $mod['name'].': '.$mod['count'];
370             $o.= html_writer::end_tag('span');
371         }
372         $o.= html_writer::end_tag('div');
374         // Output section completion data
375         if ($total > 0) {
376             $a = new stdClass;
377             $a->complete = $complete;
378             $a->total = $total;
380             $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
381             $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
382             $o.= html_writer::end_tag('div');
383         }
385         return $o;
386     }
388     /**
389      * If section is not visible to current user, display the message about that
390      * ('Not available until...', that sort of thing). Otherwise, returns blank.
391      *
392      * @param stdClass $section The course_section entry from DB
393      * @return string HTML to output
394      */
395     protected function section_availability_message($section) {
396         $o = '';
397         if (!$section->uservisible || $section->availableinfo) {
398             $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
399             if (!empty($section->availableinfo)) {
400                 $o .= $section->availableinfo;
401             } else {
402                 $o .= get_string('notavailable');
403             }
404             $o .= html_writer::end_tag('div');
405         }
406         return $o;
407     }
409     /**
410      * Show if something is on on the course clipboard (moving around)
411      *
412      * @param stdClass $course The course entry from DB
413      * @param int $sectionno The section number in the coruse which is being dsiplayed
414      * @return string HTML to output.
415      */
416     protected function course_activity_clipboard($course, $sectionno = 0) {
417         global $USER;
419         $o = '';
420         // If currently moving a file then show the current clipboard.
421         if (ismoving($course->id)) {
422             $url = new moodle_url('/course/mod.php',
423                 array('sesskey' => sesskey(),
424                       'cancelcopy' => true,
425                       'sr' => $sectionno,
426                 )
427             );
429             $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
430             $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
431             $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
432             $o.= html_writer::end_tag('div');
433         }
435         return $o;
436     }
438     /**
439      * Generate next/previous section links for naviation
440      *
441      * @param stdClass $course The course entry from DB
442      * @param array $sections The course_sections entries from the DB
443      * @param int $sectionno The section number in the coruse which is being dsiplayed
444      * @return array associative array with previous and next section link
445      */
446     protected function get_nav_links($course, $sections, $sectionno) {
447         // FIXME: This is really evil and should by using the navigation API.
448         $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
449             or !$course->hiddensections;
451         $links = array('previous' => '', 'next' => '');
452         $back = $sectionno - 1;
453         while ($back > 0 and empty($links['previous'])) {
454             if ($canviewhidden || $sections[$back]->uservisible) {
455                 $params = array();
456                 if (!$sections[$back]->visible) {
457                     $params = array('class' => 'dimmed_text');
458                 }
459                 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
460                 $previouslink .= get_section_name($course, $sections[$back]);
461                 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
462             }
463             $back--;
464         }
466         $forward = $sectionno + 1;
467         while ($forward <= $course->numsections and empty($links['next'])) {
468             if ($canviewhidden || $sections[$forward]->uservisible) {
469                 $params = array();
470                 if (!$sections[$forward]->visible) {
471                     $params = array('class' => 'dimmed_text');
472                 }
473                 $nextlink = get_section_name($course, $sections[$forward]);
474                 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
475                 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
476             }
477             $forward++;
478         }
480         return $links;
481     }
483     /**
484      * Generate the header html of a stealth section
485      *
486      * @param int $sectionno The section number in the coruse which is being dsiplayed
487      * @return string HTML to output.
488      */
489     protected function stealth_section_header($sectionno) {
490         $o = '';
491         $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden'));
492         $o.= html_writer::tag('div', '', array('class' => 'left side'));
493         $o.= html_writer::tag('div', '', array('class' => 'right side'));
494         $o.= html_writer::start_tag('div', array('class' => 'content'));
495         $o.= $this->output->heading(get_string('orphanedactivities'), 3, 'sectionname');
496         return $o;
497     }
499     /**
500      * Generate footer html of a stealth section
501      *
502      * @return string HTML to output.
503      */
504     protected function stealth_section_footer() {
505         $o = html_writer::end_tag('div');
506         $o.= html_writer::end_tag('li');
507         return $o;
508     }
510     /**
511      * Generate the html for a hidden section
512      *
513      * @param int $sectionno The section number in the coruse which is being dsiplayed
514      * @return string HTML to output.
515      */
516     protected function section_hidden($sectionno) {
517         $o = '';
518         $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden'));
519         $o.= html_writer::tag('div', '', array('class' => 'left side'));
520         $o.= html_writer::tag('div', '', array('class' => 'right side'));
521         $o.= html_writer::start_tag('div', array('class' => 'content'));
522         $o.= get_string('notavailable');
523         $o.= html_writer::end_tag('div');
524         $o.= html_writer::end_tag('li');
525         return $o;
526     }
528     /**
529      * Output the html for a single section page .
530      *
531      * @param stdClass $course The course entry from DB
532      * @param array $sections The course_sections entries from the DB
533      * @param array $mods used for print_section()
534      * @param array $modnames used for print_section()
535      * @param array $modnamesused used for print_section()
536      * @param int $displaysection The section number in the course which is being displayed
537      */
538     public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
539         global $PAGE;
541         // Can we view the section in question?
542         $context = context_course::instance($course->id);
543         $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
545         if (!isset($sections[$displaysection])) {
546             // This section doesn't exist
547             print_error('unknowncoursesection', 'error', null, $course->fullname);
548             return;
549         }
551         if (!$sections[$displaysection]->visible && !$canviewhidden) {
552             if (!$course->hiddensections) {
553                 echo $this->start_section_list();
554                 echo $this->section_hidden($displaysection);
555                 echo $this->end_section_list();
556             }
557             // Can't view this section.
558             return;
559         }
561         // Copy activity clipboard..
562         echo $this->course_activity_clipboard($course, $displaysection);
564         // General section if non-empty.
565         $thissection = $sections[0];
566         if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
567             echo $this->start_section_list();
568             echo $this->section_header($thissection, $course, true, $displaysection);
569             print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
570             if ($PAGE->user_is_editing()) {
571                 print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
572             }
573             echo $this->section_footer();
574             echo $this->end_section_list();
575         }
577         // Start single-section div
578         echo html_writer::start_tag('div', array('class' => 'single-section'));
580         // Title with section navigation links.
581         $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
582         $sectiontitle = '';
583         $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
584         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
585         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
586         // Title attributes
587         $titleattr = 'mdl-align title';
588         if (!$sections[$displaysection]->visible) {
589             $titleattr .= ' dimmed_text';
590         }
591         $sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
592         $sectiontitle .= html_writer::end_tag('div');
593         echo $sectiontitle;
595         // Now the list of sections..
596         echo $this->start_section_list();
598         // The requested section page.
599         $thissection = $sections[$displaysection];
600         echo $this->section_header($thissection, $course, true, $displaysection);
601         // Show completion help icon.
602         $completioninfo = new completion_info($course);
603         echo $completioninfo->display_help_icon();
605         print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
606         if ($PAGE->user_is_editing()) {
607             print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
608         }
609         echo $this->section_footer();
610         echo $this->end_section_list();
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;
622         // close single-section div.
623         echo html_writer::end_tag('div');
624     }
626     /**
627      * Output the html for a multiple section page
628      *
629      * @param stdClass $course The course entry from DB
630      * @param array $sections The course_sections entries from the DB
631      * @param array $mods used for print_section()
632      * @param array $modnames used for print_section()
633      * @param array $modnamesused used for print_section()
634      */
635     public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
636         global $PAGE;
638         $context = context_course::instance($course->id);
639         // Title with completion help icon.
640         $completioninfo = new completion_info($course);
641         echo $completioninfo->display_help_icon();
642         echo $this->output->heading($this->page_title(), 2, 'accesshide');
644         // Copy activity clipboard..
645         echo $this->course_activity_clipboard($course);
647         // Now the list of sections..
648         echo $this->start_section_list();
650         // General section if non-empty.
651         $thissection = $sections[0];
652         unset($sections[0]);
653         if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
654             echo $this->section_header($thissection, $course, false);
655             print_section($course, $thissection, $mods, $modnamesused, true);
656             if ($PAGE->user_is_editing()) {
657                 print_section_add_menus($course, 0, $modnames);
658             }
659             echo $this->section_footer();
660         }
662         $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
663         for ($section = 1; $section <= $course->numsections; $section++) {
664             if (!empty($sections[$section])) {
665                 $thissection = $sections[$section];
666             } else {
667                 // This will create a course section if it doesn't exist..
668                 $thissection = get_course_section($section, $course->id);
670                 // The returned section is only a bare database object rather than
671                 // a section_info object - we will need at least the uservisible
672                 // field in it.
673                 $thissection->uservisible = true;
674                 $thissection->availableinfo = null;
675                 $thissection->showavailability = 0;
676             }
677             // Show the section if the user is permitted to access it, OR if it's not available
678             // but showavailability is turned on
679             $showsection = $thissection->uservisible ||
680                     ($thissection->visible && !$thissection->available && $thissection->showavailability);
681             if (!$showsection) {
682                 // Hidden section message is overridden by 'unavailable' control
683                 // (showavailability option).
684                 if (!$course->hiddensections && $thissection->available) {
685                     echo $this->section_hidden($section);
686                 }
688                 unset($sections[$section]);
689                 continue;
690             }
692             if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
693                 // Display section summary only.
694                 echo $this->section_summary($thissection, $course, $mods);
695             } else {
696                 echo $this->section_header($thissection, $course, false);
697                 if ($thissection->uservisible) {
698                     print_section($course, $thissection, $mods, $modnamesused);
699                     if ($PAGE->user_is_editing()) {
700                         print_section_add_menus($course, $section, $modnames);
701                     }
702                 }
703                 echo $this->section_footer();
704             }
706             unset($sections[$section]);
707         }
709         if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
710             // Print stealth sections if present.
711             $modinfo = get_fast_modinfo($course);
712             foreach ($sections as $section => $thissection) {
713                 if (empty($modinfo->sections[$section])) {
714                     continue;
715                 }
716                 echo $this->stealth_section_header($section);
717                 print_section($course, $thissection, $mods, $modnamesused);
718                 echo $this->stealth_section_footer();
719             }
721             echo $this->end_section_list();
723             echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
725             // Increase number of sections.
726             $straddsection = get_string('increasesections', 'moodle');
727             $url = new moodle_url('/course/changenumsections.php',
728                 array('courseid' => $course->id,
729                       'increase' => true,
730                       'sesskey' => sesskey()));
731             $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
732             echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
734             if ($course->numsections > 0) {
735                 // Reduce number of sections sections.
736                 $strremovesection = get_string('reducesections', 'moodle');
737                 $url = new moodle_url('/course/changenumsections.php',
738                     array('courseid' => $course->id,
739                           'increase' => false,
740                           'sesskey' => sesskey()));
741                 $icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
742                 echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
743             }
745             echo html_writer::end_tag('div');
746         } else {
747             echo $this->end_section_list();
748         }
750     }
752     /**
753      * Generate html for a section summary text
754      *
755      * @param stdClass $section The course_section entry from DB
756      * @return string HTML to output.
757      */
758     protected function format_summary_text($section) {
759         $context = context_course::instance($section->course);
760         $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
761             $context->id, 'course', 'section', $section->id);
763         $options = new stdClass();
764         $options->noclean = true;
765         $options->overflowdiv = true;
766         return format_text($summarytext, $section->summaryformat, $options);
767     }
769     /**
770      * Is the section passed in the current section? (Note this isn't strictly
771      * a renderering method, but neater here).
772      *
773      * @param stdClass $course The course entry from DB
774      * @param stdClass $section The course_section entry from the DB
775      * @return bool true if the section is current
776      */
777     protected function is_section_current($section, $course) {
778         return ($course->marker == $section->section);
779     }