forked from gjbarnard/moodle-format_topcoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
1238 lines (1112 loc) · 57.1 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Collapsed Topics Information
*
* A topic based format that solves the issue of the 'Scroll of Death' when a course has many topics. All topics
* except zero have a toggle that displays that topic. One or more topics can be displayed at any given time.
* Toggles are persistent on a per browser session per course basis but can be made to persist longer by a small
* code change. Full installation instructions, code adaptions and credits are included in the 'Readme.txt' file.
*
* @package course/format
* @subpackage topcoll
* @version See the value of '$plugin->version' in version.php.
* @copyright © 2012-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/format/renderer.php');
require_once($CFG->dirroot . '/course/format/topcoll/lib.php');
class format_topcoll_renderer extends format_section_renderer_base {
protected $tccolumnwidth = 100; // Default width in percent of the column(s).
protected $tccolumnpadding = 0; // Default padding in pixels of the column(s).
protected $mobiletheme = false; // As not using a mobile theme we can react to the number of columns setting.
protected $tablettheme = false; // As not using a tablet theme we can react to the number of columns setting.
protected $courseformat = null; // Our course format object as defined in lib.php;
protected $tcsettings; // Settings for the format - array.
protected $defaulttogglepersistence; // Default toggle persistence.
protected $defaultuserpreference; // Default user preference when none set - bool - true all open, false all closed.
protected $togglelib;
protected $currentsection = false; // If not false then will be the current section number.
protected $isoldtogglepreference = false;
protected $userisediting = false;
protected $tctoggleiconsize;
protected $formatresponsive;
protected $rtl = false;
protected $bsnewgrid = false;
/**
* Constructor method, calls the parent constructor - MDL-21097.
*
* @param moodle_page $page.
* @param string $target one of rendering target constants.
*/
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
$this->courserenderer = $this->page->get_renderer('format_topcoll', 'course');
$this->togglelib = new \format_topcoll\togglelib;
$this->courseformat = course_get_format($page->course); // Needed for collapsed topics settings retrieval.
/* Since format_topcoll_renderer::section_edit_control_items() only displays the 'Set current section' control when editing
mode is on we need to be sure that the link 'Turn editing mode on' is available for a user who does not have any
other managing capability. */
$page->set_other_editing_capability('moodle/course:setcurrentsection');
$this->userisediting = $page->user_is_editing();
$this->tctoggleiconsize = clean_param(get_config('format_topcoll', 'defaulttoggleiconsize'), PARAM_TEXT);
$this->formatresponsive = get_config('format_topcoll', 'formatresponsive');
$this->rtl = right_to_left();
if (strcmp($page->theme->name, 'boost') === 0) {
$this->bsnewgrid = true;
} else if (!empty($page->theme->parents)) {
if (in_array('boost', $page->theme->parents) === true) {
$this->bsnewgrid = true;
}
}
}
/**
* Generate the starting container html for a list of sections.
* @return string HTML to output.
*/
protected function start_section_list() {
if ($this->bsnewgrid) {
return html_writer::start_tag('ul', array('class' => 'ctopics bsnewgrid'));
} else {
return html_writer::start_tag('ul', array('class' => 'ctopics'));
}
}
/**
* Generate the starting container html for a list of sections when showing a toggle.
* @return string HTML to output.
*/
protected function start_toggle_section_list() {
$classes = 'ctopics topics';
if ($this->bsnewgrid) {
$classes .= ' bsnewgrid';
}
$attributes = array();
if (($this->mobiletheme === true) || ($this->tablettheme === true)) {
$classes .= ' ctportable';
}
if ($this->formatresponsive) {
$style = '';
if ($this->tcsettings['layoutcolumnorientation'] == 1) { // Vertical columns.
$style .= 'width:' . $this->tccolumnwidth . '%;';
} else {
$style .= 'width: 100%;'; // Horizontal columns.
}
if ($this->mobiletheme === false) {
$classes .= ' ctlayout';
}
$style .= ' padding-left: ' . $this->tccolumnpadding . 'px; padding-right: ' . $this->tccolumnpadding . 'px;';
$attributes['style'] = $style;
} else {
if ($this->tcsettings['layoutcolumnorientation'] == 1) { // Vertical columns.
$classes .= ' ' . $this->get_column_class($this->tcsettings['layoutcolumns']);
} else {
$classes .= ' ' . $this->get_row_class();
}
}
$attributes['class'] = $classes;
return html_writer::start_tag('ul', $attributes);
}
/**
* Generate the closing container html for a list of sections.
* @return string HTML to output.
*/
protected function end_section_list() {
return html_writer::end_tag('ul');
}
/**
* Generate the title for this section page.
* @return string the page title.
*/
protected function page_title() {
return get_string('sectionname', 'format_topcoll');
}
/**
* Generate the content to displayed on the right part of a section
* before course modules are included.
*
* @param stdClass $section The course_section entry from DB.
* @param stdClass $course The course entry from DB.
* @param bool $onsectionpage true if being printed on a section page.
* @return string HTML to output.
*/
protected function section_right_content($section, $course, $onsectionpage) {
$o = '';
if ($section->section != 0) {
$controls = $this->section_edit_control_items($course, $section, $onsectionpage);
if (!empty($controls)) {
$o .= $this->section_edit_control_menu($controls, $course, $section);
} else if (!$onsectionpage) {
if (empty($this->tcsettings)) {
$this->tcsettings = $this->courseformat->get_settings();
}
$url = new moodle_url('/course/view.php', array('id' => $course->id, 'section' => $section->section));
// Get the specific words from the language files.
$topictext = null;
if (($this->tcsettings['layoutstructure'] == 1) || ($this->tcsettings['layoutstructure'] == 4)) {
$topictext = get_string('setlayoutstructuretopic', 'format_topcoll');
} else if (($this->tcsettings['layoutstructure'] == 2) || ($this->tcsettings['layoutstructure'] == 3)) {
$topictext = get_string('setlayoutstructureweek', 'format_topcoll');
} else {
$topictext = get_string('setlayoutstructureday', 'format_topcoll');
}
$title = get_string('viewonly', 'format_topcoll', array('sectionname' => $topictext.' '.$section->section));
switch ($this->tcsettings['layoutelement']) { // Toggle section x.
case 1:
case 3:
case 5:
case 8:
$o .= html_writer::link($url,
$topictext.html_writer::empty_tag('br').
$section->section, array('title' => $title, 'class' => 'cps_centre'));
break;
default:
$o .= html_writer::link($url,
$this->output->pix_icon('one_section', $title, 'format_topcoll'),
array('title' => $title, 'class' => 'cps_centre'));
break;
}
}
}
return $o;
}
/**
* Generate the content to displayed on the left part of a section
* before course modules are included.
*
* @param stdClass $section The course_section entry from DB.
* @param stdClass $course The course entry from DB.
* @param bool $onsectionpage true if being printed on a section page.
* @return string HTML to output.
*/
protected function section_left_content($section, $course, $onsectionpage) {
$o = '';
if (($section->section != 0) && (!$onsectionpage)) {
// Only in the non-general sections.
if ($this->courseformat->is_section_current($section)) {
$o .= get_accesshide(get_string('currentsection', 'format_' . $course->format));
}
if (empty($this->tcsettings)) {
$this->tcsettings = $this->courseformat->get_settings();
}
switch ($this->tcsettings['layoutelement']) {
case 1:
case 2:
case 5:
case 6:
$o .= html_writer::tag('span', $section->section, array('class' => 'cps_centre'));
break;
}
}
return $o;
}
/**
* Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title($section, $course) {
return $this->render($this->courseformat->inplace_editable_render_section_name($section));
}
/**
* Generate the section title to be displayed on the section page, without a link
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title_without_link($section, $course) {
return $this->render($this->courseformat->inplace_editable_render_section_name($section, false));
}
/**
* Generate the edit controls of a section.
*
* @param stdClass $course The course entry from DB.
* @param stdClass $section The course_section entry from DB.
* @param bool $onsectionpage true if being printed on a section page.
* @return array of links with edit controls.
*/
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
if (!$this->userisediting) {
return array();
}
$coursecontext = context_course::instance($course->id);
$sectionreturn = $onsectionpage ? $section->section : null;
$url = course_get_url($course, $sectionreturn);
$url->param('sesskey', sesskey());
if (empty($this->tcsettings)) {
$this->tcsettings = $this->courseformat->get_settings();
}
$controls = array();
if ((($this->tcsettings['layoutstructure'] == 1) || ($this->tcsettings['layoutstructure'] == 4)) &&
$section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
if ($course->marker == $section->section) { // Show the "light globe" on/off.
$url->param('marker', 0);
$markedthissection = get_string('markedthissection', 'format_topcoll');
$highlightoff = get_string('highlightoff');
$controls['highlight'] = array('url' => $url, "icon" => 'i/marked',
'name' => $highlightoff,
'pixattr' => array('class' => '', 'alt' => $markedthissection),
'attr' => array('class' => 'editing_highlight', 'title' => $markedthissection,
'data-action' => 'removemarker'));
} else {
$url->param('marker', $section->section);
$markthissection = get_string('markthissection', 'format_topcoll');
$highlight = get_string('highlight');
$controls['highlight'] = array('url' => $url, "icon" => 'i/marker',
'name' => $highlight,
'pixattr' => array('class' => '', 'alt' => $markthissection),
'attr' => array('class' => 'editing_highlight', 'title' => $markthissection,
'data-action' => 'setmarker'));
}
}
$parentcontrols = parent::section_edit_control_items($course, $section, $onsectionpage);
// If the edit key exists, we are going to insert our controls after it.
if (array_key_exists("edit", $parentcontrols)) {
$merged = array();
// We can't use splice because we are using associative arrays.
// Step through the array and merge the arrays.
foreach ($parentcontrols as $key => $action) {
$merged[$key] = $action;
if ($key == "edit") {
// If we have come to the edit key, merge these controls here.
$merged = array_merge($merged, $controls);
}
}
return $merged;
} else {
return array_merge($controls, $parentcontrols);
}
}
/**
* Generate a summary of a section for display on the 'course index page'.
*
* @param stdClass $section The course_section entry from DB.
* @param stdClass $course The course entry from DB.
* @param array $mods (argument not used).
* @return string HTML to output.
*/
protected function section_summary($section, $course, $mods) {
$classattr = 'section main section-summary clearfix';
$linkclasses = '';
// If section is hidden then display grey section link.
if (!$section->visible) {
$classattr .= ' hidden';
$linkclasses .= ' dimmed_text';
} else if ($this->courseformat->is_section_current($section)) {
$classattr .= ' current';
}
$o = '';
$title = $this->courseformat->get_topcoll_section_name($course, $section, false);
$liattributes = array(
'id' => 'section-' . $section->section,
'class' => $classattr,
'role' => 'region',
'aria-label' => $title
);
if (($this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$liattributes['style'] = 'width: ' . $this->tccolumnwidth . '%;';
}
$o .= html_writer::start_tag('li', $liattributes);
$o .= html_writer::tag('div', '', array('class' => 'left side'));
$o .= html_writer::tag('div', '', array('class' => 'right side'));
$o .= html_writer::start_tag('div', array('class' => 'content'));
if ($section->uservisible) {
$title = html_writer::tag('a', $title,
array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
}
$o .= $this->output->heading($title, 3, 'section-title');
$o .= html_writer::start_tag('div', array('class' => 'summarytext'));
$o .= $this->format_summary_text($section);
$o .= html_writer::end_tag('div');
$o .= $this->section_activity_summary($section, $course, null);
$o .= $this->section_availability($section);
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
return $o;
}
/**
* Generate the display of the header part of a section before
* course modules are included.
*
* @param stdClass $section The course_section entry from DB.
* @param stdClass $course The course entry from DB.
* @param bool $onsectionpage true if being printed on a section page.
* @param int $sectionreturn The section to return to after an action.
* @return string HTML to output.
*/
protected function section_header($section, $course, $onsectionpage, $sectionreturn = null) {
$o = '';
$sectionstyle = '';
$rightcurrent = '';
$context = context_course::instance($course->id);
if ($section->section != 0) {
// Only in the non-general sections.
if (!$section->visible) {
$sectionstyle = ' hidden';
}
if ($section->section == $this->currentsection) {
$sectionstyle = ' current';
$rightcurrent = ' left';
}
}
if ((!$this->formatresponsive) && ($section->section != 0) &&
($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$sectionstyle .= ' ' . $this->get_column_class($this->tcsettings['layoutcolumns']);
}
$liattributes = array(
'id' => 'section-' . $section->section,
'class' => 'section main clearfix' . $sectionstyle,
'role' => 'region',
'aria-label' => $this->courseformat->get_topcoll_section_name($course, $section, false)
);
if (($this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$liattributes['style'] = 'width: ' . $this->tccolumnwidth . '%;';
}
$o .= html_writer::start_tag('li', $liattributes);
if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) {
$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$rightcontent = '';
if (($section->section != 0) && $this->userisediting && has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/course/editsection.php', array('id' => $section->id, 'sr' => $sectionreturn));
$rightcontent .= html_writer::link($url,
$this->output->pix_icon('t/edit', get_string('edit')),
array('title' => get_string('editsection', 'format_topcoll'), 'class' => 'tceditsection'));
}
$rightcontent .= $this->section_right_content($section, $course, $onsectionpage);
if ($this->rtl) {
// Swap content.
$o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
$o .= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
} else {
$o .= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
$o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
}
}
$o .= html_writer::start_tag('div', array('class' => 'content'));
if (($onsectionpage == false) && ($section->section != 0)) {
$o .= html_writer::start_tag('div',
array('class' => 'sectionhead toggle toggle-'.$this->tcsettings['toggleiconset'],
'id' => 'toggle-'.$section->section)
);
if ((!($section->toggle === null)) && ($section->toggle == true)) {
$toggleclass = 'toggle_open';
$ariapressed = 'true';
$sectionclass = ' sectionopen';
} else {
$toggleclass = 'toggle_closed';
$ariapressed = 'false';
$sectionclass = '';
}
$toggleclass .= ' the_toggle ' . $this->tctoggleiconsize;
$o .= html_writer::start_tag('span',
array('class' => $toggleclass, 'role' => 'button', 'aria-pressed' => $ariapressed)
);
if (empty($this->tcsettings)) {
$this->tcsettings = $this->courseformat->get_settings();
}
if ($this->userisediting) {
$title = $this->section_title($section, $course);
} else {
$title = $this->courseformat->get_topcoll_section_name($course, $section, true);
}
if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) {
$o .= $this->output->heading($title, 3, 'sectionname');
} else {
$o .= html_writer::tag('h3', $title); // Moodle H3's look bad on mobile / tablet with CT so use plain.
}
$o .= $this->section_availability($section);
$o .= html_writer::end_tag('span');
$o .= html_writer::end_tag('div');
if ($this->tcsettings['showsectionsummary'] == 2) {
$o .= $this->section_summary_container($section);
}
$o .= html_writer::start_tag('div',
array('class' => 'sectionbody toggledsection' . $sectionclass,
'id' => 'toggledsection-' . $section->section)
);
if ($this->userisediting) {
// CONTRIB-7434.
$o .= html_writer::tag('span',
$this->courseformat->get_topcoll_section_name($course, $section, false),
array('class' => 'hidden', 'aria-hidden' => 'true'));
}
if ($this->userisediting && has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/course/editsection.php', array('id' => $section->id, 'sr' => $sectionreturn));
$o .= html_writer::link($url,
$this->output->pix_icon('t/edit', get_string('edit')),
array('title' => get_string('editsection', 'format_topcoll'))
);
}
if ($this->tcsettings['showsectionsummary'] == 1) {
$o .= $this->section_summary_container($section);
}
} else {
// When on a section page, we only display the general section title, if title is not the default one.
$hasnamesecpg = ($section->section == 0 && (string) $section->name !== '');
if ($hasnamesecpg) {
$o .= $this->output->heading($this->section_title($section, $course), 3, 'section-title');
}
$o .= $this->section_availability($section);
$o .= html_writer::start_tag('div', array('class' => 'summary'));
$o .= $this->format_summary_text($section);
if ($this->userisediting && has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/course/editsection.php', array('id' => $section->id, 'sr' => $sectionreturn));
$o .= html_writer::link($url,
$this->output->pix_icon('t/edit', get_string('edit')),
array('title' => get_string('editsection', 'format_topcoll'))
);
}
$o .= html_writer::end_tag('div');
}
return $o;
}
protected function section_summary_container($section) {
$summarytext = $this->format_summary_text($section);
if ($summarytext) {
$classextra = ($this->tcsettings['showsectionsummary'] == 1) ? '' : ' summaryalwaysshown';
$o = html_writer::start_tag('div', array('class' => 'summary' . $classextra));
$o .= $this->format_summary_text($section);
$o .= html_writer::end_tag('div');
} else {
$o = '';
}
return $o;
}
/**
* Generate the display of the footer part of a section.
*
* @return string HTML to output.
*/
protected function section_footer() {
$o = html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
return $o;
}
/**
* Generate the header html of a stealth section.
*
* @param int $sectionno The section number in the coruse which is being dsiplayed.
* @return string HTML to output.
*/
protected function stealth_section_header($sectionno) {
$o = '';
$sectionstyle = '';
$course = $this->courseformat->get_course();
// Horizontal column layout.
if ((!$this->formatresponsive) && ($sectionno != 0) && ($this->tcsettings['layoutcolumnorientation'] == 2)) {
$sectionstyle .= ' ' . $this->get_column_class($this->tcsettings['layoutcolumns']);
}
$liattributes = array(
'id' => 'section-' . $sectionno,
'class' => 'section main clearfix orphaned hidden' . $sectionstyle,
'role' => 'region',
'aria-label' => $this->courseformat->get_topcoll_section_name($course, $sectionno, false)
);
if (($this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$liattributes['style'] = 'width: ' . $this->tccolumnwidth . '%;';
}
$o .= html_writer::start_tag('li', $liattributes);
$o .= html_writer::tag('div', '', array('class' => 'left side'));
$section = $this->courseformat->get_section($sectionno);
$rightcontent = $this->section_right_content($section, $course, false);
$o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
$o .= html_writer::start_tag('div', array('class' => 'content'));
$o .= $this->output->heading(get_string('orphanedactivitiesinsectionno', '', $sectionno), 3, 'sectionname');
return $o;
}
/**
* Generate the html for a hidden section.
*
* @param stdClass $section The section in the course which is being displayed.
* @param int|stdClass $courseorid The course to get the section name for (object or just course id).
* @return string HTML to output.
*/
protected function section_hidden($section, $courseorid = null) {
$o = '';
$course = $this->courseformat->get_course();
$sectionstyle = 'section main clearfix hidden';
if ((!$this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$sectionstyle .= ' ' . $this->get_column_class($this->tcsettings['layoutcolumns']);
}
$liattributes = array(
'id' => 'section-' . $section->section,
'class' => $sectionstyle,
'role' => 'region',
'aria-label' => $this->courseformat->get_topcoll_section_name($course, $section, false)
);
if (($this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 2)) { // Horizontal column layout.
$liattributes['style'] = 'width: ' . $this->tccolumnwidth . '%;';
}
$o .= html_writer::start_tag('li', $liattributes);
if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) {
$leftcontent = $this->section_left_content($section, $course, false);
$rightcontent = $this->section_right_content($section, $course, false);
if ($this->rtl) {
// Swap content.
$o .= html_writer::tag('div', $leftcontent, array('class' => 'right side'));
$o .= html_writer::tag('div', $rightcontent, array('class' => 'left side'));
} else {
$o .= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
$o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
}
}
$o .= html_writer::start_tag('div', array('class' => 'content sectionhidden'));
$title = get_string('notavailable');
if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) {
$o .= $this->output->heading($title, 3, 'section-title');
} else {
$o .= html_writer::tag('h3', $title); // Moodle H3's look bad on mobile / tablet with CT so use plain.
}
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
return $o;
}
/**
* Output the html for a single section page .
*
* @param stdClass $course The course entry from DB
* @param array $sections (argument not used)
* @param array $mods (argument not used)
* @param array $modnames (argument not used)
* @param array $modnamesused (argument not used)
* @param int $displaysection The section number in the course which is being displayed
*/
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$course = $this->courseformat->get_course();
// Can we view the section in question?
if (!($sectioninfo = $modinfo->get_section_info($displaysection)) || !$sectioninfo->uservisible) {
/* This section doesn't exist or is not available for the user.
We actually already check this in course/view.php but just in case exit from this function as well. */
print_error('unknowncoursesection', 'error', course_get_url($course),
format_string($course->fullname));
}
// Copy activity clipboard.
echo $this->course_activity_clipboard($course, $displaysection);
$thissection = $modinfo->get_section_info(0);
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection);
echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection, array('sr' => $displaysection));
echo $this->courserenderer->course_section_add_cm_control($course, 0, $displaysection);
echo $this->section_footer();
echo $this->end_section_list();
}
// Start single-section div.
echo html_writer::start_tag('div', array('class' => 'single-section'));
// The requested section page.
$thissection = $modinfo->get_section_info($displaysection);
// Title with section navigation links.
$sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection);
$sectiontitle = '';
$sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation navigationtitle'));
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
// Title attributes.
$classes = 'sectionname';
if (!$thissection->visible) {
$classes .= ' dimmed_text';
}
$sectionname = html_writer::tag('span', $this->section_title_without_link($thissection, $course));
$sectiontitle .= $this->output->heading($sectionname, 3, $classes);
$sectiontitle .= html_writer::end_tag('div');
echo $sectiontitle;
// Now the list of sections.
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection);
// Show completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection, array('sr' => $displaysection));
echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
echo $this->section_footer();
echo $this->end_section_list();
// Display section bottom navigation.
$sectionbottomnav = '';
$sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
$sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
$sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
$sectionbottomnav .= html_writer::tag('div', $this->section_nav_selection($course, $sections, $displaysection),
array('class' => 'mdl-align'));
$sectionbottomnav .= html_writer::end_tag('div');
echo $sectionbottomnav;
// Close single-section div.
echo html_writer::end_tag('div');
}
/**
* Output the html for a multiple section page
*
* @param stdClass $course The course entry from DB
* @param array $sections (argument not used)
* @param array $mods (argument not used)
* @param array $modnames (argument not used)
* @param array $modnamesused (argument not used)
*/
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
$modinfo = get_fast_modinfo($course);
$course = $this->courseformat->get_course();
if (empty($this->tcsettings)) {
$this->tcsettings = $this->courseformat->get_settings();
}
$context = context_course::instance($course->id);
// Title with completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
echo $this->output->heading($this->page_title(), 2, 'accesshide');
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, 0);
// Now the list of sections..
if ($this->formatresponsive) {
$this->tccolumnwidth = 100; // Reset to default.
}
echo $this->start_section_list();
$sections = $modinfo->get_section_info_all();
// General section if non-empty.
$thissection = $sections[0];
unset($sections[0]);
if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) {
echo $this->section_header($thissection, $course, false, 0);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
echo $this->section_footer();
}
$shownonetoggle = false;
$coursenumsections = $this->courseformat->get_last_section_number();
if ($coursenumsections > 0) {
$sectiondisplayarray = array();
if ($coursenumsections > 1) {
if (($this->userisediting) || ($this->tcsettings['onesection'] == 1)) {
// Collapsed Topics all toggles.
echo $this->toggle_all();
}
if ($this->tcsettings['displayinstructions'] == 2) {
// Collapsed Topics instructions.
echo $this->display_instructions();
}
}
$currentsectionfirst = false;
if (($this->tcsettings['layoutstructure'] == 4) && (!$this->userisediting)) {
$currentsectionfirst = true;
}
if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
$section = 1;
} else {
$timenow = time();
$weekofseconds = 604800;
$course->enddate = $course->startdate + ($weekofseconds * $coursenumsections);
$section = $coursenumsections;
$weekdate = $course->enddate; // This should be 0:00 Monday of that week.
$weekdate -= 7200; // Subtract two hours to avoid possible DST problems.
}
$numsections = $coursenumsections; // Because we want to manipulate this for column breakpoints.
if (($this->tcsettings['layoutstructure'] == 3) && ($this->userisediting == false)) {
$loopsection = 1;
$numsections = 0;
while ($loopsection <= $coursenumsections) {
$nextweekdate = $weekdate - ($weekofseconds);
if ((($thissection->uservisible ||
($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) &&
($nextweekdate <= $timenow)) == true) {
$numsections++; // Section not shown so do not count in columns calculation.
}
$weekdate = $nextweekdate;
$section--;
$loopsection++;
}
// Reset.
$section = $coursenumsections;
$weekdate = $course->enddate; // This should be 0:00 Monday of that week.
$weekdate -= 7200; // Subtract two hours to avoid possible DST problems.
}
if ($numsections < $this->tcsettings['layoutcolumns']) {
$this->tcsettings['layoutcolumns'] = $numsections; // Help to ensure a reasonable display.
}
if (($this->tcsettings['layoutcolumns'] > 1) && ($this->mobiletheme === false)) {
if ($this->tcsettings['layoutcolumns'] > 4) {
// Default in config.php (and reset in database) or database has been changed incorrectly.
$this->tcsettings['layoutcolumns'] = 4;
// Update....
$this->courseformat->update_topcoll_columns_setting($this->tcsettings['layoutcolumns']);
}
if (($this->tablettheme === true) && ($this->tcsettings['layoutcolumns'] > 2)) {
// Use a maximum of 2 for tablets.
$this->tcsettings['layoutcolumns'] = 2;
}
if ($this->formatresponsive) {
$this->tccolumnwidth = 100 / $this->tcsettings['layoutcolumns'];
if ($this->tcsettings['layoutcolumnorientation'] == 2) { // Horizontal column layout.
$this->tccolumnwidth -= 0.5;
$this->tccolumnpadding = 0; // In 'px'.
} else {
$this->tccolumnwidth -= 0.2;
$this->tccolumnpadding = 0; // In 'px'.
}
}
} else if ($this->tcsettings['layoutcolumns'] < 1) {
// Distributed default in plugin settings (and reset in database) or database has been changed incorrectly.
$this->tcsettings['layoutcolumns'] = 1;
// Update....
$this->courseformat->update_topcoll_columns_setting($this->tcsettings['layoutcolumns']);
}
echo $this->end_section_list();
if ((!$this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 1)) { // Vertical columns.
echo html_writer::start_tag('div', array('class' => $this->get_row_class()));
}
echo $this->start_toggle_section_list();
$loopsection = 1;
$breaking = false; // Once the first section is shown we can decide if we break on another column.
while ($loopsection <= $coursenumsections) {
if (($this->tcsettings['layoutstructure'] == 3) && ($this->userisediting == false)) {
$nextweekdate = $weekdate - ($weekofseconds);
}
$thissection = $modinfo->get_section_info($section);
/* Show the section if the user is permitted to access it, OR if it's not available
but there is some available info text which explains the reason & should display. */
if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available && !empty($thissection->availableinfo));
} else {
$showsection = ($thissection->uservisible ||
($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) &&
($nextweekdate <= $timenow);
}
if (($currentsectionfirst == true) && ($showsection == true)) {
// Show the section if we were meant to and it is the current section:....
$showsection = ($course->marker == $section);
} else if (($this->tcsettings['layoutstructure'] == 4) &&
($course->marker == $section) && (!$this->userisediting)) {
$showsection = false; // Do not reshow current section.
}
if (!$showsection) {
// Hidden section message is overridden by 'unavailable' control.
$testhidden = false;
if ($this->tcsettings['layoutstructure'] != 4) {
if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
$testhidden = true;
} else if ($nextweekdate <= $timenow) {
$testhidden = true;
}
} else {
if (($currentsectionfirst == true) && ($course->marker == $section)) {
$testhidden = true;
} else if (($currentsectionfirst == false) && ($course->marker != $section)) {
$testhidden = true;
}
}
if ($testhidden) {
if (!$course->hiddensections && $thissection->available) {
$thissection->ishidden = true;
$sectiondisplayarray[] = $thissection;
}
}
} else {
if ($this->isoldtogglepreference == true) {
$togglestate = substr($this->togglelib->get_toggles(), $section, 1);
if ($togglestate == '1') {
$thissection->toggle = true;
} else {
$thissection->toggle = false;
}
} else {
$thissection->toggle = $this->togglelib->get_toggle_state($thissection->section);
}
if ($this->courseformat->is_section_current($thissection)) {
$this->currentsection = $thissection->section;
$thissection->toggle = true; // Open current section regardless of toggle state.
$this->togglelib->set_toggle_state($thissection->section, true);
}
$thissection->isshown = true;
$sectiondisplayarray[] = $thissection;
}
if (($this->tcsettings['layoutstructure'] != 3) || ($this->userisediting)) {
$section++;
} else {
$section--;
if (($this->tcsettings['layoutstructure'] == 3) && ($this->userisediting == false)) {
$weekdate = $nextweekdate;
}
}
$loopsection++;
if (($currentsectionfirst == true) && ($loopsection > $coursenumsections)) {
// Now show the rest.
$currentsectionfirst = false;
$loopsection = 1;
$section = 1;
}
if ($section > $coursenumsections) {
// Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
break;
}
}
$canbreak = ($this->tcsettings['layoutcolumns'] > 1);
$columncount = 1;
$breakpoint = 0;
$shownsectioncount = 0;
if ((!$this->userisediting) && ($this->tcsettings['onesection'] == 2) && (!empty($this->currentsection))) {
$shownonetoggle = $this->currentsection; // One toggle open only, so as we have a current section it will be it.
}
foreach ($sectiondisplayarray as $thissection) {
$shownsectioncount++;
if (!empty($thissection->ishidden)) {
echo $this->section_hidden($thissection);
} else if (!empty($thissection->issummary)) {
echo $this->section_summary($thissection, $course, null);
} else if (!empty($thissection->isshown)) {
if ((!$this->userisediting) && ($this->tcsettings['onesection'] == 2)) {
if ($thissection->toggle) {
if (!empty($shownonetoggle)) {
// Make sure the current section is not closed if set above.
if ($shownonetoggle != $thissection->section) {
// There is already a toggle open so others need to be closed.
$thissection->toggle = false;
$this->togglelib->set_toggle_state($thissection->section, false);
}
} else {
// No open toggle, so as this is the first, it can be the one.
$shownonetoggle = $thissection->section;
}
}
}
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
}
echo html_writer::end_tag('div');
echo $this->section_footer();