MDL-37085 Substitute function print_section_add_menus() with core_course_renderer...
[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         $url = course_get_url($course, $section->section, array('navigation' => true));
69         if ($url) {
70             $title = html_writer::link($url, $title);
71         }
72         return $title;
73     }
75     /**
76      * Generate the content to displayed on the right part of a section
77      * before course modules are included
78      *
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      */
84     protected function section_right_content($section, $course, $onsectionpage) {
85         $o = $this->output->spacer();
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         }
94         return $o;
95     }
97     /**
98      * Generate the content to displayed on the left part of a section
99      * before course modules are included
100      *
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      */
106     protected function section_left_content($section, $course, $onsectionpage) {
107         $o = $this->output->spacer();
109         if ($section->section != 0) {
110             // Only in the non-general sections.
111             if (course_get_format($course)->is_section_current($section)) {
112                 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
113             }
114         }
116         return $o;
117     }
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
125      * @param bool $onsectionpage true if being printed on a single-section page
126      * @param int $sectionreturn The section to return to after an action
127      * @return string HTML to output.
128      */
129     protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
130         global $PAGE;
132         $o = '';
133         $currenttext = '';
134         $sectionstyle = '';
136         if ($section->section != 0) {
137             // Only in the non-general sections.
138             if (!$section->visible) {
139                 $sectionstyle = ' hidden';
140             } else if (course_get_format($course)->is_section_current($section)) {
141                 $sectionstyle = ' current';
142             }
143         }
145         $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
146             'class' => 'section main clearfix'.$sectionstyle));
148         $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
149         $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
151         $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
152         $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
153         $o.= html_writer::start_tag('div', array('class' => 'content'));
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)));
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)));
161         if ($hasnamenotsecpg || $hasnamesecpg) {
162             $o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
163         }
165         $o.= html_writer::start_tag('div', array('class' => 'summary'));
166         $o.= $this->format_summary_text($section);
168         $context = context_course::instance($course->id);
169         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
170             $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
171             $o.= html_writer::link($url,
172                 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'),
173                     'class' => 'iconsmall edit', 'alt' => get_string('edit'))),
174                 array('title' => get_string('editsummary')));
175         }
176         $o.= html_writer::end_tag('div');
178         $o .= $this->section_availability_message($section);
180         return $o;
181     }
183     /**
184      * Generate the display of the footer part of a section
185      *
186      * @return string HTML to output.
187      */
188     protected function section_footer() {
189         $o = html_writer::end_tag('div');
190         $o.= html_writer::end_tag('li');
192         return $o;
193     }
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      */
203     protected function section_edit_controls($course, $section, $onsectionpage = false) {
204         global $PAGE;
206         if (!$PAGE->user_is_editing()) {
207             return array();
208         }
210         $coursecontext = context_course::instance($course->id);
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 (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             }
238         }
240         if (!$onsectionpage && has_capability('moodle/course:movesections', $coursecontext)) {
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');
247                 $controls[] = html_writer::link($url,
248                     html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/up'),
249                     'class' => 'icon up', 'alt' => $strmoveup)),
250                     array('title' => $strmoveup, 'class' => 'moveup'));
251             }
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');
259                 $controls[] = html_writer::link($url,
260                     html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/down'),
261                     'class' => 'icon down', 'alt' => $strmovedown)),
262                     array('title' => $strmovedown, 'class' => 'movedown'));
263             }
264         }
266         return $controls;
267     }
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
274      * @param array    $mods (argument not used)
275      * @return string HTML to output.
276      */
277     protected function section_summary($section, $course, $mods) {
278         $classattr = 'section main section-summary clearfix';
279         $linkclasses = '';
281         // If section is hidden then display grey section link
282         if (!$section->visible) {
283             $classattr .= ' hidden';
284             $linkclasses .= ' dimmed_text';
285         } else if (course_get_format($course)->is_section_current($section)) {
286             $classattr .= ' current';
287         }
289         $o = '';
290         $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr));
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'));
296         $title = get_section_name($course, $section);
297         if ($section->uservisible) {
298             $title = html_writer::tag('a', $title,
299                     array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
300         }
301         $o .= $this->output->heading($title, 3, 'section-title');
303         $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
304         $o.= $this->format_summary_text($section);
305         $o.= html_writer::end_tag('div');
306         $o.= $this->section_activity_summary($section, $course, null);
308         $o.= $this->section_availability_message($section);
310         $o .= html_writer::end_tag('div');
311         $o .= html_writer::end_tag('li');
313         return $o;
314     }
316     /**
317      * Generate a summary of the activites in a section
318      *
319      * @param stdClass $section The course_section entry from DB
320      * @param stdClass $course the course record from DB
321      * @param array    $mods (argument not used)
322      * @return string HTML to output.
323      */
324     private function section_activity_summary($section, $course, $mods) {
325         $modinfo = get_fast_modinfo($course);
326         if (empty($modinfo->sections[$section->section])) {
327             return '';
328         }
330         // Generate array with count of activities in this section:
331         $sectionmods = array();
332         $total = 0;
333         $complete = 0;
334         $cancomplete = isloggedin() && !isguestuser();
335         $completioninfo = new completion_info($course);
336         foreach ($modinfo->sections[$section->section] as $cmid) {
337             $thismod = $modinfo->cms[$cmid];
339             if ($thismod->modname == 'label') {
340                 // Labels are special (not interesting for students)!
341                 continue;
342             }
344             if ($thismod->uservisible) {
345                 if (isset($sectionmods[$thismod->modname])) {
346                     $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
347                     $sectionmods[$thismod->modname]['count']++;
348                 } else {
349                     $sectionmods[$thismod->modname]['name'] = $thismod->modfullname;
350                     $sectionmods[$thismod->modname]['count'] = 1;
351                 }
352                 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
353                     $total++;
354                     $completiondata = $completioninfo->get_data($thismod, true);
355                     if ($completiondata->completionstate == COMPLETION_COMPLETE) {
356                         $complete++;
357                     }
358                 }
359             }
360         }
362         if (empty($sectionmods)) {
363             // No sections
364             return '';
365         }
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         }
375         $o.= html_writer::end_tag('div');
377         // Output section completion data
378         if ($total > 0) {
379             $a = new stdClass;
380             $a->complete = $complete;
381             $a->total = $total;
383             $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
384             $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
385             $o.= html_writer::end_tag('div');
386         }
388         return $o;
389     }
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 = '';
400         if (!$section->uservisible || $section->availableinfo) {
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     }
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      */
419     protected function course_activity_clipboard($course, $sectionno = null) {
420         global $USER;
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             );
432             $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
433             $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
434             $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
435             $o.= html_writer::end_tag('div');
436         }
438         return $o;
439     }
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
447      * @return array associative array with previous and next section link
448      */
449     protected function get_nav_links($course, $sections, $sectionno) {
450         // FIXME: This is really evil and should by using the navigation API.
451         $course = course_get_format($course)->get_course();
452         $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
453             or !$course->hiddensections;
455         $links = array('previous' => '', 'next' => '');
456         $back = $sectionno - 1;
457         while ($back > 0 and empty($links['previous'])) {
458             if ($canviewhidden || $sections[$back]->uservisible) {
459                 $params = array();
460                 if (!$sections[$back]->visible) {
461                     $params = array('class' => 'dimmed_text');
462                 }
463                 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
464                 $previouslink .= get_section_name($course, $sections[$back]);
465                 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
466             }
467             $back--;
468         }
470         $forward = $sectionno + 1;
471         while ($forward <= $course->numsections and empty($links['next'])) {
472             if ($canviewhidden || $sections[$forward]->uservisible) {
473                 $params = array();
474                 if (!$sections[$forward]->visible) {
475                     $params = array('class' => 'dimmed_text');
476                 }
477                 $nextlink = get_section_name($course, $sections[$forward]);
478                 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
479                 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
480             }
481             $forward++;
482         }
484         return $links;
485     }
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      */
493     protected function stealth_section_header($sectionno) {
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     }
503     /**
504      * Generate footer html of a stealth section
505      *
506      * @return string HTML to output.
507      */
508     protected function stealth_section_footer() {
509         $o = html_writer::end_tag('div');
510         $o.= html_writer::end_tag('li');
511         return $o;
512     }
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      */
520     protected function section_hidden($sectionno) {
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     }
532     /**
533      * Output the html for a single section page .
534      *
535      * @param stdClass $course The course entry from DB
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)
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;
545         $modinfo = get_fast_modinfo($course);
546         $course = course_get_format($course)->get_course();
547         $courserenderer = $this->page->get_renderer('core', 'course');
549         // Can we view the section in question?
550         if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
551             // This section doesn't exist
552             print_error('unknowncoursesection', 'error', null, $course->fullname);
553             return;
554         }
556         if (!$sectioninfo->uservisible) {
557             if (!$course->hiddensections) {
558                 echo $this->start_section_list();
559                 echo $this->section_hidden($displaysection);
560                 echo $this->end_section_list();
561             }
562             // Can't view this section.
563             return;
564         }
566         // Copy activity clipboard..
567         echo $this->course_activity_clipboard($course, $displaysection);
568         $thissection = $modinfo->get_section_info(0);
569         if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
570             echo $this->start_section_list();
571             echo $this->section_header($thissection, $course, true, $displaysection);
572             print_section($course, $thissection, null, null, true, "100%", false, $displaysection);
573             echo $courserenderer->course_section_add_cm_control($course, 0, $displaysection);
574             echo $this->section_footer();
575             echo $this->end_section_list();
576         }
578         // Start single-section div
579         echo html_writer::start_tag('div', array('class' => 'single-section'));
581         // The requested section page.
582         $thissection = $modinfo->get_section_info($displaysection);
584         // Title with section navigation links.
585         $sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection);
586         $sectiontitle = '';
587         $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
588         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
589         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
590         // Title attributes
591         $titleattr = 'mdl-align title';
592         if (!$thissection->visible) {
593             $titleattr .= ' dimmed_text';
594         }
595         $sectiontitle .= html_writer::tag('div', get_section_name($course, $displaysection), array('class' => $titleattr));
596         $sectiontitle .= html_writer::end_tag('div');
597         echo $sectiontitle;
599         // Now the list of sections..
600         echo $this->start_section_list();
602         echo $this->section_header($thissection, $course, true, $displaysection);
603         // Show completion help icon.
604         $completioninfo = new completion_info($course);
605         echo $completioninfo->display_help_icon();
607         print_section($course, $thissection, null, null, true, '100%', false, $displaysection);
608         echo $courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
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 (argument not used)
631      * @param array $mods (argument not used)
632      * @param array $modnames (argument not used)
633      * @param array $modnamesused (argument not used)
634      */
635     public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
636         global $PAGE;
638         $modinfo = get_fast_modinfo($course);
639         $course = course_get_format($course)->get_course();
641         $context = context_course::instance($course->id);
642         $courserenderer = $this->page->get_renderer('core', 'course');
643         // Title with completion help icon.
644         $completioninfo = new completion_info($course);
645         echo $completioninfo->display_help_icon();
646         echo $this->output->heading($this->page_title(), 2, 'accesshide');
648         // Copy activity clipboard..
649         echo $this->course_activity_clipboard($course, 0);
651         // Now the list of sections..
652         echo $this->start_section_list();
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);
660                     echo $courserenderer->course_section_add_cm_control($course, 0);
661                     echo $this->section_footer();
662                 }
663                 continue;
664             }
665             if ($section > $course->numsections) {
666                 // activities inside this section are 'orphaned', this section will be printed as 'stealth' below
667                 continue;
668             }
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) {
677                     echo $this->section_hidden($section);
678                 }
680                 continue;
681             }
683             if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
684                 // Display section summary only.
685                 echo $this->section_summary($thissection, $course, null);
686             } else {
687                 echo $this->section_header($thissection, $course, false, 0);
688                 if ($thissection->uservisible) {
689                     print_section($course, $thissection, null, null, true, "100%", false, 0);
690                     echo $courserenderer->course_section_add_cm_control($course, $section);
691                 }
692                 echo $this->section_footer();
693             }
694         }
696         if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
697             // Print stealth sections if present.
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
701                     continue;
702                 }
703                 echo $this->stealth_section_header($section);
704                 print_section($course, $thissection, null, null, true, "100%", false, 0);
705                 echo $this->stealth_section_footer();
706             }
708             echo $this->end_section_list();
710             echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
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'));
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             }
732             echo html_writer::end_tag('div');
733         } else {
734             echo $this->end_section_list();
735         }
737     }
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);
750         $options = new stdClass();
751         $options->noclean = true;
752         $options->overflowdiv = true;
753         return format_text($summarytext, $section->summaryformat, $options);
754     }
756     /**
757      * Is the section passed in the current section?
758      *
759      * @deprecated since 2.4
760      * @see format_base::is_section_current()
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      */
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);
770     }