-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
1567 lines (1436 loc) · 69.5 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/>.
/**
* Renderer for outputting the Designer course format.
*
* @package format_designer
* @copyright 2021 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use format_designer\output\call_to_action;
use format_designer\output\cm_completion;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/format/renderer.php');
require_once($CFG->dirroot.'/course/format/designer/lib.php');
/**
* Basic renderer for Designer format.
*
* @copyright 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_designer_renderer extends format_section_renderer_base {
/**
* Course modinfo instance.
*
* @var course_modinfo
*/
public $modinfo;
/**
* Flow delay for each module.
*
* @var float
*/
public $flowdelay;
/**
* Constructor method, calls the parent constructor.
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
// Since format_designer_renderer::section_edit_control_items() only displays the 'Highlight' 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->page = $page;
}
/**
* Generate the starting container html for a list of sections.
*
* @param string|bool $id
* @param array $classes Additional class for section ul
* @return string HTML to output.
*/
protected function start_section_list($id=false, $classes=[]) {
$classes[] = 'designer';
$attrs = ['class' => implode(' ', $classes) ];
if ($id) {
$attrs['id'] = (is_bool($id) && $id) ? 'section-course-accordion' : $id;
}
return html_writer::start_tag('ul', $attrs);
}
/**
* 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('topicoutline');
}
/**
* Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page.
*
* @param section_info|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(course_get_format($course)->inplace_editable_render_section_name($section));
}
/**
* Generate the section title to be displayed on the section page, without a link.
*
* @param section_info|stdClass $section The course_section entry from DB
* @param int|stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title_without_link($section, $course) {
return $this->render(course_get_format($course)->inplace_editable_render_section_name($section, false));
}
/**
* Generate the edit control action menu
*
* @param array $controls The edit control items from section_edit_control_items
* @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from DB
* @return string HTML to output.
*/
protected function section_edit_control_menu($controls, $course, $section) {
/** @var format_designer $format */
$format = course_get_format($course);
$o = "";
if (!empty($controls)) {
$controllinks = [];
foreach ($controls as $value) {
$url = empty($value['url']) ? '' : $value['url'];
$icon = empty($value['icon']) ? '' : $value['icon'];
$name = empty($value['name']) ? '' : $value['name'];
$attr = empty($value['attr']) ? array() : $value['attr'];
$class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class'];
$class .= ' dropdown-item';
$attr = array_map(function($key, $value) {
return [
'name' => $key,
'value' => $value
];
}, array_keys($attr), $attr);
$controllinks[] = [
'url' => $url,
'name' => $name,
'icon' => $this->render(new pix_icon($icon, '', null, array('class' => "smallicon " . $class))),
'attributes' => $attr
];
}
$sectiontypes = [
[
'type' => 'default',
'name' => get_string('link', 'format_designer'),
'active' => empty($format->get_section_option($section->id, 'sectiontype'))
|| $format->get_section_option($section->id, 'sectiontype') == 'default',
'url' => new moodle_url('/course/view.php', ['id' => $course->id], 'section-' . $section->section)
],
[
'type' => 'list',
'name' => get_string('list', 'format_designer'),
'active' => $format->get_section_option($section->id, 'sectiontype') == 'list',
'url' => new moodle_url('/course/view.php', ['id' => $course->id], 'section-' . $section->section)
],
[
'type' => 'cards',
'name' => get_string('cards', 'format_designer'),
'active' => $format->get_section_option($section->id, 'sectiontype') == 'cards',
'url' => new moodle_url('/course/view.php', ['id' => $course->id], 'section-' . $section->section)
],
];
if (format_designer_has_pro()) {
$prosectiontypes = \local_designer\info::get_layout_menu($format, $section, $course);
$sectiontypes = array_merge($sectiontypes, $prosectiontypes);
}
$o = $this->render_from_template('format_designer/section_controls', [
'seciontypes' => $sectiontypes,
'hassectiontypes' => ($course->coursetype != DESIGNER_TYPE_FLOW),
'sectionid' => $section->id,
'sectionnumber' => $section->section,
'courseid' => $course->id,
'sectionactionmenu' => $controllinks,
'hassectionactionmenu' => !empty($controllinks)
]);
}
return $o;
}
/**
* Generate the edit control items of a section.
*
* @param int|stdClass $course The course entry from DB
* @param section_info|stdClass $section The course_section entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return array of edit control items
*/
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
if (!$this->page->user_is_editing()) {
return [];
}
$coursecontext = context_course::instance($course->id);
if ($onsectionpage) {
$url = course_get_url($course, $section->section);
} else {
$url = course_get_url($course);
}
$url->param('sesskey', sesskey());
$controls = [];
if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
if ($course->marker == $section->section) { // Show the "light globe" on/off.
$url->param('marker', 0);
$highlightoff = get_string('highlightoff');
$controls['highlight'] = [
'url' => $url,
'icon' => 'i/marked',
'name' => $highlightoff,
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'dropdown-item editing_highlight menu-action',
'data-action' => 'removemarker'
],
];
} else {
$url->param('marker', $section->section);
$highlight = get_string('highlight');
$controls['highlight'] = [
'url' => $url,
'icon' => 'i/marker',
'name' => $highlight,
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'dropdown-item editing_highlight menu-action',
'data-action' => 'setmarker'
],
];
}
}
$parentcontrols = $this->parentsection_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 = [];
// 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 the edit control items 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 edit control items
*/
public function parentsection_edit_control_items($course, $section, $onsectionpage = false) {
if (!$this->page->user_is_editing()) {
return array();
}
$sectionreturn = $onsectionpage ? $section->section : null;
$coursecontext = context_course::instance($course->id);
$numsections = course_get_format($course)->get_last_section_number();
$isstealth = $section->section > $numsections;
$baseurl = course_get_url($course, $sectionreturn);
$baseurl->param('sesskey', sesskey());
$controls = array();
if (!$isstealth && has_capability('moodle/course:update', $coursecontext)) {
if ($section->section > 0
&& get_string_manager()->string_exists('editsection', 'format_'.$course->format)) {
$streditsection = get_string('editsection', 'format_'.$course->format);
} else {
$streditsection = get_string('editsection');
}
$controls['edit'] = array(
'url' => new moodle_url('/course/editsection.php', array('id' => $section->id, 'sr' => $sectionreturn)),
'icon' => 'i/settings',
'name' => $streditsection,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item edit menu-action'));
}
if ($section->section) {
$url = clone($baseurl);
if (!$isstealth) {
if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
if ($section->visible) { // Show the hide/show eye.
$strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
$url->param('hide', $section->section);
$controls['visiblity'] = array(
'url' => $url,
'icon' => 'i/hide',
'name' => $strhidefromothers,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item editing_showhide menu-action',
'data-sectionreturn' => $sectionreturn, 'data-action' => 'hide'));
} else {
$strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
$url->param('show', $section->section);
$controls['visiblity'] = array(
'url' => $url,
'icon' => 'i/show',
'name' => $strshowfromothers,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item editing_showhide menu-action',
'data-sectionreturn' => $sectionreturn, 'data-action' => 'show'));
}
}
if (!$onsectionpage) {
if (has_capability('moodle/course:movesections', $coursecontext)) {
$url = clone($baseurl);
if ($section->section > 1) { // Add a arrow to move section up.
$url->param('section', $section->section);
$url->param('move', -1);
$strmoveup = get_string('moveup');
$controls['moveup'] = array(
'url' => $url,
'icon' => 'i/up',
'name' => $strmoveup,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item moveup menu-action'));
}
$url = clone($baseurl);
if ($section->section < $numsections) { // Add a arrow to move section down.
$url->param('section', $section->section);
$url->param('move', 1);
$strmovedown = get_string('movedown');
$controls['movedown'] = array(
'url' => $url,
'icon' => 'i/down',
'name' => $strmovedown,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item movedown menu-action'));
}
}
}
}
if (course_can_delete_section($course, $section)) {
if (get_string_manager()->string_exists('deletesection', 'format_'.$course->format)) {
$strdelete = get_string('deletesection', 'format_'.$course->format);
} else {
$strdelete = get_string('deletesection');
}
$url = new moodle_url('/course/editsection.php', array(
'id' => $section->id,
'sr' => $sectionreturn,
'delete' => 1,
'sesskey' => sesskey()));
$controls['delete'] = array(
'url' => $url,
'icon' => 'i/delete',
'name' => $strdelete,
'pixattr' => array('class' => ''),
'attr' => array('class' => 'dropdown-item editing_delete menu-action'));
}
}
return $controls;
}
/**
* 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.
*/
public 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 (course_get_format($course)->is_section_current($section)) {
$classattr .= ' current';
}
$title = get_section_name($course, $section);
$o = '';
$o .= html_writer::start_tag('li', [
'id' => 'section-'.$section->section,
'class' => $classattr,
'role' => 'region',
'aria-label' => $title,
'data-sectionid' => $section->section
]);
$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' => 'availability-section-block'));
$o .= $this->section_availability($section);
$o .= html_writer::end_tag('div');
$o .= html_writer::start_tag('div', array('class' => 'summarytext'));
if ($section->uservisible || $section->visible) {
// Show summary if section is available or has availability restriction information.
// Do not show summary if section is hidden but we still display it because of course setting
// "Hidden sections are shown in collapsed form".
$o .= $this->format_summary_text($section);
}
$o .= html_writer::end_tag('div');
$o .= $this->section_activity_summary($section, $course, null);
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
return $o;
}
/**
* Render the completion info icon to modify the content.
*
* @param \completion_info $completioninfo Completion info of the current course.
* @return html $result Completion progress info icon.
*/
public function completioninfo_icon(\completion_info $completioninfo) {
global $USER;
$result = '';
if ($completioninfo->is_enabled() && !$this->page->user_is_editing()
&& $completioninfo->is_tracked_user($USER->id) && isloggedin() && !isguestuser()) {
$result .= html_writer::tag('div', get_string('yourprogress', 'completion') .
$this->output->help_icon('completionicons', 'format_designer'), array(
'id' => 'completionprogressid', 'class' => 'completionprogress'
));
}
return $result;
}
/**
* Get course time mananagment details user current course progress and due modules course.
*
* @param stdclass $course
* @return string
*/
public function timemanagement_details(stdclass $course): string {
global $USER, $CFG, $DB;
require_once($CFG->dirroot.'/enrol/locallib.php');
$context = context_course::instance($course->id);
if (is_enrolled($context, $USER->id)) {
$enrolmanager = new course_enrolment_manager($this->page, $course);
$enrolments = $enrolmanager->get_user_enrolments($USER->id);
$enrolment = (!empty($enrolments)) ? current($enrolments) : [];
$enrolstartdate = ($enrolment->timestart) ?? '';
$enrolenddate = ($enrolment->timeend) ?? '';
} else {
$enrolstartdate = $course->startdate;
$enrolenddate = $course->enddate;
}
$data = [
'course' => $course,
'enrolmentstartdate' => ($course->enrolmentstartdate) ? $enrolstartdate : '',
'enrolmentenddate' => $course->enrolmentenddate ? $enrolenddate : '',
'coursestaffinfo' => format_designer_show_staffs_header($course),
'statuscoursestaffinfo' => !empty(format_designer_show_staffs_header($course)) ? true : false,
'slidearrow' => count(format_designer_show_staffs_header($course)) > 1 ? true : false,
'currentuser' => $USER->id,
'ismessaging' => $CFG->messaging,
];
$courseprogress = self::criteria_progress($course, $USER->id);
if ($courseprogress != null) {
$sql = "SELECT * FROM {course_completions}
WHERE course = :course AND userid = :userid AND timecompleted IS NOT NULL";
$completion = $DB->get_record_sql($sql, ['userid' => $USER->id, 'course' => $course->id]);
$data += [
'showcompletiondate' => ($course->coursecompletiondate) ?: '',
'completiondate' => (!empty($completion) ? $completion->timecompleted : ''),
'courseprogress' => ($course->activityprogress) ? $courseprogress : '',
];
}
$data['progresshelpicon'] = $this->output->help_icon('criteriaprogressinfo', 'format_designer');
// Find the course due date. only if the timemanagement installed.
if (format_designer_timemanagement_installed() && function_exists('ltool_timemanagement_cal_course_duedate')) {
$coursedatesinfo = $DB->get_record('ltool_timemanagement_course', array('course' => $course->id));
if ($course->courseduedate && $coursedatesinfo) {
$data['courseduedate'] = ltool_timemanagement_cal_course_duedate($coursedatesinfo, $enrolstartdate);
}
}
$data['due'] = $this->due_overdue_activities_count();
$html = $this->output->render_from_template('format_designer/course_time_management', $data);
return $html;
}
/**
* Get the count of due and overdue activities.
*
* @return array
*/
public function due_overdue_activities_count(): array {
global $USER, $DB;
$duecount = $overduecount = 0;
$modinfo = $this->modinfo;
$completion = new \completion_info($this->modinfo->get_course());
foreach ($modinfo->sections as $modnumbers) {
foreach ($modnumbers as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if (!empty($mod) && $DB->record_exists('course_modules', array('id' => $mod->id, 'deletioninprogress' => 0))
&& $mod->uservisible) {
$data = $completion->get_data($mod, true, $USER->id);
if ($data->completionstate != COMPLETION_COMPLETE) {
$cmcompletion = new cm_completion($mod);
$overduecount = ($cmcompletion->is_overdue()) ? $overduecount + 1 : $overduecount;
$duecount = ($cmcompletion->is_due_today()) ? $duecount + 1 : $duecount;
}
}
}
}
return ['dues' => $duecount, 'overdues' => $overduecount];
}
/**
* Get current course module progress. count of completion enable modules and count of completed modules.
*
* @param stdclass $course
* @param int $userid
* @return array Modules progress
*/
public static function criteria_progress($course, $userid) {
$completion = new \completion_info($course);
// First, let's make sure completion is enabled.
if (!$completion->is_enabled()) {
return null;
}
$result = [];
$completedcriteria = [];
$uncompletedcriteria = [];
// Get the number of modules that support completion.
$modules = $completion->get_activities();
$completionactivities = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY);
$complteioncourses = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE);
$count = count($completionactivities) + count($complteioncourses);
if (!$count) {
return null;
}
// Get the number of modules that have been completed.
$completed = 0;
if ($completionactivities) {
foreach ($completionactivities as $activity) {
$cmid = $activity->moduleinstance;
if (isset($modules[$cmid])) {
$data = $completion->get_data($modules[$cmid], true, $userid);
$completed += ($data->completionstate == COMPLETION_COMPLETE ||
$data->completionstate == COMPLETION_COMPLETE_PASS) ? 1 : 0;
$modtooltiplink = html_writer::link($modules[$cmid]->url,
get_string('stractivity', 'format_designer') . " ". $modules[$cmid]->name);
if ($data->completionstate == COMPLETION_COMPLETE ||
$data->completionstate == COMPLETION_COMPLETE_PASS) {
$completedcriteria[] = $modtooltiplink;
} else {
$uncompletedcriteria[] = $modtooltiplink;
}
}
}
}
if ($complteioncourses) {
foreach ($complteioncourses as $coursecriteria) {
$courseid = $coursecriteria->courseinstance;
$course = get_course($courseid);
$completion = new \completion_info($course);
$coursetooltiplink = html_writer::link(new moodle_url('/course/view.php',
['id' => $course->id]), $course->fullname);
if ($completion->is_course_complete($userid)) {
$completed += 1;
$completedcriteria[] = $coursetooltiplink;
} else {
$uncompletedcriteria[] = $coursetooltiplink;
}
}
}
$percent = ($completed / $count) * 100;
$completioncriteriahtml = '';
$uncompletioncriteriahtml = '';
if (!empty($completedcriteria)) {
$completioncriteriahtml = html_writer::start_div('completion-criteria-toolblock designer-criteria-tooltip');
$completioncriteriahtml .= html_writer::start_div('head-block');
$completioncriteriahtml .= get_string('struppercompleted', 'format_designer');
$completioncriteriahtml .= html_writer::end_div();
$completioncriteriahtml .= html_writer::start_div('info-block');
$completioncriteriahtml .= implode("<br>", $completedcriteria);
$completioncriteriahtml .= html_writer::end_div();
$completioncriteriahtml .= html_writer::end_div();
}
if (!empty($uncompletedcriteria)) {
$uncompletioncriteriahtml = html_writer::start_div('uncompletion-criteria-toolblock designer-criteria-tooltip');
$uncompletioncriteriahtml .= html_writer::start_div('head-block');
$uncompletioncriteriahtml .= get_string('strtodo', 'format_designer');
$uncompletioncriteriahtml .= html_writer::end_div();
$uncompletioncriteriahtml .= html_writer::start_div('info-block');
$uncompletioncriteriahtml .= implode("<br>", $uncompletedcriteria);
$uncompletioncriteriahtml .= html_writer::end_div();
$uncompletioncriteriahtml .= html_writer::end_div();
}
return [
'count' => $count,
'completed' => $completed,
'percent' => $percent,
'remain' => 100 - $percent,
'completioncriteriahtml' => $completioncriteriahtml,
'uncompletioncriteriahtml' => $uncompletioncriteriahtml
];
}
/**
* Course type classes.
*
* @param stdclass $course
* @return void
*/
public function course_type_class($course) {
if (!isset($course->coursetype)) {
return '';
}
if ($course->coursetype == DESIGNER_TYPE_COLLAPSIBLE) {
$class = 'course-type-collapsible';
} else if ($course->coursetype == DESIGNER_TYPE_KANBAN) {
$class = 'course-type-kanbanboard kanban-board';
} else if ($course->coursetype == DESIGNER_TYPE_FLOW) {
$class = (!$this->page->user_is_editing()) ? 'course-type-flow' : '';
} else {
$class = "course-type-default";
}
$id = isset($course->accordion) && $course->accordion && !$this->page->user_is_editing() ? 'section-course-accordion' : '';
return [$id, [$class] ];
}
/**
* Section classes based on different courses.
*
* @param stdclass $course
* @param stdclass $section
* @param cminfo $modinfo
* @return array list of classes.
*/
public function course_type_sectionclasses($course, $section, $modinfo) {
$attrs = $contentattrs = [];
$contentclass = $actvitiyclass = '';
$class = "";
if ($course->coursetype == DESIGNER_TYPE_COLLAPSIBLE) {
$attrs[] = 'data-toggle="collapse"';
$contentattrs[] = 'data-parent="#section-course-accordion"';
} else if ($course->coursetype == DESIGNER_TYPE_KANBAN) {
$class = "";
} else if ($course->coursetype == DESIGNER_TYPE_FLOW) {
$modnumber = isset($modinfo->sections[$section->section]) ? $modinfo->sections[$section->section] : 0;
$class = ($modnumber > 0 ) ? 'has-modules flow-stack' : 'flow-none';
$contentclass = 'flow-open';
if (count($modinfo->sections) <= 1 && $section->section == '0') {
$class .= ' flow-head-hide';
}
}
return [
'classes' => $class,
'content' => [
'classes' => $contentclass,
],
'activity' => [
'classes' => $actvitiyclass,
]
];
}
/**
* 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);
$this->modinfo = $modinfo;
$course = course_get_format($course)->get_course();
$context = context_course::instance($course->id);
// Display the time management plugin widget.
echo $this->timemanagement_details($course);
// Title with completion help icon.
$completioninfo = new completion_info($course);
echo $this->completioninfo_icon($completioninfo);
echo $this->output->heading($this->page_title(), 2, 'accesshide');
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, 0);
list($startid, $startclass) = $this->course_type_class($course);
$startclass[] = ($course->coursedisplay && !$this->page->user_is_editing()) ? 'row' : '';
echo $this->start_section_list($startid, $startclass);
$numsections = course_get_format($course)->get_last_section_number();
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section > $numsections) {
// Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
continue;
}
// 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,
// OR it is hidden but the course has a setting to display hidden sections as unavilable.
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available && !empty($thissection->availableinfo)) ||
(!$thissection->visible && !$course->hiddensections);
if (!$showsection) {
continue;
}
if (!$this->page->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->render_section($thissection, $course, false, true);
} else {
echo $this->render_section($thissection, $course, false);
}
if ($course->coursetype == DESIGNER_TYPE_KANBAN && $section == 0) {
echo html_writer::start_div('kanban-board-activities');
$kanbanactivities = true;
}
}
// Close the kanban board items.
if (isset($kanbanactivities)) {
echo html_writer::end_div();
}
if ($this->page->user_is_editing() && has_capability('moodle/course:update', $context)) {
// Print stealth sections if present.
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section <= $numsections || empty($modinfo->sections[$section])) {
// This is not stealth section or it is empty.
continue;
}
echo $this->stealth_section_header($section);
echo $this->render_section($thissection, $course, false);
echo $this->stealth_section_footer();
}
echo $this->end_section_list();
echo $this->change_number_sections($course, 0);
} else {
echo $this->end_section_list();
}
format_designer_editsetting_style($this->page);
}
/**
* 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) {
$modinfo = get_fast_modinfo($course);
$this->modinfo = $modinfo;
$course = course_get_format($course)->get_course();
$context = context_course::instance($course->id);
// 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.
throw new moodle_exception('unknowncoursesection', 'error', course_get_url($course),
format_string($course->fullname));
}
// Display the time management plugin widget.
echo $this->timemanagement_details($course);
// Copy activity clipboard..
list($startid, $startclass) = $this->course_type_class($course);
// Now the list of sections..
$sectioncollapse = isset($course->coursetype) && $course->coursetype == DESIGNER_TYPE_COLLAPSIBLE ? true : false;
echo $this->start_section_list($startid, $startclass);
$thissection = $modinfo->get_section_info(0);
if ($thissection->summary || !empty($modinfo->sections[0]) || $this->page->user_is_editing()) {
$this->render_section($thissection, $course, true);
}
if ($this->page->user_is_editing() && has_capability('moodle/course:update', $context)) {
echo $this->change_number_sections($course, 0);
}
// 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';
}
echo $sectiontitle;
echo $this->render_section($thissection, $course, true);
// Close single-section div.
echo html_writer::end_tag('div');
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;
format_designer_editsetting_style($this->page);
}
/**
* If section is not visible, display the message about that ('Not available
* until...', that sort of thing). Otherwise, returns blank.
*
* For users with the ability to view hidden sections, it shows the
* information even though you can view the section and also may include
* slightly fuller information (so that teachers can tell when sections
* are going to be unavailable etc). This logic is the same as for
* activities.
*
* @param section_info $section The course_section entry from DB
* @param bool $canviewhidden True if user can view hidden sections
* @return string HTML to output
*/
public function section_availability_message($section, $canviewhidden) {
global $CFG;
$o = '';
if (!$section->visible) {
if ($canviewhidden) {
$o .= $this->courserenderer->availability_info(get_string('hiddenfromstudents'), 'ishidden');
} else {
// We are here because of the setting "Hidden sections are shown in collapsed form".
// Student can not see the section contents but can see its name.
$o .= $this->courserenderer->availability_info(get_string('notavailable'), 'ishidden');
}
} else if (!$section->uservisible || $canviewhidden && !empty($CFG->enableavailability)) {
if (!$section->uservisible && $section->availableinfo) {
// Note: We only get to this function if availableinfo is non-empty,
// so there is definitely something to print.
$formattedinfo = \core_availability\info::format_info(
$section->availableinfo, $section->course);
$o .= $this->courserenderer->availability_info($formattedinfo, 'isrestricted');
$o .= html_writer::start_tag('div', array('class' => 'section-restricted-action'));
$o .= html_writer::tag('i', '', array('class' => 'fa fa-lock'));
$o .= html_writer::end_tag('div');
} else {
// Check if there is an availability restriction.
$ci = new \core_availability\info_section($section);
$fullinfo = $ci->get_full_information();
if ($fullinfo) {
$formattedinfo = \core_availability\info::format_info(
$fullinfo, $section->course);
$o .= $this->courserenderer->availability_info($formattedinfo, 'isrestricted isfullinfo');
$o .= html_writer::start_tag('div', array('class' => 'section-restricted-action'));
$o .= html_writer::tag('i', '', array('class' => 'fa fa-lock'));
$o .= html_writer::end_tag('div');
}
}
}
return $o;
}
/**
* Genreate the class for the sections to deifine the width of sections.
* It contains bootstrap grid classes, for desktop, laptop and mobile.
*
* @param stdclass $section Record object.
* @return string classes list.
*/
protected function generate_section_widthclass($section) {
if (!isset($section->tabletwidth)) {
return '';
}
$tablet = isset($section->tabletwidth) ? $section->tabletwidth : '';
$mobile = isset($section->mobilewidth) ? $section->mobilewidth : '';
$desktop = isset($section->desktopwidth) ? $section->desktopwidth : '';
$widthclasses = [0 => 12, 1 => 6, 2 => 4, 3 => 3, 4 => 2 ];
$classes = [];
foreach (['desktop' => 'md', 'tablet' => 'sm', 'mobile' => ''] as $device => $size) {
$class = 'col-';
$class .= ($size) ? $size.'-' : '';
$class .= (isset($widthclasses[$$device])) ? $widthclasses[$$device] : 12;
$classes[] = $class;
}
return ' '.implode(' ', $classes);
}
/**
* Render the section info.
*
* @param \section_info $section
* @param stdClass $course
* @param bool $onsectionpage
* @param bool $sectionheader
* @param int $sectionreturn
* @param bool $sectioncontent
* @return void|string
*/
public function render_section(section_info $section, stdClass $course, $onsectionpage,
$sectionheader = false, $sectionreturn = 0, $sectioncontent = false) {
global $CFG;
$sectionurl = new \moodle_url('/course/view.php', ['id' => $course->id, 'section' => $section->section]);
/** @var format_designer $format */
$format = course_get_format($course);
$sectionstyle = '';
if ($section->section != 0) {
// Only in the non-general sections.
if (!$section->visible) {
$sectionstyle = ' hidden';
}
if (course_get_format($course)->is_section_current($section)) {
$sectionstyle = ' current';
}
}
$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$rightcontent = $this->section_right_content($section, $course, $onsectionpage);
$sectionname = html_writer::tag('span', $this->section_title($section, $course));
$sectionavailability = $this->section_availability($section);
$sectionrestrict = (!$section->uservisible && $section->availableinfo) ? true : false;
// CM LIST.
$cmlist = [];