MDL-36335 - course: Orphaned activities no longer show a notice.
[moodle.git] / course / format / renderer.php
CommitLineData
1804b7c1
DP
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Base renderer for outputting course formats.
19 *
20 * @package core
21 * @copyright 2012 Dan Poltawski
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 2.3
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28
29/**
a8f02a34 30 * This is a convenience renderer which can be used by section based formats
3df72f8c 31 * to reduce code duplication. It is not necessary for all course formats to
a8f02a34 32 * use this and its likely to change in future releases.
1804b7c1
DP
33 *
34 * @package core
35 * @copyright 2012 Dan Poltawski
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 * @since Moodle 2.3
38 */
a8f02a34 39abstract class format_section_renderer_base extends plugin_renderer_base {
1804b7c1
DP
40
41 /**
42 * Generate the starting container html for a list of sections
43 * @return string HTML to output.
44 */
cbf44997 45 abstract protected function start_section_list();
1804b7c1
DP
46
47 /**
48 * Generate the closing container html for a list of sections
49 * @return string HTML to output.
50 */
cbf44997 51 abstract protected function end_section_list();
1804b7c1
DP
52
53 /**
54 * Generate the title for this section page
55 * @return string the page title
56 */
cbf44997 57 abstract protected function page_title();
1804b7c1 58
9f3015ec
RK
59 /**
60 * Generate the section title
61 *
62 * @param stdClass $section The course_section entry from DB
63 * @param stdClass $course The course entry from DB
64 * @return string HTML to output.
65 */
66 public function section_title($section, $course) {
67 $title = get_section_name($course, $section);
583c0cf6
MG
68 $url = course_get_url($course, $section->section, array('navigation' => true));
69 if ($url) {
70 $title = html_writer::link($url, $title);
9f3015ec
RK
71 }
72 return $title;
73 }
74
a830d866
DP
75 /**
76 * Generate the content to displayed on the right part of a section
a830d866 77 * before course modules are included
96e12851 78 *
a830d866
DP
79 * @param stdClass $section The course_section entry from DB
80 * @param stdClass $course The course entry from DB
81 * @param bool $onsectionpage true if being printed on a section page
82 * @return string HTML to output.
83 */
cbf44997 84 protected function section_right_content($section, $course, $onsectionpage) {
a830d866
DP
85 $o = $this->output->spacer();
86
87 if ($section->section != 0) {
88 $controls = $this->section_edit_controls($course, $section, $onsectionpage);
89 if (!empty($controls)) {
90 $o = implode('<br />', $controls);
91 }
92 }
93
94 return $o;
95 }
96
97 /**
98 * Generate the content to displayed on the left part of a section
a830d866 99 * before course modules are included
96e12851 100 *
a830d866
DP
101 * @param stdClass $section The course_section entry from DB
102 * @param stdClass $course The course entry from DB
103 * @param bool $onsectionpage true if being printed on a section page
104 * @return string HTML to output.
105 */
cbf44997 106 protected function section_left_content($section, $course, $onsectionpage) {
a830d866
DP
107 $o = $this->output->spacer();
108
109 if ($section->section != 0) {
110 // Only in the non-general sections.
2ea6533a 111 if ($this->is_section_current($section, $course)) {
a830d866
DP
112 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
113 }
114 }
115
116 return $o;
117 }
118
1804b7c1
DP
119 /**
120 * Generate the display of the header part of a section before
121 * course modules are included
122 *
123 * @param stdClass $section The course_section entry from DB
124 * @param stdClass $course The course entry from DB
9f3015ec 125 * @param bool $onsectionpage true if being printed on a single-section page
483d768b 126 * @param int $sectionreturn The section to return to after an action
1804b7c1
DP
127 * @return string HTML to output.
128 */
583c0cf6 129 protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
1804b7c1
DP
130 global $PAGE;
131
132 $o = '';
133 $currenttext = '';
134 $sectionstyle = '';
1804b7c1 135
96e12851 136 if ($section->section != 0) {
1804b7c1
DP
137 // Only in the non-general sections.
138 if (!$section->visible) {
139 $sectionstyle = ' hidden';
2ea6533a 140 } else if ($this->is_section_current($section, $course)) {
1804b7c1 141 $sectionstyle = ' current';
1804b7c1 142 }
1804b7c1
DP
143 }
144
145 $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
146 'class' => 'section main clearfix'.$sectionstyle));
a830d866
DP
147
148 $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
1804b7c1 149 $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
a830d866
DP
150
151 $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
1804b7c1
DP
152 $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
153 $o.= html_writer::start_tag('div', array('class' => 'content'));
154
a64fbc87
FM
155 // When not on a section page, we display the section titles except the general section if null
156 $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
157
158 // When on a section page, we only display the general section title, if title is not the default one
159 $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
160
161 if ($hasnamenotsecpg || $hasnamesecpg) {
9f3015ec 162 $o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
1804b7c1
DP
163 }
164
165 $o.= html_writer::start_tag('div', array('class' => 'summary'));
7cb8bfdb 166 $o.= $this->format_summary_text($section);
1804b7c1 167
7cb8bfdb 168 $context = context_course::instance($course->id);
1804b7c1 169 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
483d768b 170 $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
1804b7c1 171 $o.= html_writer::link($url,
05daea0f 172 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'),
792a3c4e 173 'class' => 'iconsmall edit', 'alt' => get_string('edit'))),
1804b7c1
DP
174 array('title' => get_string('editsummary')));
175 }
176 $o.= html_writer::end_tag('div');
177
ce4dfd27 178 $o .= $this->section_availability_message($section);
179
1804b7c1
DP
180 return $o;
181 }
182
183 /**
184 * Generate the display of the footer part of a section
185 *
186 * @return string HTML to output.
187 */
cbf44997 188 protected function section_footer() {
1804b7c1
DP
189 $o = html_writer::end_tag('div');
190 $o.= html_writer::end_tag('li');
191
192 return $o;
193 }
194
195 /**
196 * Generate the edit controls of a section
197 *
198 * @param stdClass $course The course entry from DB
199 * @param stdClass $section The course_section entry from DB
200 * @param bool $onsectionpage true if being printed on a section page
201 * @return array of links with edit controls
202 */
cbf44997 203 protected function section_edit_controls($course, $section, $onsectionpage = false) {
1804b7c1
DP
204 global $PAGE;
205
206 if (!$PAGE->user_is_editing()) {
207 return array();
208 }
209
84af4013 210 $coursecontext = context_course::instance($course->id);
1804b7c1
DP
211
212 if ($onsectionpage) {
213 $baseurl = course_get_url($course, $section->section);
214 } else {
215 $baseurl = course_get_url($course);
216 }
217 $baseurl->param('sesskey', sesskey());
218
219 $controls = array();
220
221 $url = clone($baseurl);
84af4013
FM
222 if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
223 if ($section->visible) { // Show the hide/show eye.
224 $strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
225 $url->param('hide', $section->section);
226 $controls[] = html_writer::link($url,
227 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
228 'class' => 'icon hide', 'alt' => $strhidefromothers)),
229 array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
230 } else {
231 $strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
232 $url->param('show', $section->section);
233 $controls[] = html_writer::link($url,
234 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
235 'class' => 'icon hide', 'alt' => $strshowfromothers)),
236 array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
237 }
1804b7c1
DP
238 }
239
84af4013 240 if (!$onsectionpage && has_capability('moodle/course:update', $coursecontext)) {
1804b7c1
DP
241 $url = clone($baseurl);
242 if ($section->section > 1) { // Add a arrow to move section up.
243 $url->param('section', $section->section);
244 $url->param('move', -1);
245 $strmoveup = get_string('moveup');
246
247 $controls[] = html_writer::link($url,
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 }
252
253 $url = clone($baseurl);
254 if ($section->section < $course->numsections) { // Add a arrow to move section down.
255 $url->param('section', $section->section);
256 $url->param('move', 1);
257 $strmovedown = get_string('movedown');
258
259 $controls[] = html_writer::link($url,
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 }
265
266 return $controls;
267 }
268
269 /**
270 * Generate a summary of a section for display on the 'coruse index page'
271 *
272 * @param stdClass $section The course_section entry from DB
273 * @param stdClass $course The course entry from DB
d87debaa 274 * @param array $mods course modules indexed by id (from get_all_mods)
1804b7c1
DP
275 * @return string HTML to output.
276 */
d87debaa 277 protected function section_summary($section, $course, $mods) {
76055f5d
FM
278 $classattr = 'section main section-summary clearfix';
279 $linkclasses = '';
280
bcf7175f 281 // If section is hidden then display grey section link
76055f5d
FM
282 if (!$section->visible) {
283 $classattr .= ' hidden';
284 $linkclasses .= ' dimmed_text';
285 } else if ($this->is_section_current($section, $course)) {
286 $classattr .= ' current';
bcf7175f 287 }
1804b7c1
DP
288
289 $o = '';
76055f5d 290 $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr));
1804b7c1 291
76055f5d
FM
292 $o .= html_writer::tag('div', '', array('class' => 'left side'));
293 $o .= html_writer::tag('div', '', array('class' => 'right side'));
294 $o .= html_writer::start_tag('div', array('class' => 'content'));
295
e1269d87 296 $title = get_section_name($course, $section);
ccce6a7e 297 if ($section->uservisible) {
e1269d87 298 $title = html_writer::tag('a', $title,
ccce6a7e 299 array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
ccce6a7e 300 }
e1269d87 301 $o .= $this->output->heading($title, 3, 'section-title');
1804b7c1
DP
302
303 $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
7cb8bfdb 304 $o.= $this->format_summary_text($section);
1804b7c1 305 $o.= html_writer::end_tag('div');
7c05cd0e 306 $o.= $this->section_activity_summary($section, $course, $mods);
ce4dfd27 307
d87debaa 308 $o.= $this->section_availability_message($section);
ce4dfd27 309
76055f5d
FM
310 $o .= html_writer::end_tag('div');
311 $o .= html_writer::end_tag('li');
1804b7c1
DP
312
313 return $o;
314 }
315
d87debaa
DP
316 /**
317 * Generate a summary of the activites in a section
318 *
319 * @param stdClass $section The course_section entry from DB
7c05cd0e 320 * @param stdClass $course the course record from DB
d87debaa
DP
321 * @param array $mods course modules indexed by id (from get_all_mods)
322 * @return string HTML to output.
323 */
7c05cd0e 324 private function section_activity_summary($section, $course, $mods) {
d87debaa
DP
325 if (empty($section->sequence)) {
326 return '';
327 }
328
329 // Generate array with count of activities in this section:
330 $sectionmods = array();
7c05cd0e
AA
331 $total = 0;
332 $complete = 0;
0e5533b6
SH
333 $cancomplete = isloggedin() && !isguestuser();
334 $completioninfo = new completion_info($course);
d87debaa
DP
335 $modsequence = explode(',', $section->sequence);
336 foreach ($modsequence as $cmid) {
337 $thismod = $mods[$cmid];
338
00c41b40
DP
339 if ($thismod->modname == 'label') {
340 // Labels are special (not interesting for students)!
341 continue;
342 }
343
d87debaa
DP
344 if ($thismod->uservisible) {
345 if (isset($sectionmods[$thismod->modname])) {
346 $sectionmods[$thismod->modname]['count']++;
347 } else {
348 $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
349 $sectionmods[$thismod->modname]['count'] = 1;
350 }
0e5533b6 351 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
7c05cd0e 352 $total++;
0e5533b6 353 $completiondata = $completioninfo->get_data($thismod, true);
7c05cd0e
AA
354 if ($completiondata->completionstate == COMPLETION_COMPLETE) {
355 $complete++;
356 }
357 }
d87debaa
DP
358 }
359 }
360
361 if (empty($sectionmods)) {
362 // No sections
363 return '';
364 }
365
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 }
dce49c1c 374 $o.= html_writer::end_tag('div');
7c05cd0e
AA
375
376 // Output section completion data
0e5533b6
SH
377 if ($total > 0) {
378 $a = new stdClass;
379 $a->complete = $complete;
380 $a->total = $total;
381
dce49c1c 382 $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
0e5533b6 383 $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
dce49c1c 384 $o.= html_writer::end_tag('div');
7c05cd0e 385 }
dce49c1c 386
d87debaa
DP
387 return $o;
388 }
389
ce4dfd27 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 = '';
5316007e 399 if (!$section->uservisible || $section->availableinfo) {
ce4dfd27 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 }
410
1804b7c1
DP
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 */
583c0cf6 418 protected function course_activity_clipboard($course, $sectionno = null) {
1804b7c1
DP
419 global $USER;
420
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 );
430
76055f5d 431 $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
1804b7c1
DP
432 $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
433 $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
76055f5d 434 $o.= html_writer::end_tag('div');
1804b7c1
DP
435 }
436
437 return $o;
438 }
439
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
36be7e14 446 * @return array associative array with previous and next section link
1804b7c1 447 */
cbf44997 448 protected function get_nav_links($course, $sections, $sectionno) {
1804b7c1
DP
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;
452
453 $links = array('previous' => '', 'next' => '');
454 $back = $sectionno - 1;
455 while ($back > 0 and empty($links['previous'])) {
4486aa99 456 if ($canviewhidden || $sections[$back]->uservisible) {
bcf7175f
RT
457 $params = array();
458 if (!$sections[$back]->visible) {
459 $params = array('class' => 'dimmed_text');
460 }
36be7e14
RT
461 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
462 $previouslink .= get_section_name($course, $sections[$back]);
bcf7175f 463 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
1804b7c1
DP
464 }
465 $back--;
466 }
467
468 $forward = $sectionno + 1;
469 while ($forward <= $course->numsections and empty($links['next'])) {
4486aa99 470 if ($canviewhidden || $sections[$forward]->uservisible) {
bcf7175f
RT
471 $params = array();
472 if (!$sections[$forward]->visible) {
473 $params = array('class' => 'dimmed_text');
474 }
36be7e14
RT
475 $nextlink = get_section_name($course, $sections[$forward]);
476 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
bcf7175f 477 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
1804b7c1
DP
478 }
479 $forward++;
480 }
481
36be7e14 482 return $links;
1804b7c1
DP
483 }
484
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 */
cbf44997 491 protected function stealth_section_header($sectionno) {
1804b7c1
DP
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 }
500
501 /**
502 * Generate footer html of a stealth section
503 *
504 * @return string HTML to output.
505 */
cbf44997 506 protected function stealth_section_footer() {
1804b7c1
DP
507 $o = html_writer::end_tag('div');
508 $o.= html_writer::end_tag('li');
509 return $o;
510 }
511
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 */
cbf44997 518 protected function section_hidden($sectionno) {
1804b7c1
DP
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 }
529
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;
542
1804b7c1
DP
543 // Can we view the section in question?
544 $context = context_course::instance($course->id);
545 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
546
0c053c53
ARN
547 if (!isset($sections[$displaysection])) {
548 // This section doesn't exist
549 print_error('unknowncoursesection', 'error', null, $course->fullname);
550 return;
551 }
552
1804b7c1
DP
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();
1804b7c1
DP
558 }
559 // Can't view this section.
560 return;
561 }
562
76055f5d
FM
563 // Copy activity clipboard..
564 echo $this->course_activity_clipboard($course, $displaysection);
565
243b7003
DP
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();
483d768b
FM
570 echo $this->section_header($thissection, $course, true, $displaysection);
571 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
243b7003 572 if ($PAGE->user_is_editing()) {
483d768b 573 print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
243b7003
DP
574 }
575 echo $this->section_footer();
576 echo $this->end_section_list();
577 }
578
c129f430
RT
579 // Start single-section div
580 echo html_writer::start_tag('div', array('class' => 'single-section'));
581
36be7e14 582 // Title with section navigation links.
243b7003 583 $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
36be7e14 584 $sectiontitle = '';
c129f430 585 $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
36be7e14
RT
586 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
587 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
bcf7175f
RT
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));
36be7e14
RT
594 $sectiontitle .= html_writer::end_tag('div');
595 echo $sectiontitle;
596
1804b7c1
DP
597 // Now the list of sections..
598 echo $this->start_section_list();
599
1804b7c1
DP
600 // The requested section page.
601 $thissection = $sections[$displaysection];
483d768b 602 echo $this->section_header($thissection, $course, true, $displaysection);
c129f430
RT
603 // Show completion help icon.
604 $completioninfo = new completion_info($course);
605 echo $completioninfo->display_help_icon();
606
483d768b 607 print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
1804b7c1 608 if ($PAGE->user_is_editing()) {
483d768b 609 print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
1804b7c1
DP
610 }
611 echo $this->section_footer();
1804b7c1 612 echo $this->end_section_list();
36be7e14
RT
613
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;
c129f430
RT
623
624 // close single-section div.
625 echo html_writer::end_tag('div');
1804b7c1
DP
626 }
627
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;
639
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();
803e36e1 644 echo $this->output->heading($this->page_title(), 2, 'accesshide');
1804b7c1
DP
645
646 // Copy activity clipboard..
583c0cf6 647 echo $this->course_activity_clipboard($course, 0);
1804b7c1
DP
648
649 // Now the list of sections..
650 echo $this->start_section_list();
651
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()) {
583c0cf6
MG
656 echo $this->section_header($thissection, $course, false, 0);
657 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
1804b7c1 658 if ($PAGE->user_is_editing()) {
583c0cf6 659 print_section_add_menus($course, 0, $modnames, false, false, 0);
1804b7c1
DP
660 }
661 echo $this->section_footer();
662 }
663
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);
52f14061 671
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;
57a42a24 676 $thissection->availableinfo = null;
677 $thissection->showavailability = 0;
1804b7c1 678 }
ce4dfd27 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) {
1804b7c1
DP
687 echo $this->section_hidden($section);
688 }
689
690 unset($sections[$section]);
691 continue;
692 }
693
694 if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
695 // Display section summary only.
d87debaa 696 echo $this->section_summary($thissection, $course, $mods);
1804b7c1 697 } else {
583c0cf6 698 echo $this->section_header($thissection, $course, false, 0);
ce4dfd27 699 if ($thissection->uservisible) {
583c0cf6 700 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
ce4dfd27 701 if ($PAGE->user_is_editing()) {
583c0cf6 702 print_section_add_menus($course, $section, $modnames, false, false, 0);
ce4dfd27 703 }
1804b7c1
DP
704 }
705 echo $this->section_footer();
706 }
707
708 unset($sections[$section]);
709 }
710
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);
6990c105 719 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
1804b7c1
DP
720 echo $this->stealth_section_footer();
721 }
1abf1253 722
575826c7
ARN
723 echo $this->end_section_list();
724
54495fe4 725 echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
3a35a9ff
DP
726
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'));
735
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 }
746
1abf1253 747 echo html_writer::end_tag('div');
575826c7
ARN
748 } else {
749 echo $this->end_section_list();
1804b7c1
DP
750 }
751
1804b7c1 752 }
7cb8bfdb
DP
753
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);
764
765 $options = new stdClass();
766 $options->noclean = true;
767 $options->overflowdiv = true;
768 return format_text($summarytext, $section->summaryformat, $options);
769 }
2ea6533a
DP
770
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 }
1804b7c1 782}