MDL-36335 - course: Orphaned activities no longer show a notice.
[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 ($this->is_section_current($section, $course)) {
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 ($this->is_section_current($section, $course)) {
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:update', $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('t/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('t/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 course modules indexed by id (from get_all_mods)
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 ($this->is_section_current($section, $course)) {
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, $mods);
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 course modules indexed by id (from get_all_mods)
322      * @return string HTML to output.
323      */
324     private function section_activity_summary($section, $course, $mods) {
325         if (empty($section->sequence)) {
326             return '';
327         }
329         // Generate array with count of activities in this section:
330         $sectionmods = array();
331         $total = 0;
332         $complete = 0;
333         $cancomplete = isloggedin() && !isguestuser();
334         $completioninfo = new completion_info($course);
335         $modsequence = explode(',', $section->sequence);
336         foreach ($modsequence as $cmid) {
337             $thismod = $mods[$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]['count']++;
347                 } else {
348                     $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
349                     $sectionmods[$thismod->modname]['count'] = 1;
350                 }
351                 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
352                     $total++;
353                     $completiondata = $completioninfo->get_data($thismod, true);
354                     if ($completiondata->completionstate == COMPLETION_COMPLETE) {
355                         $complete++;
356                     }
357                 }
358             }
359         }
361         if (empty($sectionmods)) {
362             // No sections
363             return '';
364         }
366         // Output section activities summary:
367         $o = '';
368         $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
369         foreach ($sectionmods as $mod) {
370             $o.= html_writer::start_tag('span', array('class' => 'activity-count'));
371             $o.= $mod['name'].': '.$mod['count'];
372             $o.= html_writer::end_tag('span');
373         }
374         $o.= html_writer::end_tag('div');
376         // Output section completion data
377         if ($total > 0) {
378             $a = new stdClass;
379             $a->complete = $complete;
380             $a->total = $total;
382             $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
383             $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
384             $o.= html_writer::end_tag('div');
385         }
387         return $o;
388     }
390     /**
391      * If section is not visible to current user, display the message about that
392      * ('Not available until...', that sort of thing). Otherwise, returns blank.
393      *
394      * @param stdClass $section The course_section entry from DB
395      * @return string HTML to output
396      */
397     protected function section_availability_message($section) {
398         $o = '';
399         if (!$section->uservisible || $section->availableinfo) {
400             $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
401             if (!empty($section->availableinfo)) {
402                 $o .= $section->availableinfo;
403             } else {
404                 $o .= get_string('notavailable');
405             }
406             $o .= html_writer::end_tag('div');
407         }
408         return $o;
409     }
411     /**
412      * Show if something is on on the course clipboard (moving around)
413      *
414      * @param stdClass $course The course entry from DB
415      * @param int $sectionno The section number in the coruse which is being dsiplayed
416      * @return string HTML to output.
417      */
418     protected function course_activity_clipboard($course, $sectionno = null) {
419         global $USER;
421         $o = '';
422         // If currently moving a file then show the current clipboard.
423         if (ismoving($course->id)) {
424             $url = new moodle_url('/course/mod.php',
425                 array('sesskey' => sesskey(),
426                       'cancelcopy' => true,
427                       'sr' => $sectionno,
428                 )
429             );
431             $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
432             $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
433             $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
434             $o.= html_writer::end_tag('div');
435         }
437         return $o;
438     }
440     /**
441      * Generate next/previous section links for naviation
442      *
443      * @param stdClass $course The course entry from DB
444      * @param array $sections The course_sections entries from the DB
445      * @param int $sectionno The section number in the coruse which is being dsiplayed
446      * @return array associative array with previous and next section link
447      */
448     protected function get_nav_links($course, $sections, $sectionno) {
449         // FIXME: This is really evil and should by using the navigation API.
450         $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
451             or !$course->hiddensections;
453         $links = array('previous' => '', 'next' => '');
454         $back = $sectionno - 1;
455         while ($back > 0 and empty($links['previous'])) {
456             if ($canviewhidden || $sections[$back]->uservisible) {
457                 $params = array();
458                 if (!$sections[$back]->visible) {
459                     $params = array('class' => 'dimmed_text');
460                 }
461                 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
462                 $previouslink .= get_section_name($course, $sections[$back]);
463                 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
464             }
465             $back--;
466         }
468         $forward = $sectionno + 1;
469         while ($forward <= $course->numsections and empty($links['next'])) {
470             if ($canviewhidden || $sections[$forward]->uservisible) {
471                 $params = array();
472                 if (!$sections[$forward]->visible) {
473                     $params = array('class' => 'dimmed_text');
474                 }
475                 $nextlink = get_section_name($course, $sections[$forward]);
476                 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
477                 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
478             }
479             $forward++;
480         }
482         return $links;
483     }
485     /**
486      * Generate the header html of a stealth section
487      *
488      * @param int $sectionno The section number in the coruse which is being dsiplayed
489      * @return string HTML to output.
490      */
491     protected function stealth_section_header($sectionno) {
492         $o = '';
493         $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden'));
494         $o.= html_writer::tag('div', '', array('class' => 'left side'));
495         $o.= html_writer::tag('div', '', array('class' => 'right side'));
496         $o.= html_writer::start_tag('div', array('class' => 'content'));
497         $o.= $this->output->heading(get_string('orphanedactivities'), 3, 'sectionname');
498         return $o;
499     }
501     /**
502      * Generate footer html of a stealth section
503      *
504      * @return string HTML to output.
505      */
506     protected function stealth_section_footer() {
507         $o = html_writer::end_tag('div');
508         $o.= html_writer::end_tag('li');
509         return $o;
510     }
512     /**
513      * Generate the html for a hidden section
514      *
515      * @param int $sectionno The section number in the coruse which is being dsiplayed
516      * @return string HTML to output.
517      */
518     protected function section_hidden($sectionno) {
519         $o = '';
520         $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden'));
521         $o.= html_writer::tag('div', '', array('class' => 'left side'));
522         $o.= html_writer::tag('div', '', array('class' => 'right side'));
523         $o.= html_writer::start_tag('div', array('class' => 'content'));
524         $o.= get_string('notavailable');
525         $o.= html_writer::end_tag('div');
526         $o.= html_writer::end_tag('li');
527         return $o;
528     }
530     /**
531      * Output the html for a single 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      * @param int $displaysection The section number in the course which is being displayed
539      */
540     public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
541         global $PAGE;
543         // Can we view the section in question?
544         $context = context_course::instance($course->id);
545         $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
547         if (!isset($sections[$displaysection])) {
548             // This section doesn't exist
549             print_error('unknowncoursesection', 'error', null, $course->fullname);
550             return;
551         }
553         if (!$sections[$displaysection]->visible && !$canviewhidden) {
554             if (!$course->hiddensections) {
555                 echo $this->start_section_list();
556                 echo $this->section_hidden($displaysection);
557                 echo $this->end_section_list();
558             }
559             // Can't view this section.
560             return;
561         }
563         // Copy activity clipboard..
564         echo $this->course_activity_clipboard($course, $displaysection);
566         // General section if non-empty.
567         $thissection = $sections[0];
568         if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
569             echo $this->start_section_list();
570             echo $this->section_header($thissection, $course, true, $displaysection);
571             print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
572             if ($PAGE->user_is_editing()) {
573                 print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
574             }
575             echo $this->section_footer();
576             echo $this->end_section_list();
577         }
579         // Start single-section div
580         echo html_writer::start_tag('div', array('class' => 'single-section'));
582         // Title with section navigation links.
583         $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
584         $sectiontitle = '';
585         $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
586         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
587         $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
588         // Title attributes
589         $titleattr = 'mdl-align title';
590         if (!$sections[$displaysection]->visible) {
591             $titleattr .= ' dimmed_text';
592         }
593         $sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
594         $sectiontitle .= html_writer::end_tag('div');
595         echo $sectiontitle;
597         // Now the list of sections..
598         echo $this->start_section_list();
600         // The requested section page.
601         $thissection = $sections[$displaysection];
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, $mods, $modnamesused, true, '100%', false, $displaysection);
608         if ($PAGE->user_is_editing()) {
609             print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
610         }
611         echo $this->section_footer();
612         echo $this->end_section_list();
614         // Display section bottom navigation.
615         $courselink = html_writer::link(course_get_url($course), get_string('returntomaincoursepage'));
616         $sectionbottomnav = '';
617         $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
618         $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
619         $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
620         $sectionbottomnav .= html_writer::tag('div', $courselink, array('class' => 'mdl-align'));
621         $sectionbottomnav .= html_writer::end_tag('div');
622         echo $sectionbottomnav;
624         // close single-section div.
625         echo html_writer::end_tag('div');
626     }
628     /**
629      * Output the html for a multiple section page
630      *
631      * @param stdClass $course The course entry from DB
632      * @param array $sections The course_sections entries from the DB
633      * @param array $mods used for print_section()
634      * @param array $modnames used for print_section()
635      * @param array $modnamesused used for print_section()
636      */
637     public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
638         global $PAGE;
640         $context = context_course::instance($course->id);
641         // Title with completion help icon.
642         $completioninfo = new completion_info($course);
643         echo $completioninfo->display_help_icon();
644         echo $this->output->heading($this->page_title(), 2, 'accesshide');
646         // Copy activity clipboard..
647         echo $this->course_activity_clipboard($course, 0);
649         // Now the list of sections..
650         echo $this->start_section_list();
652         // General section if non-empty.
653         $thissection = $sections[0];
654         unset($sections[0]);
655         if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
656             echo $this->section_header($thissection, $course, false, 0);
657             print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
658             if ($PAGE->user_is_editing()) {
659                 print_section_add_menus($course, 0, $modnames, false, false, 0);
660             }
661             echo $this->section_footer();
662         }
664         $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
665         for ($section = 1; $section <= $course->numsections; $section++) {
666             if (!empty($sections[$section])) {
667                 $thissection = $sections[$section];
668             } else {
669                 // This will create a course section if it doesn't exist..
670                 $thissection = get_course_section($section, $course->id);
672                 // The returned section is only a bare database object rather than
673                 // a section_info object - we will need at least the uservisible
674                 // field in it.
675                 $thissection->uservisible = true;
676                 $thissection->availableinfo = null;
677                 $thissection->showavailability = 0;
678             }
679             // Show the section if the user is permitted to access it, OR if it's not available
680             // but showavailability is turned on
681             $showsection = $thissection->uservisible ||
682                     ($thissection->visible && !$thissection->available && $thissection->showavailability);
683             if (!$showsection) {
684                 // Hidden section message is overridden by 'unavailable' control
685                 // (showavailability option).
686                 if (!$course->hiddensections && $thissection->available) {
687                     echo $this->section_hidden($section);
688                 }
690                 unset($sections[$section]);
691                 continue;
692             }
694             if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
695                 // Display section summary only.
696                 echo $this->section_summary($thissection, $course, $mods);
697             } else {
698                 echo $this->section_header($thissection, $course, false, 0);
699                 if ($thissection->uservisible) {
700                     print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
701                     if ($PAGE->user_is_editing()) {
702                         print_section_add_menus($course, $section, $modnames, false, false, 0);
703                     }
704                 }
705                 echo $this->section_footer();
706             }
708             unset($sections[$section]);
709         }
711         if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
712             // Print stealth sections if present.
713             $modinfo = get_fast_modinfo($course);
714             foreach ($sections as $section => $thissection) {
715                 if (empty($modinfo->sections[$section])) {
716                     continue;
717                 }
718                 echo $this->stealth_section_header($section);
719                 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
720                 echo $this->stealth_section_footer();
721             }
723             echo $this->end_section_list();
725             echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
727             // Increase number of sections.
728             $straddsection = get_string('increasesections', 'moodle');
729             $url = new moodle_url('/course/changenumsections.php',
730                 array('courseid' => $course->id,
731                       'increase' => true,
732                       'sesskey' => sesskey()));
733             $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
734             echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
736             if ($course->numsections > 0) {
737                 // Reduce number of sections sections.
738                 $strremovesection = get_string('reducesections', 'moodle');
739                 $url = new moodle_url('/course/changenumsections.php',
740                     array('courseid' => $course->id,
741                           'increase' => false,
742                           'sesskey' => sesskey()));
743                 $icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
744                 echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
745             }
747             echo html_writer::end_tag('div');
748         } else {
749             echo $this->end_section_list();
750         }
752     }
754     /**
755      * Generate html for a section summary text
756      *
757      * @param stdClass $section The course_section entry from DB
758      * @return string HTML to output.
759      */
760     protected function format_summary_text($section) {
761         $context = context_course::instance($section->course);
762         $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
763             $context->id, 'course', 'section', $section->id);
765         $options = new stdClass();
766         $options->noclean = true;
767         $options->overflowdiv = true;
768         return format_text($summarytext, $section->summaryformat, $options);
769     }
771     /**
772      * Is the section passed in the current section? (Note this isn't strictly
773      * a renderering method, but neater here).
774      *
775      * @param stdClass $course The course entry from DB
776      * @param stdClass $section The course_section entry from the DB
777      * @return bool true if the section is current
778      */
779     protected function is_section_current($section, $course) {
780         return ($course->marker == $section->section);
781     }