-
Notifications
You must be signed in to change notification settings - Fork 60
/
lib.php
2028 lines (1897 loc) · 88.5 KB
/
lib.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.md' file.
*
* @package format_topcoll
* @copyright © 2012-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - {@link https://moodle.org/user/profile.php?id=442195}
* @link https://docs.moodle.org/en/Collapsed_Topics_course_format
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/format/lib.php'); // For format_base.
/**
* Format class.
*/
class format_topcoll extends core_courseformat\base {
/** @var int $coursedisplay Used to determine the type of view URL to generate - parameter or anchor */
private $coursedisplay = COURSE_DISPLAY_SINGLEPAGE;
/** @var array $settings */
private $settings;
/**
* Creates a new instance of class
*
* Please use {@link course_get_format($courseorid)} to get an instance of the format class
*
* @param string $format
* @param int $courseid
* @return format_topcoll
*/
protected function __construct($format, $courseid) {
if ($courseid === 0) {
global $COURSE;
$courseid = $COURSE->id; // Save lots of global $COURSE as we will never be the site course.
}
parent::__construct($format, $courseid);
$section = optional_param('section', 0, PARAM_INT);
$duplicatesection = optional_param('duplicatesection', 0, PARAM_INT);
if ($section && !$duplicatesection) {
$this->coursedisplay = COURSE_DISPLAY_MULTIPAGE;
}
}
/**
* Get the course display value for the current course.
*
* @return int The current value (COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE).
*/
public function get_course_display(): int {
return $this->coursedisplay;
}
/**
* Returns the format's settings and gets them if they do not exist.
* @return array The settings as an array.
*/
public function get_settings() {
if (empty($this->settings) == true) {
$this->settings = $this->get_format_options();
foreach ($this->settings as $settingname => $settingvalue) {
if (isset($settingvalue)) {
$settingvtype = gettype($settingvalue);
if (
(($settingvtype == 'string') && ($settingvalue === '-')) ||
(($settingvtype == 'integer') && ($settingvalue === 0))
) {
// Default value indicator is a hyphen or a number equal to 0.
$this->settings[$settingname] = get_config('format_topcoll', 'default' . $settingname);
}
}
}
}
return $this->settings;
}
/**
* Indicates this format uses sections.
*
* @return bool Returns true
*/
public function uses_sections() {
return true;
}
/**
* Indicates this format uses course index.
*
* @return bool Returns true
*/
public function uses_course_index() {
return true;
}
/**
* Indicates this format uses indentation.
*
* @return bool Returns true
*/
public function uses_indentation(): bool {
return true;
}
/**
* Indicates whether the course format supports the creation of a news forum.
*
* @return bool
*/
public function supports_news() {
return true;
}
/**
* Returns the information about the ajax support. Topcoll uses ajax.
*
* @return stdClass
*/
public function supports_ajax() {
$ajaxsupport = new stdClass();
$ajaxsupport->capable = true;
return $ajaxsupport;
}
/**
* This format is compatible with the React updates.
*/
public function supports_components() {
return true; // I.e. Allows section drag and drop to work! Off until I can work out how to make it work!
}
/**
* Gets the name for the provided section.
*
* @param int|stdClass $section Section object from database or just field section.section
* @return string The section name.
*/
public function get_section_name($section) {
$course = $this->get_course();
// Don't add additional text as called in creating the navigation.
return $this->get_topcoll_section_name($course, $section, false);
}
/**
* Returns the default section name for the format.
*
* @param stdClass $section Section object from database or just field course_sections section
* @return string The default value for the section name.
*/
public function get_default_section_name($section) {
/* Follow the same logic so that this method is supported. The MDL-51610 enchancement refactored things,
but that is not appropriate for us. */
return $this->get_section_name($section);
}
/**
* Gets the name for the provided course, section and state if need to add addional text.
*
* @param stdClass $course The course entry from DB
* @param int|stdClass $section Section object from database or just field section.section
* @param boolean $additional State to add additional text yes = true or no = false.
* @return string The section name.
*/
public function get_topcoll_section_name($course, $section, $additional) {
$thesection = $this->get_section($section);
if (is_null($thesection)) {
$thesection = new stdClass();
$thesection->name = '';
if (is_object($section)) {
$thesection->section = $section->section;
} else {
$thesection->section = $section;
}
}
$o = '';
$tcsettings = $this->get_settings();
$tcsectionsettings = $this->get_format_options($thesection->section);
// Use supplied course as could be a different course to us due to a navigation block call.
$context = context_course::instance($course->id);
// We can't add a node without any text.
if ((string) $thesection->name !== '') {
$o .= format_string($thesection->name, true, ['context' => $context]);
if (
($thesection->section != 0) && (($tcsettings['layoutstructure'] == 2) ||
($tcsettings['layoutstructure'] == 3) || ($tcsettings['layoutstructure'] == 5))
) {
$o .= ' ';
if (empty($tcsectionsettings['donotshowdate'])) {
if ($additional == true) { // Break 'br' tags break backups!
$o .= html_writer::empty_tag('br');
}
$o .= $this->get_section_dates($section, $course, $tcsettings);
}
}
} else if ($thesection->section == 0) {
$o = get_string('section0name', 'format_topcoll');
} else {
if (($tcsettings['layoutstructure'] == 1) || ($tcsettings['layoutstructure'] == 4)) {
$o = get_string('sectionname', 'format_topcoll') . ' ' . $thesection->section;
} else {
$o .= $this->get_section_dates($section, $course, $tcsettings);
}
}
/*
* Now done here so that the drag and drop titles will be the correct strings as swapped in format.js.
* But only if we are using toggles which will be if all sections are on one page or we are editing the main page
* when in one section per page which is coded in 'renderer.php/print_multiple_section_page()' when it calls
* 'section_header()' as that gets called from 'format.php' when there is no entry for '$displaysetting' - confused?
* I was, took ages to figure.
*/
if (($additional == true) && ($thesection->section != 0)) {
switch ($tcsettings['layoutelement']) {
case 1:
case 2:
case 3:
case 4:
// The word 'Toggle'.
$o .= '<div class="cttoggle"> - ' . get_string('topcolltoggle', 'format_topcoll') . '</div>';
break;
}
}
return $o;
}
/**
* Returns if an specific section is visible to the current user.
*
* Formats can overrride this method to implement any special section logic.
*
* @param section_info $section the section modinfo
* @return bool;
*/
public function is_section_visible(section_info $section): bool {
if ($section->section > $this->get_last_section_number()) {
// Stealth section.
global $PAGE;
$context = context_course::instance($this->course->id);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
$modinfo = get_fast_modinfo($this->course);
// If the stealth section has modules then is visible.
return (!empty($modinfo->sections[$section->section]));
}
// Don't show.
return false;
}
$shown = parent::is_section_visible($section);
if (($shown) && ($section->sectionnum == 0)) {
// Show section zero if summary has content, otherwise check modules.
if (empty(strip_tags($section->summary))) {
// Don't show section zero if no modules or all modules unavailable to user.
$showmovehere = ismoving($this->course->id);
if (!$showmovehere) {
global $PAGE;
$context = context_course::instance($this->course->id);
if (!($PAGE->user_is_editing() && has_capability('moodle/course:update', $context))) {
$modshown = false;
$modinfo = get_fast_modinfo($this->course);
if (!empty($modinfo->sections[$section->section])) {
foreach ($modinfo->sections[$section->section] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if ($mod->is_visible_on_course_page()) {
// At least one is.
$modshown = true;
break;
}
}
}
$shown = $modshown;
}
}
}
}
return $shown;
}
/**
* get_section_dates.
*/
public function get_section_dates($section, $course = null, $tcsettings = null) {
if (empty($tcsettings) && empty($course)) {
return $this->format_topcoll_get_section_dates($section, $this->get_course());
}
if (empty($tcsettings)) {
$tcsettings = $this->get_settings();
}
$dateformat = get_string('strftimedateshort');
$o = '';
if ($tcsettings['layoutstructure'] == 5) {
$day = $this->format_topcoll_get_section_day($section, $course);
$weekday = userdate($day, $dateformat);
$o = $weekday;
} else {
$dates = $this->format_topcoll_get_section_dates($section, $course);
// We subtract 24 hours for display purposes.
$dates->end = ($dates->end - 86400);
$weekday = userdate($dates->start, $dateformat);
$endweekday = userdate($dates->end, $dateformat);
$o = $weekday . ' - ' . $endweekday;
}
return $o;
}
/**
* What structure collection type are we using?
*
* @return string Structure collection type.
*/
public function get_structure_collection_type() {
$tcsettings = $this->get_settings();
$o = '';
switch ($tcsettings['layoutstructure']) {
case 1:
case 4:
$o = get_string('layoutstructuretopics', 'format_topcoll');
break;
case 2:
case 3:
$o = get_string('layoutstructureweeks', 'format_topcoll');
break;
case 5:
$o = get_string('layoutstructuredays', 'format_topcoll');
break;
}
return $o;
}
/**
* Custom action after section has been moved in AJAX mode
*
* Used in course/rest.php
*
* @return array This will be passed in ajax respose
*/
public function ajax_section_move() {
global $PAGE;
$titles = [];
$current = -1; // MDL-33546.
$weekformat = false;
$tcsettings = $this->get_settings();
if (
($tcsettings['layoutstructure'] == 2) || ($tcsettings['layoutstructure'] == 3) ||
($tcsettings['layoutstructure'] == 5)
) {
$weekformat = true;
}
$course = $this->get_course();
$modinfo = get_fast_modinfo($course);
$formatrenderer = $PAGE->get_renderer('format_topcoll');
if ($formatrenderer && $sections = $modinfo->get_section_info_all()) {
foreach ($sections as $sectionnumber => $section) {
$titles[$sectionnumber] = $formatrenderer->section_title($section, null); // Course not needed.
if (($weekformat == true) && ($this->is_section_current($section))) {
$current = $sectionnumber; // Only set if a week based course to keep the current week in the same place.
}
}
}
return ['sectiontitles' => $titles, 'current' => $current, 'action' => 'move'];
}
/**
* The URL to use for the specified course (with section)
*
* Please note that course view page /course/view.php?id=COURSEID is hardcoded in many
* places in core and contributed modules. If course format wants to change the location
* of the view script, it is not enough to change just this function. Do not forget
* to add proper redirection.
*
* @param int|stdClass $section Section object from database or just field course_sections.section
* if null the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section not empty, the function returns section page; otherwise, it returns course page.
* 'sr' (int) used by course formats to specify to which section to return
* 'expanded' (bool) if true the section will be shown expanded, true by default
* @return null|moodle_url
*/
public function get_view_url($section, $options = []) {
$course = $this->get_course();
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
if (array_key_exists('sr', $options)) {
$sectionno = $options['sr'];
} else if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ((!empty($options['navigation'])) && $sectionno !== null) {
// Unlike core, navigate to section on course page.
$url->set_anchor('section-'.$sectionno);
} else if ($this->uses_sections() && $sectionno !== null) {
if ($this->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
$url->set_anchor('section-'.$sectionno);
}
}
return $url;
}
/**
* Returns the list of blocks to be automatically added for the newly created course
*
* First we check defaultdisplayblocks to see which of the four default blocks should be displayed,
* then build an array of strings that will hold the list of blocks to be displayed.
*
* @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
* each of values is an array of block names (for pre and post side columns respectively).
* Confused? See the definitions in /lib/blocklib.php.
*/
public function get_default_blocks() {
/* Assign the location side for the blocks. defaultdisplayblocksloc: 1=pre, 2=post
Then put the string list of blocks on the side location. */
$blocklist = explode(',', get_config('format_topcoll', 'defaultdisplayblocks'));
if (empty($blocklist[0])) {
return [];
}
if (get_config('format_topcoll', 'defaultdisplayblocksloc') == 2) {
$bpr = $blocklist;
$bpl = [];
} else {
$bpr = [];
$bpl = $blocklist;
}
// Return our block list on the correct side.
return [
BLOCK_POS_RIGHT => $bpr,
BLOCK_POS_LEFT => $bpl,
];
}
/**
* Definitions of the additional options that this course format uses for section
*
* See course_format::course_format_options() for return array definition.
*
* Additionally section format options may have property 'cache' set to true
* if this option needs to be cached in get_fast_modinfo(). The 'cache' property
* is recommended to be set only for fields used in course_format::get_section_name(),
* course_format::extend_course_navigation() and course_format::get_view_url()
*
* For better performance cached options are recommended to have 'cachedefault' property
* Unlike 'default', 'cachedefault' should be static and not access get_config().
*
* Regardless of value of 'cache' all options are accessed in the code as
* $sectioninfo->OPTIONNAME
* where $sectioninfo is instance of section_info, returned by
* get_fast_modinfo($course)->get_section_info($sectionnum)
* or get_fast_modinfo($course)->get_section_info_all()
*
* All format options for particular section are returned by calling:
* $this->get_format_options($section);
*
* @param bool $foreditform
* @return array
*/
public function section_format_options($foreditform = false) {
static $sectionformatoptions = false;
if ($sectionformatoptions === false) {
$sectionformatoptions = [
'donotshowdate' => [
'default' => 0,
'type' => PARAM_INT,
],
];
}
if ($foreditform && !isset($sectionformatoptions['donotshowdate']['label'])) {
$sectionformatoptionsedit = [
'donotshowdate' => [
'label' => new lang_string('donotshowdate', 'format_topcoll'),
'help' => 'donotshowdate',
'help_component' => 'format_topcoll',
'element_type' => 'checkbox',
],
];
$sectionformatoptions = array_merge_recursive($sectionformatoptions, $sectionformatoptionsedit);
}
$tcsettings = $this->get_settings();
if (
($tcsettings['layoutstructure'] == 2) || ($tcsettings['layoutstructure'] == 3) ||
($tcsettings['layoutstructure'] == 5)
) {
// Weekly layout.
return $sectionformatoptions;
} else {
return [];
}
}
/**
* Definitions of the additional options that this course format uses for course
*
* Collapsed Topics format uses the following options (until extras are migrated):
* - numsections
* - hiddensections
*
* @param bool $foreditform
* @return array of options
*/
public function course_format_options($foreditform = false) {
static $courseformatoptions = false;
$courseconfig = null;
$enabledplugins = [];
$courseid = $this->get_courseid();
if ($courseformatoptions === false) {
$courseconfig = get_config('moodlecourse');
if (\format_topcoll\activity::activitymetaenabled()) {
$engagementactivities = ['assign', 'quiz', 'choice', 'feedback', 'forum', 'lesson', 'data'];
foreach ($engagementactivities as $plugintype) {
if (get_config('format_topcoll', 'coursesectionactivityfurtherinformation' . $plugintype) == 2) {
switch ($plugintype) {
case 'assign':
array_push($enabledplugins, 'assignments');
break;
case 'quiz':
array_push($enabledplugins, 'quizzes');
break;
case 'data':
array_push($enabledplugins, 'databases');
break;
case 'choice' || 'feedback' || 'forum' || 'lesson':
array_push($enabledplugins, $plugintype . 's');
break;
default:
coding_exception(
'Try to process invalid plugin',
'Check the plugintypes that are supported by format_topcoll'
);
}
}
}
}
if ($courseid == 1) { // New course.
$defaultnumsections = $courseconfig->numsections;
} else { // Existing course that may not have 'numsections' - see get_last_section().
global $DB;
$defaultnumsections = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', [$courseid]);
}
$courseformatoptions = [
'numsections' => [
'default' => $defaultnumsections,
'type' => PARAM_INT,
],
'hiddensections' => [
'default' => $courseconfig->hiddensections ?? 0,
'type' => PARAM_INT,
],
'displayinstructions' => [
'default' => 0,
'type' => PARAM_INT,
],
'layoutelement' => [
'default' => 0,
'type' => PARAM_INT,
],
'layoutstructure' => [
'default' => 0,
'type' => PARAM_INT,
],
'layoutcolumnorientation' => [
'default' => 0,
'type' => PARAM_INT,
],
'layoutcolumns' => [
'default' => 0,
'type' => PARAM_INT,
],
'flexiblemodules' => [
'default' => 0,
'type' => PARAM_INT,
],
'toggleallenabled' => [
'default' => 0,
'type' => PARAM_INT,
],
'viewsinglesectionenabled' => [
'default' => 0,
'type' => PARAM_INT,
],
'togglealignment' => [
'default' => 0,
'type' => PARAM_INT,
],
'toggleiconposition' => [
'default' => 0,
'type' => PARAM_INT,
],
'toggleiconset' => [
'default' => '-',
'type' => PARAM_ALPHAEXT,
],
'toggleiconfontclosed' => [
'default' => '-',
'type' => PARAM_TEXT,
],
'toggleiconfontopen' => [
'default' => '-',
'type' => PARAM_TEXT,
],
'onesection' => [
'default' => 0,
'type' => PARAM_INT,
],
'toggleallhover' => [
'default' => 0,
'type' => PARAM_INT,
],
'toggleforegroundcolour' => [
'default' => '-',
'type' => PARAM_ALPHANUMEXT,
],
'toggleforegroundopacity' => [
'default' => '-',
'type' => PARAM_RAW,
],
'toggleforegroundhovercolour' => [
'default' => '-',
'type' => PARAM_ALPHANUMEXT,
],
'toggleforegroundhoveropacity' => [
'default' => '-',
'type' => PARAM_RAW,
],
'togglebackgroundcolour' => [
'default' => '-',
'type' => PARAM_ALPHANUMEXT,
],
'togglebackgroundopacity' => [
'default' => '-',
'type' => PARAM_RAW,
],
'togglebackgroundhovercolour' => [
'default' => '-',
'type' => PARAM_ALPHANUMEXT,
],
'togglebackgroundhoveropacity' => [
'default' => '-',
'type' => PARAM_RAW,
],
'showsectionsummary' => [
'default' => 0,
'type' => PARAM_INT,
],
];
/* If at least one plugin is set to 'yes' then show config with default of 'yes',
otherwise will use the value prevously stored. */
if (!empty($enabledplugins)) {
$courseformatoptions['showadditionalmoddata'] = [
'default' => 0,
'type' => PARAM_INT,
];
}
}
if ($foreditform && !isset($courseformatoptions['displayinstructions']['label'])) {
/* Note: Because 'admin_setting_configcolourpicker' in 'settings.php' needs to use a prefixing '#'
this needs to be stripped off here if it's there for the format's specific colour picker. */
$defaulttgfgcolour = get_config('format_topcoll', 'defaulttoggleforegroundcolour');
if ($defaulttgfgcolour[0] == '#') {
$defaulttgfgcolour = substr($defaulttgfgcolour, 1);
}
$defaulttgfghvrcolour = get_config('format_topcoll', 'defaulttoggleforegroundhovercolour');
if ($defaulttgfghvrcolour[0] == '#') {
$defaulttgfghvrcolour = substr($defaulttgfghvrcolour, 1);
}
$defaulttgbgcolour = get_config('format_topcoll', 'defaulttogglebackgroundcolour');
if ($defaulttgbgcolour[0] == '#') {
$defaulttgbgcolour = substr($defaulttgbgcolour, 1);
}
$defaulttgbghvrcolour = get_config('format_topcoll', 'defaulttogglebackgroundhovercolour');
if ($defaulttgbghvrcolour[0] == '#') {
$defaulttgbghvrcolour = substr($defaulttgbghvrcolour, 1);
}
$context = $this->get_context();
if (is_null($courseconfig)) {
$courseconfig = get_config('moodlecourse');
}
$sectionmenu = [];
for ($i = 0; $i <= $courseconfig->maxsections; $i++) {
$sectionmenu[$i] = "$i";
}
$displayinstructionsvalues = $this->generate_default_entry(
'displayinstructions',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit = [
'numsections' => [
'label' => new lang_string('numbersections', 'format_topcoll'),
'element_type' => 'select',
'element_attributes' => [$sectionmenu],
],
'hiddensections' => [
'label' => new lang_string('hiddensections'),
'help' => 'hiddensections',
'help_component' => 'moodle',
'element_type' => 'select',
'element_attributes' => [
[
0 => new lang_string('hiddensectionscollapsed'),
1 => new lang_string('hiddensectionsinvisible'),
],
],
],
'displayinstructions' => [
'label' => new lang_string('displayinstructions', 'format_topcoll'),
'help' => 'displayinstructions',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$displayinstructionsvalues],
],
];
if (has_capability('format/topcoll:changelayout', $context)) {
$layoutelementvalues = $this->generate_default_entry(
'layoutelement',
0,
// In insertion order and not numeric for sorting purposes.
[
// Toggle word, toggle section x and section number.
1 => new lang_string('setlayout_all', 'format_topcoll'),
// Toggle word and toggle section x.
3 => new lang_string('setlayout_toggle_word_section_x', 'format_topcoll'),
// Toggle word and section number.
2 => new lang_string('setlayout_toggle_word_section_number', 'format_topcoll'),
// Toggle section x and section number.
5 => new lang_string('setlayout_toggle_section_x_section_number', 'format_topcoll'),
// Toggle word.
4 => new lang_string('setlayout_toggle_word', 'format_topcoll'),
// Toggle section x.
8 => new lang_string('setlayout_toggle_section_x', 'format_topcoll'),
// Section number.
6 => new lang_string('setlayout_section_number', 'format_topcoll'),
// No additions.
7 => new lang_string('setlayout_no_additions', 'format_topcoll'),
]
);
$courseformatoptionsedit['layoutelement'] = [
'label' => new lang_string('setlayoutelements', 'format_topcoll'),
'help' => 'setlayoutelements',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$layoutelementvalues],
];
$layoutstructurevalues = $this->generate_default_entry(
'layoutstructure',
0,
[
// Topic.
1 => new lang_string('setlayoutstructuretopic', 'format_topcoll'),
// Week.
2 => new lang_string('setlayoutstructureweek', 'format_topcoll'),
// Current Week First.
3 => new lang_string('setlayoutstructurelatweekfirst', 'format_topcoll'),
// Current Topic First.
4 => new lang_string('setlayoutstructurecurrenttopicfirst', 'format_topcoll'),
// Day.
5 => new lang_string('setlayoutstructureday', 'format_topcoll'),
]
);
$courseformatoptionsedit['layoutstructure'] = [
'label' => new lang_string('setlayoutstructure', 'format_topcoll'),
'help' => 'setlayoutstructure',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$layoutstructurevalues],
];
$layoutcolumnorientationvalues = $this->generate_default_entry(
'layoutcolumnorientation',
0,
[
3 => new lang_string('columndynamic', 'format_topcoll'),
2 => new lang_string('columnhorizontal', 'format_topcoll'),
1 => new lang_string('columnvertical', 'format_topcoll'),
]
);
$courseformatoptionsedit['layoutcolumnorientation'] = [
'label' => new lang_string('setlayoutcolumnorientation', 'format_topcoll'),
'help' => 'setlayoutcolumnorientation',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$layoutcolumnorientationvalues],
];
$layoutcolumnsvalues = $this->generate_default_entry(
'layoutcolumns',
0,
[
1 => new lang_string('one', 'format_topcoll'),
2 => new lang_string('two', 'format_topcoll'),
3 => new lang_string('three', 'format_topcoll'),
4 => new lang_string('four', 'format_topcoll'),
]
);
$courseformatoptionsedit['layoutcolumns'] = [
'label' => new lang_string('setlayoutcolumns', 'format_topcoll'),
'help' => 'setlayoutcolumns',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$layoutcolumnsvalues],
];
$flexiblemodulesvalues = $this->generate_default_entry(
'flexiblemodules',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit['flexiblemodules'] = [
'label' => new lang_string('setflexiblemodules', 'format_topcoll'),
'help' => 'setflexiblemodules',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$flexiblemodulesvalues],
];
$toggleallenabledvalues = $this->generate_default_entry(
'toggleallenabled',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit['toggleallenabled'] = [
'label' => new lang_string('settoggleallenabled', 'format_topcoll'),
'help' => 'settoggleallenabled',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$toggleallenabledvalues],
];
$viewsinglesectionenabledvalues = $this->generate_default_entry(
'viewsinglesectionenabled',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit['viewsinglesectionenabled'] = [
'label' => new lang_string('setviewsinglesectionenabled', 'format_topcoll'),
'help' => 'setviewsinglesectionenabled',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$viewsinglesectionenabledvalues],
];
$toggleiconpositionvalues = $this->generate_default_entry(
'toggleiconposition',
0,
[
1 => new lang_string('left', 'format_topcoll'),
2 => new lang_string('right', 'format_topcoll'),
]
);
$courseformatoptionsedit['toggleiconposition'] = [
'label' => new lang_string('settoggleiconposition', 'format_topcoll'),
'help' => 'settoggleiconposition',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$toggleiconpositionvalues],
];
$onesectionvalues = $this->generate_default_entry(
'onesection',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit['onesection'] = [
'label' => new lang_string('onesection', 'format_topcoll'),
'help' => 'onesection',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$onesectionvalues],
];
$showsectionsummaryvalues = $this->generate_default_entry(
'showsectionsummary',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$courseformatoptionsedit['showsectionsummary'] = [
'label' => new lang_string('setshowsectionsummary', 'format_topcoll'),
'help' => 'setshowsectionsummary',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$showsectionsummaryvalues],
];
} else {
$courseformatoptionsedit['layoutelement'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['layoutstructure'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['layoutcolumns'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['layoutcolumnorientation'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['flexiblemodules'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['toggleallenabled'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['viewsinglesectionenabled'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['toggleiconposition'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['onesection'] = [
'label' => 0, 'element_type' => 'hidden', ];
$courseformatoptionsedit['showsectionsummary'] = [
'label' => 0, 'element_type' => 'hidden', ];
}
if ((!empty($enabledplugins)) && (has_capability('format/topcoll:changeactivitymeta', $context))) {
$showadditionalmoddatavalues = $this->generate_default_entry(
'showadditionalmoddata',
0,
[
1 => new lang_string('no'),
2 => new lang_string('yes'),
]
);
$stringenabled = implode(', ', $enabledplugins);
$portion = strrchr($stringenabled, ',');
$stringenabled = str_replace($portion, (" and" . substr($portion, 1)), $stringenabled);
$courseformatoptionsedit['showadditionalmoddata'] = [
'label' => new lang_string('showadditionalmoddata', 'format_topcoll', $stringenabled),
'help' => 'showadditionalmoddata',
'help_component' => 'format_topcoll',
'element_type' => 'select',
'element_attributes' => [$showadditionalmoddatavalues],
];
$tcsettings = $this->get_settings();
if ((!empty($tcsettings['showadditionalmoddata'])) && ($tcsettings['showadditionalmoddata'] == 2)) {
$maxstudentsinfo = \format_topcoll\activity::maxstudentsnotexceeded($courseid, true);
if ($maxstudentsinfo['maxstudents'] == 0) {
$activityinfostring = get_string(
'courseadditionalmoddatastudentsinfounlimited',
'format_topcoll',
$maxstudentsinfo['nostudents']
);
} else if (!$maxstudentsinfo['notexceeded']) {
$activityinfostring = get_string(
'courseadditionalmoddatastudentsinfolimitednoshow',
'format_topcoll',
['students' => $maxstudentsinfo['nostudents'], 'maxstudents' => $maxstudentsinfo['maxstudents']]
);
} else {
$activityinfostring = get_string(
'courseadditionalmoddatastudentsinfolimitedshow',
'format_topcoll',
['students' => $maxstudentsinfo['nostudents'], 'maxstudents' => $maxstudentsinfo['maxstudents']]