forked from Neoforgetech/moodle-mod_peerreview
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassignment.class.php
More file actions
2904 lines (2540 loc) · 155 KB
/
Copy pathassignment.class.php
File metadata and controls
2904 lines (2540 loc) · 155 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/>.
/**
* Peer Review assignment class extension
*
* @package contrib
* @subpackage assignment_progress
* @copyright 2010 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* Notes about generic Assignment fields
*
* assignment->var1 is used for reward value of each review
* assignment->var2 is used for optional self-reflection
* assignment->var3 is used to distinguish between submission of a file or online text
* submission->data1 is used for an online submission text (if that form of submission is chosen)
*
*/
// Extend the base assignment class for peer review assignments
class assignment_peerreview {
// File related constants
const FILE_PREFIX = 'toReview';
const CRITERIA_FILE = 'criteria.php';
const DOWNLOAD_PEERREVIEW_FILE = 'downloadFileToReview.php';
const VIEW_ONLINE_TEXT = 'viewOnlineText.php';
const MASS_MARK_FILE = 'massMark.php';
const SAVE_COMMENTS_FILE = 'saveComments.php';
const SET_MARK_FILE = 'setMark.php';
const STYLES_FILE = 'styles.php';
const TOGGLE_FLAG_FILE = 'toggleFlag.php';
const RESUBMIT_FILE = 'resubmit.php';
const SUBMISSIONS_FILE = 'submissions.php';
const ANALYSIS_FILE = 'analysis.php';
const VIEW_FILE = 'view.php';
// Submission formats
const SUBMIT_DOCUMENT = 0;
const ONLINE_TEXT = 1;
// Review constants
public $REVIEW_COLOURS = array('#DCB39D','#AEA97E','#C1D692','#E1E1AE');
public $REVIEW_COMMENT_COLOURS = array('#FCD3BD','#CEC99E','#E1F6B2','#F1F1CE');
public $NUMBER_OF_COLOURS = 4; //count($this->REVIEW_COLOURS);
const REVIEW_FEEDBACK_MIN = 10; // reviews
const MINIMAL_REVIEW_TIME = 30; // seconds
const MINIMAL_REVIEW_COMMENT_LENGTH = 12; // characters
const ACCURACY_REQUIRED = 0.7;
const ACCEPTABLE_REVIEW_RATE = 0.9;
const ACCEPTABLE_REVIEW_ATTENTION_RATE = 0.9;
const ACCEPTABLE_MODERATION_RATE = 0.6;
const ACCEPTABLE_REVIEW_TIME = 60; // seconds
const ACCEPTABLE_COMMENT_LENGTH = 50; // characters
const ACCEPTABLE_FLAG_RATE = 0.1;
const ACCEPTABLE_CHECKED_RATE = 0.5;
// Status values
const FLAGGED = 0; // Moderation required
const CONFLICTING = 1; // Moderation required
const FLAGGEDANDCONFLICTING = 2; // Moderation required
const LESSTHANTWOREVIEWS = 3; // Moderation required
const CONCENSUS = 4; // Good
const OVERRIDDEN = 5; // Good
//--------------------------------------------------------------------------
// Constructor
function assignment_peerreview($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
$this->base($cmid, $assignment, $cm, $course);
global $DB;
$this->strassignment = get_string('modulename', 'peerreview');
$this->strassignments = get_string('modulenameplural', 'peerreview');
$this->type = 'peerreview';
if(isset($this->assignment->id) && $extra_settings = $DB->get_record('peerreview',array('id'=>$this->assignment->id))) {
$this->assignment->fileextension = $extra_settings->fileextension;
$this->assignment->savedcomments = $extra_settings->savedcomments;
}
}
function base($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
global $COURSE;
if ($cmid == 'staticonly') {
//use static functions only!
return;
}
global $CFG,$DB;
if ($cm) {
$this->cm = $cm;
} else if (! $this->cm = get_coursemodule_from_id('peerreview', $cmid)) {
error('Course Module ID was incorrect');
}
$this->context = context_module::instance($this->cm->id);
if ($course) {
$this->course = $course;
} else if ($this->cm->course == $COURSE->id) {
$this->course = $COURSE;
} else if (! $this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
error('Course is misconfigured');
}
if ($assignment) {
$this->assignment = $assignment;
} else if (! $this->assignment = $DB->get_record('peerreview',array('id'=> $this->cm->instance))) {
error('assignment ID was incorrect');
}
$this->assignment->cmidnumber = $this->cm->id; // compatibility with modedit assignment obj
$this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj
$this->strassignment = get_string('modulename', 'peerreview');
$this->strassignments = get_string('modulenameplural', 'peerreview');
$this->strsubmissions = get_string('submissions', 'peerreview');
$this->strlastmodified = get_string('lastmodified');
$this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
// visibility handled by require_login() with $cm parameter
// get current group only when really needed
/// Set up things for a HTML editor if it's needed
/*if ($this->usehtmleditor = can_use_html_editor()) {
$this->defaultformat = FORMAT_HTML;
} else {
$this->defaultformat = FORMAT_MOODLE;
}*/
$this->defaultformat = FORMAT_MOODLE;
}
//--------------------------------------------------------------------------
// Not used with peerreview but needs to be overloaded here
function print_student_answer($userid, $return=false){
}
//--------------------------------------------------------------------------
// The main view function
function view() {
global $USER, $CFG;
$context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
require_capability('mod/assignment:view', $context);
$teacher = has_capability('mod/assignment:grade', $context);
$criteriaList = get_records_list('assignment_criteria','assignment',$this->assignment->id,'ordernumber');
$numberOfCriteria = 0;
if(is_array($criteriaList)) {
$criteriaList = array_values($criteriaList);
$numberOfCriteria = count($criteriaList);
}
if($teacher && $numberOfCriteria==0) {
redirect($CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::CRITERIA_FILE.'?id='.$this->cm->id.'&a='.$this->assignment->id,0);
return;
}
$submission = $this->get_submission();
$reviewsAllocated = get_records_select('assignment_review','assignment=\''.$this->assignment->id.'\' and reviewer=\''.$USER->id.'\' ORDER BY id ASC');
if(is_array($reviewsAllocated)) {
$reviewsAllocated = array_values($reviewsAllocated);
$numberOfReviewsAllocated = count($reviewsAllocated);
}
else {
$numberOfReviewsAllocated = 0;
}
$numberOfReviewsDownloaded = count_records('assignment_review','assignment',$this->assignment->id,'reviewer',$USER->id,'downloaded','1');
$numberOfReviewsCompleted = count_records('assignment_review','assignment',$this->assignment->id,'reviewer',$USER->id,'complete','1');
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
$this->view_header();
//Determine what stage the student is up to and show progress
if(!$teacher) {
// Not yet submitted
if(!$submission) {
if($this->isopen()) {
$this->print_progress_box('blueProgressBox','1',get_string('submit','peerreview'),get_string('submitbelow','peerreview'));
}
else {
$this->print_progress_box('redProgressBox','1',get_string('submit','peerreview'),get_string('closedpastdue','peerreview'));
}
$this->print_progress_box('greyProgressBox','2',get_string('reviews','peerreview'),get_string('submitfirst','peerreview'));
$this->print_progress_box('greyProgressBox','3',get_string('feedback','peerreview'),get_string('notavailable','peerreview'));
}
// Submitted
else {
$this->print_progress_box('greenProgressBox','1',get_string('submit','peerreview'),get_string('submitted','peerreview'));
// Completing Reviews
if($numberOfReviewsCompleted<2) {
if($numberOfReviewsCompleted==1) {
$this->print_progress_box('blueProgressBox','2',get_string('reviews','peerreview'),get_string('reviewsonemore','peerreview'));
}
else {
if($numberOfReviewsAllocated==0) {
$this->print_progress_box('blueProgressBox','2',get_string('reviews','peerreview'),get_string('reviewsnotallocated','peerreview'));
}
else {
$this->print_progress_box('blueProgressBox','2',get_string('reviews','assignment_peerreview'),get_string('completereviewsbelow','assignment_peerreview'));
}
}
$this->print_progress_box('greyProgressBox','3',get_string('feedback','assignment_peerreview'),get_string('notavailable','assignment_peerreview'));
}
// Viewing feedback
else {
$this->print_progress_box('greenProgressBox','2',get_string('reviews','assignment_peerreview'),get_string('reviewscomplete','assignment_peerreview'));
if($submission->timemarked == 0) {
$this->print_progress_box('blueProgressBox','3',get_string('feedback','assignment_peerreview'),get_string('marknotassigned','assignment_peerreview'));
}
else {
$this->print_progress_box('greenProgressBox','3',get_string('feedback','assignment_peerreview'),get_string('markassigned','assignment_peerreview'));
}
}
}
}
$this->print_progress_box('end');
// Completing Reviews
if(!$teacher && $submission && $numberOfReviewsAllocated==2 && $numberOfReviewsCompleted<2) {
print_box_start();
// Allow review file to be downloaded
if($numberOfReviewsDownloaded == $numberOfReviewsCompleted) {
print_heading(get_string('reviewnumber','assignment_peerreview',$numberOfReviewsCompleted+1),"left");
if(isset($this->assignment->var3) && $this->assignment->var3==self::ONLINE_TEXT) {
print_heading(get_string('gettheonlinetext','assignment_peerreview'),"left",3);
echo '<a onclick="setTimeout(\'document.getElementById(\\\'continueButton\\\').disabled=false;\',3000);return openpopup(\'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?a='.$this->assignment->id.'&id='.$this->cm->id.'&sesskey='.sesskey().'&view=peerreview\', \'window'.($numberOfReviewsCompleted+1).'\', \'menubar=0,location=0,scrollbars,resizable,width=500,height=400\', 0);" target="window'.($numberOfReviewsCompleted+1).'" href="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?a='.$this->assignment->id.'&id='.$this->cm->id.'&view=peerreview">'.get_string('clicktoview','assignment_peerreview').'</a>';
print_heading(get_string('continuetoreview','assignment_peerreview'),"left",3);
}
else {
print_heading(get_string('getthedocument','assignment_peerreview'),"left",3);
require_once($CFG->libdir.'/filelib.php');
echo '<a onclick="setTimeout(\'document.getElementById(\\\'continueButton\\\').disabled=false;\',3000);return true;" href="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::DOWNLOAD_PEERREVIEW_FILE.'/'.self::FILE_PREFIX.($numberOfReviewsCompleted+1).'.'.$this->assignment->fileextension.'?a='.$this->assignment->id.'&id='.$this->cm->id.'&sesskey='.sesskey().'&forcedownload=1"><img class="icon" src="'.$CFG->pixpath.'/f/'.mimeinfo('icon', 'blah.'.$this->assignment->fileextension).'" alt="'.get_string('clicktodownload','assignment_peerreview').'" />'.get_string('clicktodownload','assignment_peerreview').'</a>';
print_heading(get_string('continuetoreviewdocument','assignment_peerreview'),"left",3);
}
echo '<noscript>';
echo '<a href="view.php?id='.$this->cm->id.'">'.get_string('continue','assignment_peerreview').'</a>';
echo '</noscript>';
echo '<script>';
echo 'document.write(\'<input type="button" disabled id="continueButton" onclick="document.location=\\\'view.php?id='.$this->cm->id.'\\\'" value="'.get_string('continue','assignment_peerreview').'" />\');';
echo '</script>';
echo '<br />';
// Show the assignment instructions but hidden
echo $OUTPUT->spacer(array('height'=>30, 'width'=>30));
echo '<p id="showDescription"><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'block\';document.getElementById(\'showDescription\').style.display=\'none\';">'.get_string('showdescription','assignment_peerreview').'</a></p>';
echo '<div id="hiddenDescription" style="display:none;">';
echo '<p><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'none\';document.getElementById(\'showDescription\').style.display=\'block\';">'.get_string('hidedescription','assignment_peerreview').'</a></p>';
$this->view_intro();
echo '</div>';
}
// Reviewing
else {
// Save review
if($comment = clean_param(htmlspecialchars(optional_param('comment',NULL,PARAM_RAW)),PARAM_CLEAN)) {
print_heading(get_string('reviewnumber','assignment_peerreview',$numberOfReviewsCompleted+1));
notify(get_string('savingreview','assignment_peerreview'),'notifysuccess');
for($i=0; $i<$numberOfCriteria; $i++) {
$criterionToSave = new Object;
$criterionToSave->review = $reviewsAllocated[$numberOfReviewsCompleted]->id;
$criterionToSave->criterion = $i;
$criterionToSave->checked = optional_param('criterion'.$i,0,PARAM_BOOL);
insert_record('assignment_review_criterion',$criterionToSave);
}
$reviewToUpdate = get_record('assignment_review','id',$reviewsAllocated[$numberOfReviewsCompleted]->id);
$reviewToUpdate->reviewcomment = $comment;
$reviewToUpdate->complete = 1;
$reviewToUpdate->timecompleted = time();
$reviewToUpdate->timemodified = $reviewToUpdate->timecompleted;
update_record('assignment_review',$reviewToUpdate);
// Send an email to student
$subject = get_string('peerreviewreceivedsubject','assignment_peerreview');
$linkToReview = $CFG->wwwroot.'/mod/assignment/view.php?id='.$this->cm->id;
$message = get_string('peerreviewreceivedmessage','assignment_peerreview')."\n\n".get_string('assignmentname','assignment').': '.$this->assignment->name."\n".get_string('course').': '.$this->course->fullname."\n\n";
$messageText = $message.$linkToReview;
$messageHTML = nl2br($message).'<a href="'.$linkToReview.'" target="_blank">'.get_string('peerreviewreceivedlinktext','assignment_peerreview').'</a>';
$this->email_from_teacher($this->course->id, $reviewToUpdate->reviewee, $subject, $messageText, $messageHTML);
redirect('view.php?id='.$this->cm->id, get_string('reviewsaved','assignment_peerreview'),1);
}
// Show review form
else if($numberOfCriteria>0) {
echo '<div style="position:relative;">';
print_heading(get_string('reviewnumber','assignment_peerreview',$numberOfReviewsCompleted+1),'left');
echo '<div style="text-align:right;position:absolute;top:0;right:0">';
if(isset($this->assignment->var3) && $this->assignment->var3==self::ONLINE_TEXT) {
echo '<a onclick="setTimeout(\'document.getElementById(\\\'continueButton\\\').disabled=false;\',3000);return openpopup(\'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?a='.$this->assignment->id.'&id='.$this->cm->id.'&sesskey='.sesskey().'&view=peerreview\', \'window'.($numberOfReviewsCompleted+1).'\', \'menubar=0,location=0,scrollbars,resizable,width=500,height=400\', 0);" target="window'.($numberOfReviewsCompleted+1).'" href="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?a='.$this->assignment->id.'&id='.$this->cm->id.'&view=peerreview">'.get_string('lostonlinetext','assignment_peerreview').'</a>';
}
else {
require_once($CFG->libdir.'/filelib.php');
echo '<a onclick="setTimeout(\'document.getElementById(\\\'continueButton\\\').disabled=false;\',3000);return true;" href="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::DOWNLOAD_PEERREVIEW_FILE.'/'.self::FILE_PREFIX.($numberOfReviewsCompleted+1).'.'.$this->assignment->fileextension.'?a='.$this->assignment->id.'&id='.$this->cm->id.'"><img class="icon" src="'.$CFG->pixpath.'/f/'.mimeinfo('icon', 'blah.'.$this->assignment->fileextension).'" alt="'.get_string('lostfile','assignment_peerreview').'" />'.get_string('lostfile','assignment_peerreview').'</a>';
}
echo '</div>';
echo '<p id="showDescription"><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'block\';document.getElementById(\'showDescription\').style.display=\'none\';">'.get_string('showdescription','assignment_peerreview').'</a></p>';
echo '<div id="hiddenDescription" style="display:none;">';
echo '<p><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'none\';document.getElementById(\'showDescription\').style.display=\'block\';">'.get_string('hidedescription','assignment_peerreview').'</a></p>';
$this->view_intro();
echo '</div>';
echo '<form action="view.php" method="post">';
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
echo '<p>'.get_string('criteriainstructions','assignment_peerreview').'</p>';
echo '<table style="width:99%;">';
$options = new object;
$options->para = false;
foreach($criteriaList as $i=>$criterion) {
echo '<tr'.($i%2==0?' class="evenCriteriaRow"':'').'><td class="criteriaCheckboxColumn"><input type="checkbox" name="criterion'.$criterion->ordernumber.'" id="criterion'.$criterion->ordernumber.'" /></td><td class="criteriaTextColumn"><label for="criterion'.$criterion->ordernumber.'">'.format_text(($criterion->textshownatreview!=''?$criterion->textshownatreview:$criterion->textshownwithinstructions),FORMAT_MOODLE,$options).'</label></td></tr>';
}
echo '</table>';
echo $OUTPUT->spacer(array('height'=>20, 'width'=>20));
echo '<p>'.get_string('commentinstructions','assignment_peerreview').'</p>';
echo '<textarea name="comment" id="comment" rows="5" style="width:99%;"></textarea>';
echo '<input type="submit" value="'.get_string('savereview','assignment_peerreview').'" onclick="if(document.getElementById(\'comment\').value==\'\'){alert(\''.get_string('nocommentalert','assignment_peerreview').'\');document.getElementById(\'comment\').focus();return false;}">';
echo '</form>';
echo '</div>';
}
else {
notify(get_string('nocriteriaset','assignment_peerreview'));
}
}
print_box_end();
}
// For early submitters waiting for reviews to be allocated
else if(!$teacher && $submission && $numberOfReviewsAllocated==0) {
print_box_start();
notify(get_string("poolnotlargeenough", "assignment_peerreview"),'notifysuccess','left');
print_heading(get_string('yoursubmission','assignment_peerreview'),"left",2);
echo '<table cellpadding="3">';
if(isset($this->assignment->var3) && $this->assignment->var3==self::ONLINE_TEXT) {
echo '<tr><td><strong>'.get_string('submission','assignment_peerreview').': </strong></td><td>';
link_to_popup_window($CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?id='.$this->cm->id.'&a='.$this->assignment->id.'&sesskey='.sesskey().'&view=selfview');
echo '</td></tr>';
}
else {
require_once($CFG->libdir.'/filelib.php');
$filearea = $this->file_area_name($USER->id);
$files = get_directory_list($CFG->dataroot.'/'.$filearea, '', false);
echo '<tr><td><strong>'.get_string('submittedfile','assignment_peerreview').': </strong></td><td><a href="'.get_file_url($filearea.'/'.$files[0], array('forcedownload'=>1)).'" ><img src="'.$CFG->pixpath.'/f/'.mimeinfo('icon', $files[0]).'" class="icon" alt="icon" />'.$files[0].'</a></td></tr>';
}
echo '<tr><td><strong>'.get_string('submittedtime','assignment_peerreview').': </strong></td><td>'.userdate($submission->timecreated,get_string('strftimedaydatetime')).'</td></tr>';
echo '</table>';
// Show the assignment instructions but hidden
echo '<p id="showDescription"><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'block\';document.getElementById(\'showDescription\').style.display=\'none\';">'.get_string('showdescription','assignment_peerreview').'</a></p>';
echo '<div id="hiddenDescription" style="display:none;">';
echo '<p><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'none\';document.getElementById(\'showDescription\').style.display=\'block\';">'.get_string('hidedescription','assignment_peerreview').'</a></p>';
$this->view_intro();
echo '</div>';
print_box_end();
}
// Feedback on submission and reviews of student
else if(!$teacher && $submission && $numberOfReviewsCompleted==2) {
print_box_start();
// Find the reviews for this student
$reviews = $this->get_reviews_of_student($USER->id);
$numberOfReviewsOfThisStudent = 0;
if(is_array($reviews)) {
$numberOfReviewsOfThisStudent = count($reviews);
}
$status = $this->get_status($reviews,$numberOfCriteria);
// Table at top of page
echo '<table cellpadding="0" style="width:99%;"><tr><td style="width:50%;vertical-align:top;">';
// Table about student submission
print_heading(get_string('yoursubmission','assignment_peerreview'),"left",1);
echo '<table cellpadding="3">';
echo '<tr><td><strong>'.get_string('grade','assignment_peerreview').': </strong></td><td>'.($submission->timemarked==0?get_string('notavailable','assignment_peerreview'):$this->display_grade($submission->grade)).'</td></tr>';
echo '<tr><td><strong>'.get_string('status').': </strong></td><td>';
switch($status) {
case self::FLAGGED:
case self::CONFLICTING:
case self::FLAGGEDANDCONFLICTING:
echo get_string('waitingforteacher','assignment_peerreview',$this->course->teacher); break;
case self::LESSTHANTWOREVIEWS: echo get_string('waitingforpeers','assignment_peerreview'); break;
case self::CONCENSUS: echo get_string('reviewconcensus','assignment_peerreview'); break;
case self::OVERRIDDEN: echo get_string('reviewsoverridden','assignment_peerreview',$this->course->teacher); break;
}
echo '</td></tr>';
if(isset($this->assignment->var3) && $this->assignment->var3==self::ONLINE_TEXT) {
echo '<tr><td><strong>'.get_string('submission','assignment_peerreview').': </strong></td><td>';
link_to_popup_window($CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?id='.$this->cm->id.'&a='.$this->assignment->id.'&sesskey='.sesskey().'&view=selfview');
echo '</td></tr>';
}
else {
require_once($CFG->libdir.'/filelib.php');
$filearea = $this->file_area_name($USER->id);
$files = get_directory_list($CFG->dataroot.'/'.$filearea, '', false);
echo '<tr><td><strong>'.get_string('submittedfile','assignment_peerreview').': </strong></td><td><a href="'.get_file_url($filearea.'/'.$files[0], array('forcedownload'=>1)).'" ><img src="'.$CFG->pixpath.'/f/'.mimeinfo('icon', $files[0]).'" class="icon" alt="icon" />'.$files[0].'</a></td></tr>';
}
echo '<tr><td><strong>'.get_string('submittedtime','assignment_peerreview').': </strong></td><td>'.userdate($submission->timecreated,get_string('strftimedaydatetime')).'</td></tr>';
echo '</table>';
echo '</td><td style="vertical-align:top;">';
// Gather stats about student reviewing
$reviewStats = $this->get_review_statistics();
$reviewsByThisStudent = get_records_select('assignment_review','assignment=\''.$this->assignment->id.'\' AND reviewer=\''.$submission->userid.'\' AND complete=\'1\'');
$numberOfReviewsByThisStudent = is_array($reviewsByThisStudent)?count($reviewsByThisStudent):0;
$timeTakenReviewing = 0;
$commentLength = 0;
$criterionMatchesWithInstructor = 0;
$comparableReviews = 0;
$flags = 0;
foreach($reviewsByThisStudent as $id=>$review) {
$timeTakenReviewing += $review->timecompleted - $review->timedownloaded;
$commentLength += strlen($review->reviewcomment);
$teacherReviews = get_records_select('assignment_review','assignment=\''.$this->assignment->id.'\' AND reviewee=\''.$review->reviewee.'\' AND teacherreview=\'1\' AND complete=\'1\'','timecompleted DESC','*',0,1);
if(is_array($teacherReviews) && count($teacherReviews)>0) {
$comparableReviews++;
$teacherReviews = array_values($teacherReviews);
$teacherCriteria = array_values(get_records('assignment_review_criterion','review',$teacherReviews[0]->id,'criterion'));
$studentCriteria = array_values(get_records('assignment_review_criterion','review',$review->id,'criterion'));
for($i=0; $i<$numberOfCriteria; $i++) {
if($teacherCriteria[$i]->checked == $studentCriteria[$i]->checked) {
$criterionMatchesWithInstructor++;
}
}
}
if($review->flagged==1) {
$flags++;
}
}
// Table about reviews by student
print_heading(get_string('yourreviewing','assignment_peerreview'),"left",1);
echo '<table cellpadding="1">';
echo '<tr><td><strong>'.get_string('completed','assignment_peerreview').': </strong></td><td><img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/tick.gif" style="vertical-align:middle;" /> '.$numberOfReviewsByThisStudent.' '.get_string('completedlabel','assignment_peerreview',$this->assignment->var1).'</td></tr>';
echo '<tr><td><strong>'.get_string('reviewtimetaken','assignment_peerreview').': </strong></td><td>';
// Time taken
if($reviewStats->numberOfReviews < self::REVIEW_FEEDBACK_MIN) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/questionMark.gif" style="vertical-align:middle;" /> ';
print_string('notenoughreviewstocompare','assignment_peerreview');
}
else if ($timeTakenReviewing/2 < self::MINIMAL_REVIEW_TIME || $timeTakenReviewing/2 < $reviewStats->reviewTimeOutlierLowerBoundary) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
print_string('shorterthanmost','assignment_peerreview');
}
else if ($timeTakenReviewing/2 > $reviewStats->reviewTimeOutlierUpperBoundary) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
print_string('longerthanmost','assignment_peerreview');
}
else {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/tick.gif" style="vertical-align:middle;" /> ';
print_string('good','assignment_peerreview');
}
echo '</td></tr>';
// Comments made
echo '<tr><td><strong>'.get_string('reviewcomments','assignment_peerreview').': </strong></td><td>';
if($reviewStats->numberOfReviews < self::REVIEW_FEEDBACK_MIN) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/questionMark.gif" style="vertical-align:middle;" /> ';
print_string('notenoughreviewstocompare','assignment_peerreview');
}
else if ($commentLength/2 < self::MINIMAL_REVIEW_COMMENT_LENGTH || $commentLength/2 < $reviewStats->commentLengthOutlierLowerBoundary) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
print_string('shorterthanmost','assignment_peerreview');
}
else if ($commentLength/2 > $reviewStats->commentLengthOutlierUpperBoundary) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
print_string('longerthanmost','assignment_peerreview');
}
else {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/tick.gif" style="vertical-align:middle;" /> ';
print_string('goodlength','assignment_peerreview');
}
echo '</td></tr>';
// Accuracy
echo '<tr><td><strong>'.get_string('reviewaccuracy','assignment_peerreview').': </strong></td><td>';
if($comparableReviews < 1) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/questionMark.gif" style="vertical-align:middle;" /> ';
print_string('notenoughmoderationstocompare','assignment_peerreview');
}
else {
if ($criterionMatchesWithInstructor/($comparableReviews*$numberOfCriteria) < self::ACCURACY_REQUIRED) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
print_string('poor','assignment_peerreview');
}
else {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/tick.gif" style="vertical-align:middle;" /> ';
print_string('good','assignment_peerreview');
}
echo ' ('.(int)($criterionMatchesWithInstructor/($comparableReviews*$numberOfCriteria)*100).'%)';
}
echo '</td></tr>';
echo '<tr><td><strong>'.get_string('flags','assignment_peerreview').': </strong></td><td>';
if ($flags>=1) {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/alert.gif" style="vertical-align:middle;" /> ';
}
else {
echo '<img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/tick.gif" style="vertical-align:middle;" /> ';
}
echo get_string('flags'.$flags,'assignment_peerreview').'</td></tr>';
echo '</table>';
echo '</td></tr></table>';
echo '<p id="showDescription"><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'block\';document.getElementById(\'showDescription\').style.display=\'none\';">'.get_string('showdescription','assignment_peerreview').'</a></p>';
echo '<div id="hiddenDescription" style="display:none;">';
echo '<p><a href="#null" onclick="document.getElementById(\'hiddenDescription\').style.display=\'none\';document.getElementById(\'showDescription\').style.display=\'block\';">'.get_string('hidedescription','assignment_peerreview').'</a></p>';
$this->view_intro();
echo '</div>';
// If reviews are available, show to student
if($reviews) {
print_heading(get_string('reviewsofyoursubmission','assignment_peerreview'),"left",1);
echo '<table width="99%" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;">';
for($i=0; $i<$numberOfCriteria; $i++) {
echo '<tr class="criteriaDisplayRow">';
for($j=0; $j<$numberOfReviewsOfThisStudent; $j++) {
echo '<td class="criteriaCheckboxColumn" style="background:'.$this->REVIEW_COLOURS[$j%$this->NUMBER_OF_COLOURS].'"><input type="checkbox" disabled'.($reviews[$j]->{'checked'.$i}==1?' checked':'').' /></td>';
}
$options = new object;
$options->para = false;
echo '<td class="criteriaDisplayColumn">'.format_text(($criteriaList[$i]->textshownatreview!=''?$criteriaList[$i]->textshownatreview:$criteriaList[$i]->textshownwithinstructions),FORMAT_MOODLE,$options).'</td>';
echo '</tr>';
}
$studentCount = 1;
for($i=0; $i<$numberOfReviewsOfThisStudent; $i++) {
echo '<tr>';
for($j=0; $j<$numberOfReviewsOfThisStudent; $j++) {
echo '<td class="criteriaCheckboxColumn" style="background:'.($j>$numberOfReviewsOfThisStudent-$i-1?$this->REVIEW_COLOURS[($numberOfReviewsOfThisStudent-$i-1)%$this->NUMBER_OF_COLOURS]:$this->REVIEW_COLOURS[$j%$this->NUMBER_OF_COLOURS]).';"> </td>';
}
echo '<td class="reviewCommentRow" style="background:'.$this->REVIEW_COLOURS[($numberOfReviewsOfThisStudent-$i-1)%$this->NUMBER_OF_COLOURS].';">';
echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
echo '<tr class="reviewDetailsRow">';
echo '<td><em>'.get_string('conductedby','assignment_peerreview').': '.($reviews[$numberOfReviewsOfThisStudent-$i-1]->teacherreview==1?$reviews[$numberOfReviewsOfThisStudent-$i-1]->firstname.' '.$reviews[$numberOfReviewsOfThisStudent-$i-1]->lastname.' ('.$this->course->teacher.')':$this->course->student.' '.$studentCount++).'</em></td>';
echo '<td class="reviewDateColumn"><em>'.userdate($reviews[$numberOfReviewsOfThisStudent-$i-1]->timemodified,get_string('strftimedatetime')).'</em></td>';
echo '</tr>';
echo '<tr><td colspan="2"><div class="commentTextBox" style="background:'.$this->REVIEW_COMMENT_COLOURS[($numberOfReviewsOfThisStudent-$i-1)%count($this->REVIEW_COMMENT_COLOURS)].';">'.format_string(stripslashes($reviews[$numberOfReviewsOfThisStudent-$i-1]->reviewcomment)).'</div></td></tr>';
if($reviews[$numberOfReviewsOfThisStudent-$i-1]->teacherreview!=1) {
echo '<tr class="reviewDetailsRow"><td colspan="2"><em>';
echo $reviews[$numberOfReviewsOfThisStudent-$i-1]->flagged==1?get_string('flagprompt1','assignment_peerreview',$this->course->teacher).' ':get_string('flagprompt2','assignment_peerreview').' ';
$flagToggleURL = 'type/peerreview/'.self::TOGGLE_FLAG_FILE.'?id='.$this->cm->id.'&a='.$this->assignment->id.'&r='.$reviews[$numberOfReviewsOfThisStudent-$i-1]->review.'&sesskey='.sesskey();
echo '<a href="'.$flagToggleURL.'" id="flag'.($numberOfReviewsOfThisStudent-$i-1).'">';
echo $reviews[$numberOfReviewsOfThisStudent-$i-1]->flagged==1?get_string('flaglink1','assignment_peerreview').' <img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/flagRed.gif">':get_string('flaglink2','assignment_peerreview').' <img src="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/images/flagGreen.gif">';
echo '</a>';
echo '</em></td></tr>';
}
echo '</table>';
echo '</td>';
echo '</tr>';
// Record that the review has been viewed by the student
if($reviews[$numberOfReviewsOfThisStudent-$i-1]->timefirstviewedbyreviewee==0) {
set_field('assignment_review', 'timefirstviewedbyreviewee', time(), 'id', $reviews[$numberOfReviewsOfThisStudent-$i-1]->review);
}
set_field('assignment_review', 'timelastviewedbyreviewee', time(), 'id', $reviews[$numberOfReviewsOfThisStudent-$i-1]->review);
set_field('assignment_review', 'timesviewedbyreviewee', $reviews[$numberOfReviewsOfThisStudent-$i-1]->timesviewedbyreviewee+1, 'id', $reviews[$numberOfReviewsOfThisStudent-$i-1]->review);
}
echo '</table>';
}
else {
echo '<p>'.get_string('noreviews','assignment_peerreview');
}
print_box_end();
}
// First page with description and criteria
else {
// Show description
$this->view_intro();
// Show criteria
print_box_start();
echo '<a name="criteria"></a>';
print_heading(get_string('criteria','assignment_peerreview'),'left');
if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE,$this->cm->id))) {
echo '<p><a href="type/peerreview/'.self::CRITERIA_FILE.'?id='.$this->cm->id.'&a='.$this->assignment->id.'">'.get_string('setcriteria', 'assignment_peerreview').'</a></p>';
print_heading(get_string('criteriabeforesubmission','assignment_peerreview'),'left',3);
}
if($numberOfCriteria>0) {
echo '<table style="width:99%;">';
$options = new object;
$options->para = false;
foreach($criteriaList as $i=>$criterion) {
echo '<tr '.($i%2==0?'class="evenCriteriaRow"':'').'><td class="criteriaCheckboxColumn"><input type="checkbox" checked disabled /></td><td class="criteriaTextColumn">'.format_text($criterion->textshownwithinstructions,FORMAT_MOODLE,$options).'</td></tr>';
}
echo '</table>';
if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE,$this->cm->id))) {
print_heading(get_string('criteriaaftersubmission','assignment_peerreview'),'left',3);
echo '<table style="width:99%;">';
foreach($criteriaList as $i=>$criterion) {
echo '<tr '.($i%2==0?'class="evenCriteriaRow"':'').'><td class="criteriaCheckboxColumn"><input type="checkbox" checked disabled /></td><td class="criteriaTextColumn">'.format_text(($criteriaList[$i]->textshownatreview!=''?$criteriaList[$i]->textshownatreview:$criteriaList[$i]->textshownwithinstructions),FORMAT_MOODLE,$options).'</td></tr>';
}
echo '</table>';
}
}
else {
notify(get_string('nocriteriaset','assignment_peerreview'));
}
print_box_end();
$this->view_dates();
// With peer review teachers can grade but not submit (not here)
if (has_capability('mod/assignment:submit', $context) && !$teacher && $this->isopen() && !$submission) {
$this->view_upload_form();
}
else if(!$this->isopen()) {
print_string("notopen","assignment_peerreview");
}
}
$this->view_footer();
}
//--------------------------------------------------------------------------
// Shows the assignment description
function view_intro() {
$formatoptions = new stdClass;
$formatoptions->noclean = true;
print_box_start();
echo format_text($this->assignment->description, $this->assignment->format, $formatoptions);
print_box_end();
}
//--------------------------------------------------------------------------
// After marking in a pop-up window, this javascript updates the submission listing
function update_main_listing($submission) {
global $SESSION, $CFG;
$perpage = get_user_preferences('assignment_perpage', 10);
$moderationtarget = get_user_preferences('assignment_moderationtarget', 0);
$output = '';
/// Run some Javascript to try and update the parent page
$output .= '<script type="text/javascript">'."\n<!--\n";
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['moderations'])) {
$moderationCountSQL = 'SELECT count(r.id) FROM '.$CFG->prefix.'assignment a, '.$CFG->prefix.'assignment_review r WHERE a.course='.$this->course->id.' AND a.id=r.assignment AND r.teacherreview=1 AND r.reviewee=\''.$submission->userid.'\'';
$moderationCount = count_records_sql($moderationCountSQL);
$moderations = ($moderationCount<$moderationtarget)?'<span class="errorStatus">'.$moderationCount.'</span>':$moderationCount;
$output .= 'if(opener.document.getElementById(\'mo'.$submission->userid.'\')) {'."\n";
$output .= ' opener.document.getElementById(\'mo'.$submission->userid.'\').innerHTML=\''.$moderations."';\n";
$output .= "}\n";
}
$reviewsOfThisStudent = $this->get_reviews_of_student($submission->userid);
$criteriaList = get_records_list('assignment_criteria','assignment',$this->assignment->id,'ordernumber');
$numberOfCriteria = 0;
if(is_array($criteriaList)) {
$criteriaList = array_values($criteriaList);
$numberOfCriteria = count($criteriaList);
}
$statusCode = $this->get_status($reviewsOfThisStudent,$numberOfCriteria);
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['status'])) {
$output .= 'if(opener.document.getElementById(\'st'.$submission->userid.'\')) {'."\n";
$output .= ' opener.document.getElementById(\'st'.$submission->userid.'\').innerHTML=\''.addslashes($this->print_status($statusCode,true))."';\n";
$output .= "}\n";
}
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['seedoreviews'])) {
$output .= 'if(opener.document.getElementById(\'seOutline'.$submission->userid.'\')) {'."\n";
$output .= ' opener.document.getElementById(\'seOutline'.$submission->userid.'\').setAttribute(\'class\',\'s'.($statusCode<=3?'0':'1')."');\n";
$output .= "}\n";
}
$numberOfReviewsByThisStudent = count_records('assignment_review','assignment',$this->assignment->id,'reviewer',$submission->userid,'complete','1');
$suggestedMarkToDisplay = $this->get_marks($reviewsOfThisStudent,$criteriaList,$numberOfReviewsByThisStudent,$this->assignment->var1);
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['suggestedmark'])) {
$output .= 'if(opener.document.getElementById(\'gvalue'.$submission->userid.'\')) {'."\n";
$output .= ' opener.document.getElementById(\'gvalue'.$submission->userid.'\').value=\''.$suggestedMarkToDisplay."';\n";
$output .= "}\n";
}
$output .= "\n-->\n</script>";
return $output;
}
//--------------------------------------------------------------------------
// Directs calls from submissions.php to single pop-up window or submissions list
function submissions($mode) {
global $CFG, $USER;
switch ($mode) {
case 'grade': // We are in a popup window grading
if ($submission = $this->process_feedback()) {
//IE needs proper header with encoding
print_header(get_string('feedback', 'assignment').':'.format_string($this->assignment->name));
print_heading(get_string('changessaved'));
print $this->update_main_listing($submission);
}
close_window();
break;
case 'single': // We are in a popup window displaying submission
$this->display_submission();
break;
case 'all': // Main window, display everything
$this->display_submissions();
break;
case 'next':
/// We are currently in pop up, but we want to skip to next one without saving.
/// This turns out to be similar to a single case
/// The URL used is for the next submission.
$this->display_submission();
break;
case 'saveandnext':
///We are in pop up. save the current one and go to the next one.
//first we save the current changes
if ($submission = $this->process_feedback()) {
$extra_javascript = $this->update_main_listing($submission);
}
//then we display the next submission
$this->display_submission($extra_javascript);
break;
default:
echo "something seriously is wrong!!";
break;
}
}
//--------------------------------------------------------------------------
// Outputs the list of submissions with various details
function display_submissions($message='') {
global $CFG, $db, $USER;
require_once($CFG->libdir.'/gradelib.php');
$CFG->stylesheets[] = $CFG->wwwroot . '/mod/assignment/type/peerreview/'.self::STYLES_FILE;
// Update preferences
if (isset($_POST['updatepref'])){
$perpage = optional_param('perpage', 20, PARAM_INT);
$perpage = ($perpage <= 0) ? 20 : $perpage ;
set_user_preference('assignment_perpage', $perpage);
$moderationtarget = optional_param('moderationtarget', 0, PARAM_INT);
$moderationtarget = ($moderationtarget <= 0) ? 0 : $moderationtarget ;
set_user_preference('assignment_moderationtarget', $moderationtarget);
}
// Get preferences
$perpage = get_user_preferences('assignment_perpage', 10);
$moderationtarget = get_user_preferences('assignment_moderationtarget', 0);
// Some shortcuts to make the code read better
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
$course = $this->course;
$assignment = $this->assignment;
$cm = $this->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$page = optional_param('page', 0, PARAM_INT);
$reviewStats = $this->get_review_statistics();
// Log this view
add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id);
// Print header and navigation breadcrumbs
$navigation = build_navigation($this->strsubmissions, $this->cm);
print_header_simple(format_string($this->assignment->name,true), "", $navigation,
'', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
$this->print_peerreview_tabs('submissions');
// Print optional message
if (!empty($message)) {
echo $message; // display messages here if any
}
// Check to see if groups are being used in this assignment
// find out current groups mode
// $groupmode = groups_get_activity_groupmode($cm);
// $currentgroup = groups_get_activity_group($cm, true);
// groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/assignment/submissions.php?id=' . $cm->id);
// Help on review process
echo '<div style="text-align:center;margin:0 0 10px 0;">';
helpbutton('reviewallocation', get_string('reviewallocation','assignment_peerreview'), 'assignment/type/peerreview', true,true);
echo '</div>';
// Get all ppl that are allowed to submit assignments
// if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id')) {
$users = array_keys($users);
}
// Filter out teachers
if ($users && $teachers = get_users_by_capability($context, 'mod/assignment:grade', 'u.id')) {
$users = array_diff($users, array_keys($teachers));
}
// Warn if class is too small
if(count($users) < 5) {
notify(get_string('numberofstudentswarning','assignment_peerreview'));
}
// if groupmembersonly used, remove users who are not in any group
// if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
// if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
// $users = array_intersect($users, array_keys($groupingusers));
// }
// }
// Create the table to be shown
require_once($CFG->libdir.'/tablelib.php');
$table = new flexible_table('mod-assignment-peerreview-submissions');
$tablecolumns = array('picture', 'fullname', 'submitted', 'reviews', 'moderations', 'status', 'seedoreviews', 'suggestedmark','finalgrade');
$table->define_columns($tablecolumns);
$tableheaders = array('',
get_string('fullname'),
get_string('submission','assignment_peerreview').helpbutton('submission',get_string('submission','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('reviewsbystudent','assignment_peerreview').helpbutton('reviewsbystudent',get_string('reviewsbystudent','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('moderationstitle','assignment_peerreview').helpbutton('moderationtarget',get_string('moderationtarget','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('status').helpbutton('status',get_string('status','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('seedoreviews','assignment_peerreview').helpbutton('seedoreviews',get_string('seedoreviews','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('suggestedgrade','assignment_peerreview').helpbutton('suggestedgrade',get_string('suggestedgrade','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true),
get_string('finalgrade', 'assignment_peerreview').helpbutton('finalgrade',get_string('finalgrade','assignment_peerreview'),'assignment/type/peerreview/',true,false,'',true));
$table->define_headers($tableheaders);
// $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&currentgroup='.$currentgroup);
$table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id);
// $table->sortable(true, 'submitted');
$table->sortable(true);
$table->collapsible(true);
// $table->initialbars(true);
$table->initialbars(false);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'fullname');
$table->column_class('submitted', 'submitted');
$table->column_class('reviews', 'reviews');
$table->column_class('moderations', 'moderations');
$table->column_class('status', 'status');
$table->column_class('seedoreviews', 'seedoreviews');
$table->column_class('suggestedmark', 'suggestedmark');
$table->column_class('finalgrade', 'finalgrade');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'submissions');
$table->set_attribute('width', '99%');
$table->set_attribute('align', 'center');
$table->column_style('submitted','text-align','left');
$table->column_style('finalgrade','text-align','center');
$table->no_sorting('picture');
$table->no_sorting('reviews');
$table->no_sorting('moderations');
$table->no_sorting('status');
$table->no_sorting('seedoreviews');
$table->no_sorting('suggestedmark');
$table->no_sorting('finalgrade');
$table->setup();
if (empty($users)) {
print_heading(get_string('nosubmitusers','assignment'));
return true;
}
// Construct the SQL
if ($where = $table->get_sql_where()) {
$where .= ' AND ';
}
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
s.id AS submissionid, s.grade,
s.timecreated as submitted, s.timemarked ';
$sql = 'FROM '.$CFG->prefix.'user u '.
'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id=s.userid AND s.assignment='.$this->assignment->id.' '.
'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';
if ($sort = $table->get_sql_sort()) {
$sort = ' ORDER BY '.$sort;
$sort = str_replace('submitted', 'COALESCE(submitted,2147483647)', $sort);
}
else {
$sort = 'ORDER BY COALESCE(submitted,2147483647) ASC, submissionid ASC, u.lastname ASC';
}
$table->pagesize($perpage, count($users));
///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
$offset = $page * $perpage;
$strupdate = get_string('update');
$strgrade = get_string('grade');
$grademenu = make_grades_menu($this->assignment->grade);
// Get the criteria
$criteriaList = get_records_list('assignment_criteria','assignment',$this->assignment->id,'ordernumber');
$numberOfCriteria = 0;
if(is_array($criteriaList)) {
$criteriaList = array_values($criteriaList);
$numberOfCriteria = count($criteriaList);
}
if (($ausers = get_records_sql($select.$sql.$sort, $table->get_page_start(), $table->get_page_size())) !== false) {
// $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
foreach ($ausers as $auser) {
// $final_grade = $grading_info->items[0]->grades[$auser->id];
// Calculate user status
$auser->status = $auser->timemarked > 0;
$picture = print_user_picture($auser, $course->id, $auser->picture, false, true);
$studentName = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$auser->id.'&course='.$this->course->id.'">'.fullname($auser).'</a>';
// If submission has been made
if (!empty($auser->submissionid)) {
$filearea = $this->file_area_name($auser->id);
$fileLink = '';
if (isset($this->assignment->var3) && $this->assignment->var3==self::ONLINE_TEXT) {
$url = '/mod/assignment/type/peerreview/'.self::VIEW_ONLINE_TEXT.'?id='.$this->cm->id.'&a='.$this->assignment->id.'&userid='.$auser->id.'&sesskey='.sesskey().'&view=moderation';
$fileLink .= '<a href="'.$CFG->wwwroot.$url.'" target="_blank" onclick="return openpopup(\''.$url.'\',\'\',\'menubar=0,location=0,scrollbars,resizable,width=500,height=400\');" title="'.get_string('clicktoview','assignment_peerreview').'"><img src="'.$CFG->pixpath.'/f/html.gif" /></a>';
}
else {
$basedir = $this->file_area($auser->id);
if ($files = get_directory_list($basedir)) {
require_once($CFG->libdir.'/filelib.php');
foreach ($files as $key => $file) {
$icon = mimeinfo('icon', $file);
$ffurl = get_file_url("$filearea/$file", array('forcedownload'=>1));
$fileLink .= '<a href="'.$ffurl.'" title="'.get_string('clicktodownload','assignment_peerreview').'"><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" /></a>';
}
}
}
$submitted = '<div class="files" style="display:inline;">'.$fileLink.'</div><div style="display:inline;" id="tt'.$auser->id.'">'.userdate($auser->submitted,get_string('strftimeintable','assignment_peerreview')).'</div>';
$submitted .= ' <a href="'.$CFG->wwwroot.'/mod/assignment/type/peerreview/'.self::RESUBMIT_FILE.'?id='.$this->cm->id.'&a='.$this->assignment->id.'&userid='.$auser->id.'&sesskey='.sesskey().'">('.get_string('resubmitlabel','assignment_peerreview').')</a>';
// Reviews by student
$numberOfReviewsByThisStudent = 0;
if($reviewsByThisStudent = get_records_select('assignment_review','assignment=\''.$this->assignment->id.'\' AND reviewer=\''.$auser->id.'\' AND complete=\'1\'')) {
$numberOfReviewsByThisStudent = count($reviewsByThisStudent);
$reviewsByThisStudent = array_values($reviewsByThisStudent);
$reviews = '<div style="text-align:center;" id="re'.$auser->id.'">';
for($i=0; $i<$numberOfReviewsByThisStudent; $i++) {
$reviews .= '<span id="rev'.$reviewsByThisStudent[$i]->id.'" style="padding:5px 2px;">';
$popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id. '&userid='.$reviewsByThisStudent[$i]->reviewee.'&mode=single&offset=-1';
$buttonText = ''.($i+1);
$timeTakenReviewing = $reviewsByThisStudent[$i]->timecompleted - $reviewsByThisStudent[$i]->timedownloaded;
$commentLength = strlen($reviewsByThisStudent[$i]->reviewcomment);
if(
($timeTakenReviewing < self::MINIMAL_REVIEW_TIME || $timeTakenReviewing < $reviewStats->reviewTimeOutlierLowerBoundary) &&
($commentLength < self::MINIMAL_REVIEW_COMMENT_LENGTH || $commentLength < $reviewStats->commentLengthOutlierLowerBoundary)
) {
$buttonText .= ' ?';
}
$reviews .= element_to_popup_window ('button', $popup_url, 'grade'.$auser->id, $buttonText, 600, 780, $buttonText, 'none', true, 'user'.$auser->id.'rev'.$i);
$reviews .= '</span>';
// $reviews .= $i<$numberOfReviewsByThisStudent-1?', ':'';
}
$reviews .= '</div>';
$reviews .= '<script>';
for($i=0; $i<$numberOfReviewsByThisStudent; $i++) {
$reviews .= 'document.getElementById(\'user'.$auser->id.'rev'.$i.'\').setAttribute(\'onmouseover\',\'document.getElementById("se'.$reviewsByThisStudent[$i]->reviewee.'").style.background="#ff9999";\');';
$reviews .= 'document.getElementById(\'user'.$auser->id.'rev'.$i.'\').setAttribute(\'onmouseout\',\'document.getElementById("se'.$reviewsByThisStudent[$i]->reviewee.'").style.background="transparent";\');';
}
$reviews .= '</script>';
}
else {
$reviews = '<div id="re'.$auser->id.'"> </div>';
}