forked from johndimopoulos/moodle-gradingform_erubric
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.php
More file actions
2186 lines (1954 loc) · 134 KB
/
Copy pathrenderer.php
File metadata and controls
2186 lines (1954 loc) · 134 KB
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/>.
/**
* Contains renderer used for displaying e-rubric
*
* @package gradingform
* @subpackage Learinng Analytics Enriched Rubric (e-rubric)
* @copyright 2012 John Dimopoulos
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// Required files for resources and grading
require_once($CFG->libdir.'/gradelib.php');
require_once("$CFG->libdir/resourcelib.php");
/**
* Grading method plugin renderer
*
* @package gradingform
* @subpackage Learinng Analytics Enriched Rubric (e-rubric)
* @copyright 2012 John Dimopoulos <johndimopoulos@sch.gr>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gradingform_erubric_renderer extends plugin_renderer_base {
//** Array to encapsulate the course resources (Book, File, URL etc.) that can be used for enrichment as 'moduleid->instanceid' => 'instancename'. */
protected $resources = array();
//** Array to encapsulate the course assignments (moodle 2.2 & 2.3 compatible) that can be used for enrichment as 'moduleid->instanceid' => 'instancename'. */
protected $assignments = array();
//** Array to encapsulate the course activities (of type forum or chat) that can be used for enrichment as 'moduleid->instanceid' => 'instancename'. */
protected $activities = array();
//** Array to encapsulate the icons for all this course's resources, assignments and activities (defined in here), as 'moduleid'=>'htmlimagestring' .*/
public $moduleicon = array();
//** Boolean to show missing course modules error message. *//
protected $missingmodules = null;
// Define the modules (chat-forum-old assignment-new assignment) ids that will be retrieved from modules table during _contruct.
public $chatmoduleid = null; // Make this public to use in erubriceditor.php.
protected $forummoduleid = null;
protected $oldassignmoduleid = null;
protected $newassignmoduleid = null;
/**
* Constructor
*
* The constructor takes two arguments. The first is the page that the renderer
* has been created to assist with, and the second is the target.
* The target is an additional identifier that can be used to load different
* renderers for different options.
*
* In order to create and initialize the appropriate arrays for resources, activities, assignments and icons,
* we must update the declared constructor of the parent class, and since we can't just update it, we declare it again
* adding the appropriate commands that suit our purpose.
*
* @param moodle_page $page the page we are doing output for.
* @param string $target one of rendering target constants
* @see core:renderer::__construct()
*/
public function __construct(moodle_page $page, $target) {
// Find and update course modules ids.
GLOBAL $DB;
$this->chatmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="chat"', null);
$this->forummoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="forum"', null);
$this->oldassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assignment"', null);
$this->newassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assign"', null);
$this->labelmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="label"', null); // Use the Label module id, to exclude it from course resources.
$this->output = $page->get_renderer('core', null, $target);
parent::__construct($page, $target);
// These are needed for the enriched rubric renderer construction.
$this->resources = $this->get_modules_array('resources', $this->moduleicon);
$this->assignments = $this->get_modules_array('assignments', $this->moduleicon);
$this->activities = $this->get_modules_array('activities', $this->moduleicon);
}
/**
* Function to update the renderer's icons array, according to modules used for the current course.
*
* @param array $moduleicons the renderer's icons for modules used.
* @param int $moduleid the id of the course module
* @param string $modulename the name of the course module to use it in order to obtain the icon url and to put it in image title tag
*/
private function check_update_modules_icon (&$moduleicons, $moduleid, $modulename) {
if (!array_key_exists($moduleid, $moduleicons)){
GLOBAL $OUTPUT;
$moduleicons[$moduleid] = '<img src="'.$OUTPUT->pix_url('icon', $modulename).'" title="'.ucfirst($modulename).'">';
}
}
/**
* Get list of Resources, Activities and Assingments for this course and this enriched rubric.
* As activities we take by default chat and forum modules, corresponding to students collaboration.
* For future adding of collaboration activities, the coresponding module ids are passed inside the
* moduleactivitiesids array.
* This function also calls the update function for the icons array of these course modules.
*
* @param array $moduleicons the renderer's icons for modules used
* @param string $mdtype the type description of the course module
*/
private function get_modules_array($mdtype, &$moduleicons) {
global $COURSE;
global $DB;
// Check cuurent moodle version against moodle version for new assignment type (Moodle 2.3).
global $CFG;
$moodle_2_3_0_version = '2012062500';
$newassignmentmodule = false;
if ($CFG->version >= $moodle_2_3_0_version)
$newassignmentmodule = true;
$moduleactivitiesids = array($this->chatmoduleid, $this->forummoduleid);
$returnArray = array();
$params = null;
// Make SQL statement according to module type.
switch ($mdtype) {
case 'assignments':
global $PAGE;
// In case this page is accessed for activity reporting do nothing.
if (!isset($PAGE->cm->modname)) return('');
$curmodule = $PAGE->cm->modname;
$curmoduleid = (int)$PAGE->cm->module;
$curmoduleinstance = $PAGE->cm->instance;
//**** For moodle 2.3 onwards ****//
if ($newassignmentmodule){
$sql = "SELECT cm.id AS uniqueID, cm.module, cm.instance, module.name, module.id, cm.course
FROM {course_modules} cm
INNER JOIN {modules} module ON (cm.module = module.id)
WHERE cm.course = $COURSE->id ";
if ($curmoduleid==$this->newassignmoduleid){
$sql .= "AND (cm.module = $this->oldassignmoduleid OR (cm.module = $this->newassignmoduleid AND cm.instance != $curmoduleinstance))";
}else{
$sql .= "AND (cm.module = $this->newassignmoduleid OR (cm.module = $this->oldassignmoduleid AND cm.instance != $curmoduleinstance))";
}
//**** For moodle 2.2 versions ****//
}else{
$sql = "SELECT cm.id AS uniqueID, cm.module, cm.instance, module.name, module.id, cm.course
FROM {course_modules} cm
INNER JOIN {modules} module ON (cm.module = module.id)
WHERE cm.course = $COURSE->id AND cm.module = $this->oldassignmoduleid AND cm.instance != $curmoduleinstance";
}
break;
case 'activities':
$sql = "SELECT cm.id AS uniqueID, cm.module, cm.instance, module.name, module.id, cm.course
FROM {course_modules} cm
INNER JOIN {modules} module ON (cm.module = module.id) ";
if ($newassignmentmodule){
$sql .= "WHERE cm.course = $COURSE->id AND cm.module != $this->oldassignmoduleid AND cm.module != $this->newassignmoduleid ";
}else{
$sql .= "WHERE cm.course = $COURSE->id AND cm.module != $this->oldassignmoduleid ";
}
$sizeofids = count($moduleactivitiesids);
if ($sizeofids>0){
$sql .= 'AND (';
foreach ($moduleactivitiesids as $i => $modid) {
$sql .= 'cm.module = '.$moduleactivitiesids[$i];
if ($i<$sizeofids-1) $sql .= ' || ';
}
$sql .= ')';
}
break;
case 'resources':
$sql = "SELECT cm.id AS uniqueID, cm.module, cm.instance, module.name, module.id, cm.course
FROM {course_modules} cm
INNER JOIN {modules} module ON (cm.module = module.id) ";
if ($newassignmentmodule){
$sql .= "WHERE cm.course = $COURSE->id AND cm.module != $this->labelmoduleid AND cm.module != $this->oldassignmoduleid AND cm.module != $this->newassignmoduleid ";
}else{
$sql .= "WHERE cm.course = $COURSE->id AND cm.module != $this->labelmoduleid AND cm.module != $this->oldassignmoduleid ";
}
$sizeofids = count($moduleactivitiesids);
if ($sizeofids>0){
foreach ($moduleactivitiesids as $i => $modid) {
$sql .= 'AND cm.module != '.$moduleactivitiesids[$i].' ';
}
}
break;
}
$rs = $DB->get_records_sql($sql, $params);
if ($mdtype=='resources' && !empty($rs)) {
$areresources = array(); // Put modules id for the ones that are already checked.
foreach ($rs as $record) {
// This module instance refers to a resource module. No need to check again. Just update the return array and moduleicons array.
if (in_array($record->module, $areresources)){
$modInstName = $DB->get_field($record->name, 'name', array('id'=>$record->instance));
$returnArray[$record->module.'->'.$record->instance] = $modInstName;
$this->check_update_modules_icon ($moduleicons, $record->module, $record->name); // Update icons array.
// Check if this module instance belongs to a resource module.
}else{
$archetype = plugin_supports('mod', $record->name, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
if ($archetype == MOD_ARCHETYPE_RESOURCE) {
$areresources[] = $record->module; // Add new module id in the array to avoid further check of module folder.
$modInstName = $DB->get_field($record->name, 'name', array('id'=>$record->instance));
$returnArray[$record->module.'->'.$record->instance] = $modInstName;
$this->check_update_modules_icon ($moduleicons, $record->module, $record->name); // Update icons array.
}
}
}
asort($returnArray);
}else if (!empty($rs)){
foreach ($rs as $record) {
$modInstName = $DB->get_field($record->name, 'name', array('id'=>$record->instance));
$returnArray[$record->module.'->'.$record->instance] = $modInstName;
$this->check_update_modules_icon ($moduleicons, $record->module, $record->name); // Update icons array.
}
asort($returnArray);
}
return $returnArray;
}
/**
* This function returns html code for displaying the tr of a simple criterion. Depending on $mode it may be the
* code to edit the enriched rubric, to preview it, to evaluate somebody or to review the evaluation.
*
* This function may be called from display_erubric() to display the whole enriched rubric, or it can be
* called by itself to return a template used by JavaScript to add new empty criteria to the
* enriched rubric being designed.
* In this case it will use macros like {NAME}, {LEVELS}, {CRITERION-id}, etc.
*
* When overriding this function it is very important to remember that all elements of html
* form (in edit or evaluate mode) must have the name $elementname.
*
* Also JavaScript relies on the class names of elements and when developer changes them
* script might stop working.
*
* @param int $mode enriched rubric display mode @see gradingform_erubric_controller
* @param array $options display options for this rubric, defaults are: {@link gradingform_erubric_controller::get_default_options()}
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param array|null $criterion criterion data
* @param string $levelsstr evaluated templates for this criterion levels
* @param array|null $value (only in view mode) teacher's feedback on this criterion
* @return string
*/
public function criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $levelsstr = '{LEVELS}', $value = null) {
// TODO description format, remark format
if ($criterion === null || !is_array($criterion) || !array_key_exists('id', $criterion)) {
$criterion = array('id' => '{CRITERION-id}', 'description' => '{CRITERION-description}', 'sortorder' => '{CRITERION-sortorder}', 'class' => '{CRITERION-class}', 'criteriontype' => '{CRITERION-criteriontype}');
} else {
foreach (array('sortorder', 'description', 'class', 'criteriontype') as $key) {
// Set missing array elements to empty strings to avoid warnings.
if (!array_key_exists($key, $criterion)) {
$criterion[$key] = '';
}
}
}
$criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}'));
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls'));
foreach (array('moveup', 'delete', 'movedown') as $key) {
$value = get_string('criterion'.$key, 'gradingform_erubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']',
'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value, 'tabindex' => -1));
$criteriontemplate .= html_writer::tag('div', $button, array('class' => $key));
}
$criteriontemplate .= html_writer::end_tag('td'); // .controls
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$description = html_writer::tag('textarea', s($criterion['description']), array('name' => '{NAME}[criteria][{CRITERION-id}][description]', 'cols' => '10', 'rows' => '5'));
} else {
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN) {
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][description]', 'value' => $criterion['description']));
}
$description = s($criterion['description']);
}
$descriptionclass = 'description';
if (isset($criterion['error_description'])) {
$descriptionclass .= ' error';
}
$criteriontemplate .= html_writer::tag('td', $description, array('class' => $descriptionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-description'));
$levelsstrtable = html_writer::tag('table', html_writer::tag('tr', $levelsstr, array('id' => '{NAME}-criteria-{CRITERION-id}-levels')));
$levelsclass = 'levels';
if (isset($criterion['error_levels'])) {
$levelsclass .= ' error';
}
$criteriontemplate .= html_writer::tag('td', $levelsstrtable, array('class' => $levelsclass));
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('criterionaddlevel', 'gradingform_erubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][addlevel]',
'id' => '{NAME}-criteria-{CRITERION-id}-levels-addlevel', 'value' => $value, 'title' => $value));
$criteriontemplate .= html_writer::tag('td', $button, array('class' => 'addlevel'));
}
$displayremark = ($options['enableremarks'] && ($mode != gradingform_erubric_controller::DISPLAY_VIEW || $options['showremarksstudent']));
if ($displayremark) {
$currentremark = '';
if (isset($value['remark'])) {
$currentremark = $value['remark'];
}
if ($mode == gradingform_erubric_controller::DISPLAY_EVAL) {
$input = html_writer::tag('textarea', s($currentremark), array('name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'rows' => '5'));
$criteriontemplate .= html_writer::tag('td', $input, array('class' => 'remark'));
} else if ($mode == gradingform_erubric_controller::DISPLAY_EVAL_FROZEN) {
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'value' => $currentremark));
}else if ($mode == gradingform_erubric_controller::DISPLAY_REVIEW || $mode == gradingform_erubric_controller::DISPLAY_VIEW) {
$criteriontemplate .= html_writer::tag('td', s($currentremark), array('class' => 'remark'));
}
}
$criteriontemplate .= html_writer::end_tag('tr');
$criteriontemplate = str_replace('{NAME}', $elementname, $criteriontemplate);
$criteriontemplate = str_replace('{CRITERION-id}', $criterion['id'], $criteriontemplate);
return $criteriontemplate;
}
/**
* This function returns html code for displaying the tr of an enriched criterion. Depending on $mode it may be the
* code to edit the enriched rubric, to preview it, to evaluate somebody or to review the evaluation.
*
* This function may be called from display_erubric() to display the whole enriched rubric, or it can be
* called by itself to return a template used by JavaScript to add new empty criteria to the
* enriched rubric being designed.
* In this case it will use macros like {NAME}, {LEVELS}, {CRITERION-id}, etc.
*
* When overriding this function it is very important to remember that all elements of html
* form (in edit or evaluate mode) must have the name $elementname.
*
* Also JavaScript relies on the class names of elements and when developer changes them
* script might stop working.
*
* @param int $mode enriched rubric display mode @see gradingform_erubric_controller
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param array|null $criterion criterion data
* @param string $levelsstr evaluated templates for this criterion levels
* @param array|null $value (only in view mode) teacher's feedback on this criterion
* @return string
*/
public function enriched_criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $levelsstr = '{LEVELS}', $value = null) {
// Display enriched criteria according to options.
if (!$options['showenrichedcriteriateacher'] && in_array($mode, array(gradingform_erubric_controller::DISPLAY_EVAL, gradingform_erubric_controller::DISPLAY_EVAL_FROZEN, gradingform_erubric_controller::DISPLAY_REVIEW))) {
return '';
}
if (!$options['showenrichedcriteriastudent'] && ($mode == gradingform_erubric_controller::DISPLAY_VIEW || $mode == gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED)) {
return '';
}
if ($criterion === null || !is_array($criterion) || !array_key_exists('id', $criterion)) {
$criterion = array('id' => '{CRITERION-id}', 'class' => '{CRITERION-class}', 'criteriontype' => '{CRITERION-criteriontype}',
'collaborationtype' => '{CRITERION-collaborationtype}', 'coursemodules' => '{CRITERION-coursemodules}',
'operator' => '{CRITERION-operator}', 'referencetype' => '{CRITERION-referencetype}');
} else {
foreach (array('class', 'criteriontype', 'collaborationtype', 'coursemodules', 'referencetype', 'operator') as $key) {
// Set missing array elements to empty strings to avoid warnings.
if (!array_key_exists($key, $criterion)) {
$criterion[$key] = '';
}
}
}
$enrichedcriteriontemplate = html_writer::start_tag('tr', array('class' => 'enrichedcriterion'. $criterion['class'], 'id' => '{NAME}-enriched-criteria-{CRITERION-id}'));
// Get the course modules for the criterion.
$moduletypename = '';
if ($criterion['coursemodules'] && is_array($criterion['coursemodules'])) {
foreach ($criterion['coursemodules'] as $modulename => $moduleids) { // This is one iteration step, just to get the modulename.
$moduletypename = $modulename;
// Get the already created array of modules according to the type of criterion aka. $modulename.
$moduleselectarray = array();
switch ($modulename) {
case 'assignment':
$moduleselectarray = $this->assignments;
$deletebuttontitle = get_string('deleteassignment', 'gradingform_erubric');
break;
case 'activity':
$moduleselectarray = $this->activities;
$deletebuttontitle = get_string('deleteactivity', 'gradingform_erubric');
break;
case 'resource':
$moduleselectarray = $this->resources;
$deletebuttontitle = get_string('deleteresource', 'gradingform_erubric');
break;
}
}
}
// Criterion type options array.
$criteriontypevalues = array(gradingform_erubric_controller::INTERACTION_TYPE_COLLABORATION=>get_string('selectcollaboration', 'gradingform_erubric'),
gradingform_erubric_controller::INTERACTION_TYPE_GRADE=>get_string('selectgrade', 'gradingform_erubric'),
gradingform_erubric_controller::INTERACTION_TYPE_STUDY=>get_string('selectstudy', 'gradingform_erubric'));
// Collaboration type options array.
$collaborationtypevalues = array(gradingform_erubric_controller::COLLABORATION_TYPE_ENTRIES=>get_string('collaborationtypeentries', 'gradingform_erubric'),
gradingform_erubric_controller::COLLABORATION_TYPE_FILE_ADDS=>get_string('collaborationtypefileadds', 'gradingform_erubric'),
gradingform_erubric_controller::COLLABORATION_TYPE_REPLIES=>get_string('collaborationtypereplies', 'gradingform_erubric'),
gradingform_erubric_controller::COLLABORATION_TYPE_INTERACTIONS=>get_string('collaborationtypeinteractions', 'gradingform_erubric'));
// Operator options array.
$operatorvalues = array( gradingform_erubric_controller::OPERATOR_EQUAL => get_string('criterionoperatorequals', 'gradingform_erubric'),
gradingform_erubric_controller::OPERATOR_MORE_THAN => get_string('criterionoperatormorethan', 'gradingform_erubric'));
// Value type options array.
$referencetypevalues = array( gradingform_erubric_controller::REFERENCE_STUDENT => get_string('referencetypenumber', 'gradingform_erubric'),
gradingform_erubric_controller::REFERENCE_STUDENTS => get_string('referencetypepercentage', 'gradingform_erubric'));
// Output select fields.
$criteriontype = '';
$collaborationtype = '';
$coursemodules = '';
$operator = '';
$referencetype = '';
// Output fields classes in case of errors.
$errorclasses = array('criteriontype'=>'', 'collaborationtype'=>'', 'coursemodules'=>'', 'operator'=>'', 'referencetype'=>'');
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
// Check for errors and update $errorclasses array.
foreach ($errorclasses as $key=>$values) {
if (array_key_exists('error_'.$key, $criterion)){
$errorclasses[$key] = ' error';
}
}
//*** Course Modules for the criterion ***//
if ($criterion['coursemodules'] && is_array($criterion['coursemodules'])) {
// When showing raw form data from a not validated form,
// change the coursemodules array to be the same with the array created from the database JSON string.
if (!is_array($criterion['coursemodules'][$moduletypename][0])) $criterion['coursemodules'][$moduletypename][0] = $criterion['coursemodules'][$moduletypename];
foreach ($criterion['coursemodules'][$moduletypename][0] as $mdlinstance) { // This loop iterates according to the number of course modules added
// Check if someone is trying to use this form as a template from another course,
// or if any of the previously stored enriched course modules have been erased
// and display error message.
if (!array_key_exists($mdlinstance, $moduleselectarray)){
$coursemodules .= html_writer::start_tag('li');
$coursemodules .= html_writer::start_tag('span', array('class'=>'missing'));
$coursemodules .= get_string('err_missingcoursemodule', 'gradingform_erubric');
$coursemodules .= html_writer::end_tag('span');
$coursemodules .= html_writer::end_tag('li');
// Update missing course modules error if needed.
if (!$this->missingmodules) $this->missingmodules = true;
}else{ // Proceed as normal.
// Create the appropriate instance array.
$tempinstance = explode('->', $mdlinstance);
$moduleid = $tempinstance[0];
$instanceid = $tempinstance[1];
$errorclass = '';
// Check for errors referring to collaboration criterion type.
if (array_key_exists('error_collaborationmodules', $criterion) && $moduleid==$this->chatmoduleid){
$errorclass = 'error';
}
$coursemodules .= html_writer::start_tag('li', array('id' => '{NAME}-criteria-{CRITERION-id}-'.$moduletypename.'-'.$moduleid.'-'.$instanceid, 'class'=>$errorclass));
$coursemodules .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][coursemodules]['.$moduletypename.'][]', 'value' => $mdlinstance));
$coursemodules .= $this->moduleicon[$moduleid].' '; // Display module icon.
$coursemodules .= html_writer::tag('span', $moduleselectarray[$mdlinstance], array('title'=>$moduleselectarray[$mdlinstance], 'class'=>'nameoverflowedit'));
$coursemodules .= html_writer::start_tag('div', array('class' => 'delete'));
$coursemodules .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][deletemodule]',
'id' => '{NAME}-criteria-{CRITERION-id}-'.$moduletypename.'-'.$moduleid.'-'.$instanceid.'-deletemodule',
'value' => '{NAME}-criteria-{CRITERION-id}-'.$moduletypename.'-'.$moduleid.'-'.$instanceid, 'title' => $deletebuttontitle, 'tabindex'=> '-1'));
$coursemodules .= html_writer::end_tag('div');
$coursemodules .= html_writer::end_tag('li');
}
}
}
// Enrichement select fields.
$criteriontype = html_writer::select($criteriontypevalues, '{NAME}[criteria][{CRITERION-id}][criteriontype]', $criterion['criteriontype'], array(''=>' '), array('class'=>'criteriontype', 'id' => '{NAME}-criteria-{CRITERION-id}-criteriontype'));
$activity = html_writer::select($this->activities, '{NAME}[criteria][{CRITERION-id}][activity]', '', array(''=>get_string('addnew', 'gradingform_erubric')), array('class'=>'activity', 'id' => '{NAME}-criteria-{CRITERION-id}-activity'));
$assignment = html_writer::select($this->assignments, '{NAME}[criteria][{CRITERION-id}][assignment]', '', array(''=>get_string('addnew', 'gradingform_erubric')), array('class'=>'assignment', 'id' => '{NAME}-criteria-{CRITERION-id}-assignment'));
$resource = html_writer::select($this->resources, '{NAME}[criteria][{CRITERION-id}][resource]', '', array(''=>get_string('addnew', 'gradingform_erubric')), array('class'=>'resource', 'id' => '{NAME}-criteria-{CRITERION-id}-resource'));
$collaborationtype = html_writer::select($collaborationtypevalues, '{NAME}[criteria][{CRITERION-id}][collaborationtype]', $criterion['collaborationtype'], array(''=>' '), array('class'=>'collaborationtype', 'id' => '{NAME}-criteria-{CRITERION-id}-collaborationtype'));
$operator = html_writer::select($operatorvalues, '{NAME}[criteria][{CRITERION-id}][operator]', $criterion['operator'], array(''=>' '), array('class'=>'operator', 'id' => '{NAME}-criteria-{CRITERION-id}-operator'));
$referencetype = html_writer::select($referencetypevalues, '{NAME}[criteria][{CRITERION-id}][referencetype]', $criterion['referencetype'], array(''=>' '), array('class'=>'referencetype', 'id' => '{NAME}-criteria-{CRITERION-id}-referencetype'));
} else {
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN) {
$enrichedcriteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][criteriontype]', 'value' => $criterion['criteriontype']));
$enrichedcriteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][collaborationtype]', 'value' => $criterion['collaborationtype']));
$enrichedcriteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][operator]', 'value' => $criterion['operator']));
$enrichedcriteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][referencetype]', 'value' => $criterion['referencetype']));
}
// If there are course modules to display.
if ($criterion['coursemodules'] && is_array($criterion['coursemodules'])) {
// If showing raw form data from a not validated form,
// change the coursemodules array to be the same with the array created from the database JSON string.
if (!is_array($criterion['coursemodules'][$moduletypename][0])) $criterion['coursemodules'][$moduletypename][0] = $criterion['coursemodules'][$moduletypename];
foreach ($criterion['coursemodules'][$moduletypename][0] as $mdlinstance) { // This loop iterates according to the number of course modules added.
// Check if someone is trying to use this form as a template from another course
// or if any of the previously stored enriched course modules has been erased
// and display error message unless this form is of mode DISPLAY_VIEW or DISPLAY_PREVIEW_GRADED.
if (!array_key_exists($mdlinstance, $moduleselectarray)){
if ($mode != gradingform_erubric_controller::DISPLAY_VIEW && $mode != gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED){
$coursemodules .= html_writer::start_tag('li');
$coursemodules .= html_writer::start_tag('span', array('class'=>'missing'));
$coursemodules .= get_string('err_missingcoursemodule', 'gradingform_erubric');
$coursemodules .= html_writer::end_tag('span');
$coursemodules .= html_writer::end_tag('li');
// Update missing course modules error if needed.
if (!$this->missingmodules) $this->missingmodules = true;
}
}else{ // Proceed as normal.
$tempinstance = explode('->', $mdlinstance); // Create the appropriate instance array.
$moduleid = $tempinstance[0];
$instanceid = $tempinstance[1];
$coursemodules .= html_writer::start_tag('li', array('id' => '{NAME}-criteria-{CRITERION-id}-'.$moduletypename.'-'.$moduleid.'-'.$instanceid));
$coursemodules .= $this->moduleicon[$moduleid].' '; // Display module icon
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN) {
$enrichedcriteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][coursemodules]['.$moduletypename.'][]', 'value' => $mdlinstance));
}
$coursemodules .= html_writer::tag('span', $moduleselectarray[$mdlinstance], array('title'=>$moduleselectarray[$mdlinstance], 'class'=>'nameoverflow'));
$coursemodules .= html_writer::end_tag('li');
}
}
}
if ($criterion['criteriontype']) $criteriontype = html_writer::tag('div', $criteriontypevalues[$criterion['criteriontype']], array('class'=>'plainvaluerich'));
if ($criterion['collaborationtype']) $collaborationtype = html_writer::tag('div', $collaborationtypevalues[$criterion['collaborationtype']], array('class'=>'plainvaluerich'));
if ($criterion['operator']) $operator = html_writer::tag('div', $operatorvalues[$criterion['operator']], array('class'=>'plainvaluerich'));
if ($criterion['referencetype']) $referencetype = html_writer::tag('div', $referencetypevalues[$criterion['referencetype']], array('class'=>'plainvaluerich'));
}
// Handle tr's first 2 columns.
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$enrichedcriteriontemplate .= html_writer::start_tag('td', array('colspan' => '2', 'class' => 'enrichedcriteria', 'id' => '{NAME}-criteria-{CRITERION-id}-enriched_interaction'));
}else{
$enrichedcriteriontemplate .= html_writer::start_tag('td', array('class' => 'enrichedcriteria', 'id' => '{NAME}-criteria-{CRITERION-id}-enriched_interaction'));
}
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'enriched-wrapper'));
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'rich'.$errorclasses['criteriontype']));
$enrichedcriteriontemplate .= get_string('participationin', 'gradingform_erubric');
$enrichedcriteriontemplate .= $criteriontype;
$enrichedcriteriontemplate .= html_writer::end_tag('div');
// Check if collaboration type should be displayed.
if ($collaborationtype || $mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'rich'.$errorclasses['collaborationtype']));
$enrichedcriteriontemplate .= get_string('collaborationtype', 'gradingform_erubric');
$enrichedcriteriontemplate .= $collaborationtype;
$enrichedcriteriontemplate .= html_writer::end_tag('div');
}
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'rich coursemodule'.$errorclasses['coursemodules']));
$enrichedcriteriontemplate .= get_string('coursemoduleis', 'gradingform_erubric');
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'modulecontainer'));
$enrichedcriteriontemplate .= html_writer::start_tag('ul');
$enrichedcriteriontemplate .= $coursemodules;
$enrichedcriteriontemplate .= html_writer::end_tag('ul');
// Check if course modules selects should be displayed.
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$enrichedcriteriontemplate .= $activity;
$enrichedcriteriontemplate .= $resource;
$enrichedcriteriontemplate .= $assignment;
}
$enrichedcriteriontemplate .= html_writer::end_tag('div'); // End of module container with contents and select fields
$enrichedcriteriontemplate .= html_writer::end_tag('div');
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'rich'.$errorclasses['operator']));
$enrichedcriteriontemplate .= get_string('participationis', 'gradingform_erubric');
$enrichedcriteriontemplate .= $operator;
$enrichedcriteriontemplate .= html_writer::end_tag('div');
$enrichedcriteriontemplate .= html_writer::start_tag('div', array('class' => 'rich'.$errorclasses['referencetype']));
$enrichedcriteriontemplate .= get_string('participationon', 'gradingform_erubric');
$enrichedcriteriontemplate .= $referencetype;
$enrichedcriteriontemplate .= html_writer::end_tag('div');
$enrichedcriteriontemplate .= html_writer::end_tag('div');
$enrichedcriteriontemplate .= html_writer::end_tag('td');
// Create the levels table.
$levelsstrtable = html_writer::tag('table', html_writer::tag('tr', $levelsstr, array('id' => '{NAME}-enriched-criteria-{CRITERION-id}-levels')));
$levelsclass = 'levels';
if (isset($criterion['error_levels'])) {
$levelsclass .= ' error';
}
$enrichedcriteriontemplate .= html_writer::tag('td', $levelsstrtable, array('class' => $levelsclass)); // Attach the levels table.
// Check if help icon for enrichment should be displayed.
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
global $OUTPUT;
$identifier = 'enrichment';
$component = 'gradingform_erubric';
$linktext = '';
$helpicon = $OUTPUT->help_icon($identifier, $component, $linktext);
$enrichedcriteriontemplate .= html_writer::tag('td', $helpicon, array('class' => 'addlevel'));
}
// Check if the benchmark from evaluation should be displayed or leave an empty td.
$displayremark = ($options['enableremarks'] && $mode == gradingform_erubric_controller::DISPLAY_VIEW && $options['showremarksstudent']);
$displaybenchmark = (($options['showenrichedbenchmarkstudent'] && $mode == gradingform_erubric_controller::DISPLAY_VIEW) ||
($options['showenrichedbenchmarkteacher'] && ($mode == gradingform_erubric_controller::DISPLAY_EVAL ||
$mode == gradingform_erubric_controller::DISPLAY_EVAL_FROZEN)));
if ($displaybenchmark) { // Display benchmark.
// Get the benchmarks (if they exists) from values array, to display them to student.
if (!array_key_exists('enrichedbenchmark', $criterion) && isset($value['enrichedbenchmark']))
$criterion['enrichedbenchmark'] = $value['enrichedbenchmark'];
if (!array_key_exists('enrichedbenchmarkstudent', $criterion) && isset($value['enrichedbenchmarkstudent']))
$criterion['enrichedbenchmarkstudent'] = $value['enrichedbenchmarkstudent'];
if (!array_key_exists('enrichedbenchmarkstudents', $criterion) && isset($value['enrichedbenchmarkstudents']))
$criterion['enrichedbenchmarkstudents'] = $value['enrichedbenchmarkstudents'];
$benchmarkstr = '';
// If there are benchmarks in the criterion data (even null).
if (array_key_exists('enrichedbenchmark', $criterion) || array_key_exists('enrichedbenchmarkstudents', $criterion)){
//** In case of evalluation, put value in hidden field to update enriched rubric fillings. **//
if (($mode == gradingform_erubric_controller::DISPLAY_EVAL || $mode == gradingform_erubric_controller::DISPLAY_EVAL_FROZEN)){
// Criterion benchmark.
if (strlen((String)$criterion['enrichedbenchmark'])>0){
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmark]', 'value' => $criterion['enrichedbenchmark']));
}else{
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmark]', 'value' => ''));
}
// Student benchmark.
if (strlen((String)$criterion['enrichedbenchmarkstudent'])>0){
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmarkstudent]', 'value' => $criterion['enrichedbenchmarkstudent']));
}else{
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmarkstudent]', 'value' => ''));
}
// Students benchmark.
if (strlen((String)$criterion['enrichedbenchmarkstudents'])>0) {
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmarkstudents]', 'value' => $criterion['enrichedbenchmarkstudents']));
}else{
$benchmarkstr .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][enrichedbenchmarkstudents]', 'value' => ''));
}
}
// If there was a reference according to students avaluation, show student and students avereges.
if ($criterion['referencetype'] == gradingform_erubric_controller::REFERENCE_STUDENTS && array_key_exists('enrichedbenchmarkstudents', $criterion) && !is_null($criterion['enrichedbenchmarkstudents'])) {
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'studentico', 'title' => get_string('studentbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'rightarrow'));
$benchmarkstr .= html_writer::tag('div', $criterion['enrichedbenchmarkstudent'], array('class' => 'valuecontainer', 'title' => get_string('studentbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'ranges'));
$benchmarkstr .= html_writer::empty_tag('hr');
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'studentsico', 'title' => get_string('studentsbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'rightarrow'));
$benchmarkstr .= html_writer::tag('div', $criterion['enrichedbenchmarkstudents'], array('class' => 'valuecontainer', 'title' => get_string('studentsbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'ranges'));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'downarrow'));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'calculator', 'title' => get_string('benchmarkfinal', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'rightarrow'));
$benchmarkstr .= html_writer::tag('div', $criterion['enrichedbenchmark'].'%', array('class' => 'valuecontainer', 'title' => get_string('benchmarkfinal', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'outcome', 'title' => get_string('benchmarkfinal', 'gradingform_erubric')));
// If the student benchmark is valid, display it.
} else if (array_key_exists('enrichedbenchmark', $criterion) && !is_null($criterion['enrichedbenchmark'])) {
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'studentico', 'title' => get_string('studentbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'rightarrow'));
$benchmarkstr .= html_writer::tag('div', $criterion['enrichedbenchmark'], array('class' => 'valuecontainer', 'title' => get_string('studentbenchmarkinfo', 'gradingform_erubric')));
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'ranges'));
// Student or sudents benchmarks have no valid value.
}else{
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'valuenull', 'title' => get_string('benchmarkinfonull', 'gradingform_erubric')));
}
// If there are no benchmarks in the criterion and this form is displayed to a student.
}else if ($mode == gradingform_erubric_controller::DISPLAY_VIEW) {
$benchmarkstr .= html_writer::tag('div', '', array('class' => 'valuenull', 'title' => get_string('benchmarkinfonull', 'gradingform_erubric')));
}
$enrichedcriteriontemplate .= html_writer::tag('td', $benchmarkstr, array('class' => 'results', 'title' => get_string('benchmarkinfo', 'gradingform_erubric')));
}
if ($displayremark && !$displaybenchmark) { // Display empty td.
$enrichedcriteriontemplate .= html_writer::tag('td', '', array('class' => 'results'));
}
$enrichedcriteriontemplate .= html_writer::end_tag('tr'); // Close the enriched criterion table row.
$enrichedcriteriontemplate = str_replace('{NAME}', $elementname, $enrichedcriteriontemplate);
$enrichedcriteriontemplate = str_replace('{CRITERION-id}', $criterion['id'], $enrichedcriteriontemplate);
return $enrichedcriteriontemplate;
}
/**
* This function returns html code for displaying one simple level of one criterion. Depending on $mode
* it may be the code to edit enriched rubric, to preview it, to evaluate somebody or to review the evaluation.
*
* This function may be called from display_erubric() to display the whole rubric, or it can be
* called by itself to return a template used by JavaScript to add new empty level to the
* criterion during the design of the enriched rubric.
* In this case it will use macros like {NAME}, {CRITERION-id}, {LEVEL-id}, etc.
*
* When overriding this function it is very important to remember that all elements of html
* form (in edit or evaluate mode) must have the name $elementname.
*
* Also JavaScript relies on the class names of elements and when developer changes them
* script might stop working.
*
* @param int $mode rubric display mode @see gradingform_erubric_controller
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param string|int $criterionid either id of the nesting criterion or a macro for template
* @param array|null $level level data, also in view mode it might also have property $level['checked'] whether this level is checked
* @return string
*/
public function level_template($mode, $options, $elementname = '{NAME}', $criterionid = '{CRITERION-id}', $level = null) {
if (!isset($level['id'])) {
$level = array('id' => '{LEVEL-id}', 'definition' => '{LEVEL-definition}', 'score' => '{LEVEL-score}', 'class' => '{LEVEL-class}', 'checked' => false, 'enrichedvalue' => '{LEVEL-enrichedvalue}');
} else {
foreach (array('score', 'definition', 'class', 'checked', 'enrichedvalue') as $key) {
// Set missing array elements to empty strings to avoid warnings.
if (!array_key_exists($key, $level)) {
$level[$key] = '';
}
}
}
// Template for one level within one criterion.
$tdattributes = array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}', 'class' => 'level'. $level['class']);
if (isset($level['tdwidth'])) {
$tdattributes['width'] = round($level['tdwidth']).'%';
}
$leveltemplate = html_writer::start_tag('td', $tdattributes);
$leveltemplate .= html_writer::start_tag('div', array('class' => 'level-wrapper'));
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$definition = html_writer::tag('textarea', s($level['definition']), array('name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'cols' => '10', 'rows' => '4'));
$score = html_writer::empty_tag('input', array('type' => 'text', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'size' => '3', 'value' => $level['score']));
} else {
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN) {
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'value' => $level['definition']));
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'value' => $level['score']));
}
$definition = s($level['definition']);
$score = $level['score'];
}
if ($mode == gradingform_erubric_controller::DISPLAY_EVAL) {
$input = html_writer::empty_tag('input', array('type' => 'radio', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']) +
($level['checked'] ? array('checked' => 'checked') : array()));
$leveltemplate .= html_writer::tag('div', $input, array('class' => 'radio'));
}
if ($mode == gradingform_erubric_controller::DISPLAY_EVAL_FROZEN && $level['checked']) {
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']));
}
$score = html_writer::tag('span', $score, array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-score', 'class' => 'scorevalue'));
$definitionclass = 'definition';
if (isset($level['error_definition'])) {
$definitionclass .= ' error';
}
$leveltemplate .= html_writer::tag('div', $definition, array('class' => $definitionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-definition'));
$displayscore = true;
if (!$options['showscoreteacher'] && in_array($mode, array(gradingform_erubric_controller::DISPLAY_EVAL, gradingform_erubric_controller::DISPLAY_EVAL_FROZEN, gradingform_erubric_controller::DISPLAY_REVIEW))) {
$displayscore = false;
}
if (!$options['showscorestudent'] && in_array($mode, array(gradingform_erubric_controller::DISPLAY_VIEW, gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED))) {
$displayscore = false;
}
if ($displayscore) {
$scoreclass = 'score';
if (isset($level['error_score'])) {
$scoreclass .= ' error';
}
$leveltemplate .= html_writer::tag('div', get_string('scorepostfix', 'gradingform_erubric', $score), array('class' => $scoreclass));
}
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('leveldelete', 'gradingform_erubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][delete]', 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-delete', 'value' => $value, 'title' => $value, 'tabindex' => -1));
$leveltemplate .= html_writer::tag('div', $button, array('class' => 'delete'));
}
$leveltemplate .= html_writer::end_tag('div'); // .level-wrapper
$leveltemplate .= html_writer::end_tag('td'); // .level
$leveltemplate = str_replace('{NAME}', $elementname, $leveltemplate);
$leveltemplate = str_replace('{CRITERION-id}', $criterionid, $leveltemplate);
$leveltemplate = str_replace('{LEVEL-id}', $level['id'], $leveltemplate);
return $leveltemplate;
}
/**
* This function returns html code for displaying one enriched level of one criterion. Depending on $mode
* it may be the code to edit enriched rubric, to preview it, to evaluate somebody or to review the evaluation.
*
* This function may be called from display_erubric() to display the whole rubric, or it can be
* called by itself to return a template used by JavaScript to add new empty level to the
* criterion during the design of the enriched rubric.
* In this case it will use macros like {NAME}, {CRITERION-id}, {LEVEL-id}, etc.
*
* When overriding this function it is very important to remember that all elements of html
* form (in edit or evaluate mode) must have the name $elementname.
*
* Also JavaScript relies on the class names of elements and when developer changes them
* script might stop working.
*
* @param int $mode rubric display mode @see gradingform_erubric_controller
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param string|int $criterionid either id of the nesting criterion or a macro for template
* @param array|null $level level data, also in view mode it might also have property $level['checked'] whether this level is checked
* @return string
*/
public function enriched_level_template($mode, $options, $elementname = '{NAME}', $criterionid = '{CRITERION-id}', $level = null) {
if (!isset($level['id'])) {
$level = array('id' => '{LEVEL-id}', 'class' => '{LEVEL-class}', 'checked' => false, 'enrichedvalue' => '{LEVEL-enrichedvalue}', 'enrichedvaluesuffix'=>'');
} else {
foreach (array('class', 'checked', 'enrichedvalue', 'enrichedvaluesuffix') as $key) {
// Set missing array elements to empty strings to avoid warnings.
if (!array_key_exists($key, $level)) {
$level[$key] = '';
}
}
}
// Template for one level within one criterion.
$tdattributes = array('id' => '{NAME}-enriched-criteria-{CRITERION-id}-levels-{LEVEL-id}', 'class' => 'enrichedlevel'. $level['class']);
if (isset($level['tdwidth'])) {
$tdattributes['width'] = round($level['tdwidth']).'%';
}
$enrichedleveltemplate = html_writer::start_tag('td', $tdattributes);
// Check the options about showing the levels' enriched value.
$displayvalue = true;
$enrichedvalueclass = 'richvalue';
if (!$options['showenrichedvalueteacher'] && in_array($mode, array(gradingform_erubric_controller::DISPLAY_EVAL, gradingform_erubric_controller::DISPLAY_EVAL_FROZEN, gradingform_erubric_controller::DISPLAY_REVIEW))) {
$displayvalue = false;
}
if (!$options['showenrichedvaluestudent'] && ($mode == gradingform_erubric_controller::DISPLAY_VIEW || $mode == gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED)) {
$displayvalue = false;
}
if ($displayvalue && (isset($level['error_enrichedvalueformat']) || isset($level['error_enrichedvaluemissing']))) {
$enrichedvalueclass .= ' error';
}
if ($mode == gradingform_erubric_controller::DISPLAY_EVAL) {
if ($level['checked']) $enrichedvalueclass .= ' checked';
}
$enrichedleveltemplate .= html_writer::start_tag('div', array('class' => $enrichedvalueclass));
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$enrichedvalue = html_writer::empty_tag('input', array('type' => 'text', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][enrichedvalue]', 'size' => '3', 'value' => $level['enrichedvalue']));
} else {
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN) {
$enrichedleveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][enrichedvalue]', 'value' => $level['enrichedvalue']));
}
$enrichedvalue = $level['enrichedvalue'];
}
if ($mode == gradingform_erubric_controller::DISPLAY_EVAL_FROZEN && $level['checked']) {
$enrichedleveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][enrichedvalue]', 'value' => $level['enrichedvalue']));
}
$enrichedvalue = html_writer::tag('span', $enrichedvalue, array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-enrichedvalue', 'class' => 'enrichedvalue'));
$enrichedvalue .= html_writer::tag('i', $level['enrichedvaluesuffix'], array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-enrichedvaluesuffix'));
if ($displayvalue) {
$enrichedleveltemplate .= $enrichedvalue;
}
$enrichedleveltemplate .= html_writer::end_tag('div'); // .richvalue
$enrichedleveltemplate .= html_writer::end_tag('td'); // .level
$enrichedleveltemplate = str_replace('{NAME}', $elementname, $enrichedleveltemplate);
$enrichedleveltemplate = str_replace('{CRITERION-id}', $criterionid, $enrichedleveltemplate);
$enrichedleveltemplate = str_replace('{LEVEL-id}', $level['id'], $enrichedleveltemplate);
return $enrichedleveltemplate;
}
/**
* This function returns html code for displaying enriched rubric template (content before and after
* criteria list). Depending on $mode it may be the code to edit the eriched rubric, to preview it,
* to evaluate somebody or to review the evaluation.
*
* This function is called from display_erubric() to display the whole rubric.
*
* When overriding this function it is very important to remember that all elements of html
* form (in edit or evaluate mode) must have the name $elementname.
*
* Also JavaScript relies on the class names of elements and when developer changes them
* script might stop working.
*
* @param int $mode rubric display mode @see gradingform_erubric_controller
* @param array $options display options for this rubric, defaults are: {@link gradingform_erubric_controller::get_default_options()}
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param string $criteriastr evaluated templates for this rubric's criteria
* @return string
*/
protected function erubric_template($mode, $options, $elementname, $criteriastr) {
// CSS suffix for class of the main div. Depends on the mode and language (for Greek).
$classsuffix = '';
$lang = current_language();
if ($lang == 'el') $classsuffix = ' hellenic';
switch ($mode) {
case gradingform_erubric_controller::DISPLAY_EDIT_FULL:
$classsuffix .= ' editor editable'; break;
case gradingform_erubric_controller::DISPLAY_EDIT_FROZEN:
$classsuffix .= ' editor frozen'; break;
case gradingform_erubric_controller::DISPLAY_PREVIEW:
case gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED:
$classsuffix .= ' editor preview'; break;
case gradingform_erubric_controller::DISPLAY_EVAL:
$classsuffix .= ' evaluate editable'; break;
case gradingform_erubric_controller::DISPLAY_EVAL_FROZEN:
$classsuffix .= ' evaluate frozen'; break;
case gradingform_erubric_controller::DISPLAY_REVIEW:
$classsuffix .= ' review'; break;
case gradingform_erubric_controller::DISPLAY_VIEW:
$classsuffix .= ' view'; break;
}
$enrichedrubrictemplate = '';
// Display error message in case of missing course modules.
if ($this->missingmodules && $mode != gradingform_erubric_controller::DISPLAY_VIEW && $mode != gradingform_erubric_controller::DISPLAY_PREVIEW_GRADED){
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL || $mode == gradingform_erubric_controller::DISPLAY_EDIT_FROZEN){
$enrichedrubrictemplate .= $this->box(
html_writer::tag('div', get_string('err_missingcoursemodulesedit', 'gradingform_erubric'), array('class' => 'missingmodule'))
, 'generalbox');
}else{
$enrichedrubrictemplate .= $this->box(
html_writer::tag('div', get_string('err_missingcoursemodules', 'gradingform_erubric'), array('class' => 'missingmodule'))
, 'generalbox');
}
}
$enrichedrubrictemplate .= html_writer::start_tag('div', array('id' => 'erubric-{NAME}', 'class' => 'clearfix gradingform_erubric'.$classsuffix));
$enrichedrubrictemplate .= html_writer::tag('table', $criteriastr, array('class' => 'criteria', 'id' => '{NAME}-criteria'));
if ($mode == gradingform_erubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('addcriterion', 'gradingform_erubric');
$input = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][addcriterion]', 'id' => '{NAME}-criteria-addcriterion', 'value' => $value, 'title' => $value));
$enrichedrubrictemplate .= html_writer::tag('div', $input, array('class' => 'addcriterion'));
}
$enrichedrubrictemplate .= $this->erubric_edit_options($mode, $options);
$enrichedrubrictemplate .= html_writer::end_tag('div');
return str_replace('{NAME}', $elementname, $enrichedrubrictemplate);
}
/**
* Generates html template to view/edit the enriched rubric options. Expression {NAME} is used in
* template for the form element name.
*
* @param int $mode rubric display mode see {@link gradingform_erubric_controller}
* @param array $options display options for this rubric, defaults are: {@link gradingform_erubric_controller::get_default_options()}
* @return string
*/
protected function erubric_edit_options($mode, $options) {
if ($mode != gradingform_erubric_controller::DISPLAY_EDIT_FULL
&& $mode != gradingform_erubric_controller::DISPLAY_EDIT_FROZEN
&& $mode != gradingform_erubric_controller::DISPLAY_PREVIEW) {
// Options are displayed only in edit mode.
return;
}
$html = html_writer::start_tag('div', array('class' => 'options'));
$html .= html_writer::tag('div', get_string('rubricoptions', 'gradingform_erubric'), array('class' => 'optionsheading'));
$attrs = array('type' => 'hidden', 'name' => '{NAME}[options][optionsset]', 'value' => 1);
foreach ($options as $option => $value) {
$html .= html_writer::start_tag('div', array('class' => 'option '.$option));
$attrs = array('name' => '{NAME}[options]['.$option.']', 'id' => '{NAME}-options-'.$option);
switch ($option) {
case 'sortlevelsasc':
// Display option as dropdown.
$html .= html_writer::tag('span', get_string($option, 'gradingform_erubric'), array('class' => 'label'));
$value = (int)(!!$value); // Make sure $value is either 0 or 1.