forked from uclmoodle/moodle-report_myfeedback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
6084 lines (5752 loc) · 317 KB
/
Copy pathlib.php
File metadata and controls
6084 lines (5752 loc) · 317 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/>.
/**
* My Feedback Report.
*
* @package report_myfeedback
* @author Jessica Gramp <j.gramp@ucl.ac.uk>
* @author Delvon Forrester <delvon@esparanza.co.uk>
* @credits Based on original work report_mygrades by David Bezemer <david.bezemer@uplearning.nl> which in turn is based on
* block_myfeedback by Karen Holland, Mei Jin, Jiajia Chen. Also uses SQL originating from Richard Havinga
* <richard.havinga@ulcc.ac.uk>. The code for using an external database is taken from Juan leyva's
* <http://www.twitter.com/jleyvadelgado> configurable reports block.
* The idea for this reporting tool originated with Dr Jason Davies <j.p.davies@ucl.ac.uk> and
* Prof John Mitchell <j.mitchell@ucl.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* This function extends the navigation with the My feedback report.
*
* @param global_navigation $navigation The navigation node to extend
*/
function report_myfeedback_extend_navigation(global_navigation $navigation) {
// TODO: Segun Babalola. Where does $course come from?
// TODO: Check that pix_icon is not deprecated.
$url = new moodle_url('/report/myfeedback/index.php', array('course' => $course->id));
$navigation->add(get_string('pluginname', 'report_myfeedback'), $url, null, null, null, new pix_icon('i/report', ''));
}
/**
* This function extends the My settings >> activity with the My feedback report.
*
* @param global_navigation $navigation The navigation node to extend
* @param stdClass $course The course object
* @param stdClass $user The user object
*/
function report_myfeedback_extend_navigation_user($navigation, $user, $course) {//backward compatibility to v2.8 and earlier versions
$context = context_user::instance($user->id, MUST_EXIST);
$url = new moodle_url('/report/myfeedback/index.php', array('userid' => $user->id));
$navigation->add(get_string('pluginname', 'report_myfeedback'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
/**
* This function extends the navigation with the My feedback report for users you have access to.
*
* @param global_navigation $navigation The navigation node to extend
* @param stdClass $user The user object
* @param stdClass $context The context
* @param stdClass $course The course object
* @param stdClass $coursecontext The context of the course
*/
function report_myfeedback_extend_navigation_user_settings($navigation, $user, $context, $course, $coursecontext) {
$url = new moodle_url('/report/myfeedback/index.php', array('userid' => $user->id));
$navigation->add(get_string('pluginname', 'report_myfeedback'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
/**
* This function extends the navigation in course admin >> reports with the My feedback report.
*
* @param global_navigation $navigation The navigation node to extend
* @param stdClass $course The course object
* @param stdClass $context The context of the course
*/
function report_myfeedback_extend_navigation_course($navigation, $course, $context) {
global $USER;
$url = has_capability('report/myfeedback:modtutor', $context) ? new moodle_url('/report/myfeedback/index.php', array('userid' => $USER->id, 'currenttab' => 'mymodules')) :
new moodle_url('/report/myfeedback/index.php', array('userid' => $USER->id));
$navigation->add(get_string('pluginname', 'report_myfeedback'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
/**
* This function extends the navigation with the My feedback report to the user's profile.
*
* @param core_user\output\myprofile\tree $tree, The node to add to
* @param stdClass $user The user object
* @param bool $iscurrentuser Whether the logged-in user is current user
* @param stdClass $course The course object
*/
function report_myfeedback_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {//for comaptibility with v2.9 and later
$url = new moodle_url('/report/myfeedback/index.php', array('userid' => $user->id));
if (!empty($course)) {
$url->param('course', $course->id);
}
$string = get_string('pluginname', 'report_myfeedback');
$node = new core_user\output\myprofile\node('reports', 'myfeedbackreport', $string, null, $url);
$tree->add_node($node);
return true;
}
class report_myfeedback {
/**
* Initialises the report and sets the title
*/
public function init() {
$this->title = get_string('my_feedback', 'report_myfeedback');
}
/**
* Sets up global $DB moodle_database instance
*
* @global stdClass $CFG The global configuration instance.
* @see config.php
* @see config-dist.php
* @global stdClass $DB The global moodle_database instance.
* @global stdClass $remotedb The global remote moodle_database instance.
* @return void|bool Returns true when finished setting up $DB or $remotedb. Returns void when $DB has already been set.
*/
function setup_ExternalDB($ext_db = null) {
global $CFG, $DB, $remotedb;
// Use a custom $remotedb (and not current system's $DB) if set - code sourced from configurable
// Reports plugin.
$remotedbhost = get_config('report_myfeedback', 'dbhost');
$remotedbname = get_config('report_myfeedback', 'dbname');
$remotedbuser = get_config('report_myfeedback', 'dbuser');
$remotedbpass = get_config('report_myfeedback', 'dbpass');
if ($ext_db && $ext_db != 'current') {
$remotedbhost = get_config('report_myfeedback', 'dbhostarchive');
$remotedbname = get_config('report_myfeedback', 'namingconvention') . $ext_db;
$remotedbuser = get_config('report_myfeedback', 'dbuserarchive');
$remotedbpass = get_config('report_myfeedback', 'dbpassarchive');
}
if (empty($remotedbhost) OR empty($remotedbname) OR empty($remotedbuser)) {
$remotedb = $DB;
setup_DB();
} else {
if (!isset($CFG->dblibrary)) {
$CFG->dblibrary = 'native';
// use new drivers instead of the old adodb driver names
switch ($CFG->dbtype) {
case 'postgres7' :
$CFG->dbtype = 'pgsql';
break;
case 'mssql_n':
$CFG->dbtype = 'mssql';
break;
case 'oci8po':
$CFG->dbtype = 'oci';
break;
case 'mysql' :
$CFG->dbtype = 'mysqli';
break;
}
}
if (!isset($CFG->dboptions)) {
$CFG->dboptions = array();
}
if (isset($CFG->dbpersist)) {
$CFG->dboptions['dbpersist'] = $CFG->dbpersist;
}
if (!$remotedb = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary)) {
throw new dml_exception('dbdriverproblem', "Unknown driver $CFG->dblibrary/$CFG->dbtype");
}
try {
$remotedb->connect($remotedbhost, $remotedbuser, $remotedbpass, $remotedbname, $CFG->prefix, $CFG->dboptions);
} catch (moodle_exception $e) {
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
$body = "Connection error: " . $CFG->wwwroot .
"\n\nInfo:" .
"\n\tError code: " . $e->errorcode .
"\n\tDebug info: " . $e->debuginfo .
"\n\tServer: " . $_SERVER['SERVER_NAME'] . " (" . $_SERVER['SERVER_ADDR'] . ")";
if (file_exists($CFG->dataroot . '/emailcount')) {
$fp = @fopen($CFG->dataroot . '/emailcount', 'r');
$content = @fread($fp, 24);
@fclose($fp);
if ((time() - (int) $content) > 600) {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, $body);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
} else {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, $body);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
}
// rethrow the exception
if ($CFG->debug != 0) {
throw $e;
} else {
echo get_string('archivedbnotexist', 'report_myfeedback');
}
}
$DB = $remotedb;
$CFG->dbfamily = $remotedb->get_dbfamily(); // TODO: BC only for now
return true;
}
return false;
}
/**
* Gets whether or not the module is installed and visible
*
* @param str $modname The name of the module
* @return bool true if the module exists and is not hidden in the site admin settings,
* otherwise false
*/
public function mod_is_available($modname) {
global $remotedb;
$installedplugins = core_plugin_manager::instance()->get_plugins_of_type('mod');
// Is the module installed?
if (array_key_exists($modname, $installedplugins)) {
// Is the module visible?
if ($remotedb->get_field('modules', 'visible', array('name' => $modname
))) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Checks whether or not an online pdf feedback annotated file
* or any feedback file has been generated
*
* @param str $iteminstance The assign id
* @param str $userid The user id
* @param str $gradeid The gradeid
* @return bool true if there's a pdf feedback annotated file
* or any feedback filed for the submission, otherwise false
*/
public function has_pdf_feedback_file($iteminstance, $userid, $gradeid) {
global $remotedb;
// Is there any online pdf annotation feedback or any feedback file?
if ($remotedb->get_record('assignfeedback_editpdf_annot', array('gradeid' => $gradeid), $fields = 'id', $strictness = IGNORE_MULTIPLE)) {
return true;
}
if ($remotedb->get_record('assignfeedback_editpdf_cmnt', array('gradeid' => $gradeid), $fields = 'id', $strictness = IGNORE_MULTIPLE)) {
return true;
}
$sql = "SELECT af.numfiles
FROM {assign_grades} ag
JOIN {assignfeedback_file} af on ag.id=af.grade
AND ag.id=? AND ag.userid=? AND af.assignment=?";
$params = array($gradeid, $userid, $iteminstance);
$feedbackfile = $remotedb->get_record_sql($sql, $params);
if ($feedbackfile) {
if ($feedbackfile->numfiles != 0) {
return true;
}
}
return false;
}
/**
* Checks whether or not there is any workshop feedback file either from peers or tutor
*
* @param int $userid The user id
* @param int $subid The workshop submission id
* @return boolean true if there is a feedback file and false if there ain't
*/
public function has_workshop_feedback_file($userid, $subid) {
global $remotedb;
// Is there any feedback file?
$sql = "SELECT DISTINCT max(wa.id) as id, wa.feedbackauthorattachment
FROM {workshop_assessments} wa
JOIN {workshop_submissions} ws ON wa.submissionid=ws.id
AND ws.authorid=? AND ws.id=? and ws.example = 0";
$params = array($userid, $subid);
$feedbackfile = $remotedb->get_record_sql($sql, $params);
if ($feedbackfile) {
if ($feedbackfile->feedbackauthorattachment != 0) {
return true;
}
}
return false;
}
/**
* Gets and returns any workshop feedback
*
* @global stdClass $remotedb The database object
* @global stdClass $CFG The global config
* @param int $userid The user id
* @param int $subid The workshop submission id
* @param int $assignid The workshop id
* @param int $cid The course id
* @param int $itemnumber The grade_item itemnumber
* @return string All the feedback information
*/
public function has_workshop_feedback($userid, $subid, $assignid, $cid, $itemnumber) {
global $remotedb, $CFG;
$feedback = '';
//Get the other feedback that comes when graded so will have a grade id otherwise it is not unique
$peer = "SELECT DISTINCT wg.id, wg.peercomment, wa.reviewerid, wa.feedbackreviewer, w.conclusion
FROM {workshop} w
JOIN {workshop_submissions} ws ON ws.workshopid=w.id AND w.course=? AND w.useexamples=0
JOIN {workshop_assessments} wa ON wa.submissionid=ws.id AND ws.authorid=?
AND ws.workshopid=? AND ws.example=0 AND wa.submissionid=?
LEFT JOIN {workshop_grades} wg ON wg.assessmentid=wa.id AND wa.submissionid=?";
$arr = array($cid, $userid, $assignid, $subid, $subid);
//TODO: fix this! If won't work here, use: if ($rs->valid()) {}
if ($assess = $remotedb->get_recordset_sql($peer, $arr)) {
if ($itemnumber == 1) {
foreach ($assess as $a) {
if ($a->feedbackreviewer && strlen($a->feedbackreviewer) > 0) {
$feedback = (strip_tags($a->feedbackreviewer) ? "<b>" . get_string('tutorfeedback', 'report_myfeedback') . "</b><br/>" . strip_tags($a->feedbackreviewer) : '');
}
}
$assess->close();
return $feedback;
}
}
if ($itemnumber != 1) {
//get the feedback from author as this does not necessarily mean they are graded
$auth = "SELECT DISTINCT wa.id, wa.feedbackauthor, wa.reviewerid
FROM {workshop} w
JOIN {workshop_submissions} ws ON ws.workshopid=w.id AND w.course=? AND w.useexamples=0
JOIN {workshop_assessments} wa ON wa.submissionid=ws.id AND ws.authorid=?
AND ws.workshopid=? AND ws.example=0 AND wa.submissionid=?";
$par = array($cid, $userid, $assignid, $subid);
$self = $pfeed = false;
if ($asse = $remotedb->get_records_sql($auth, $par)) {
foreach ($asse as $cub) {
if ($cub->feedbackauthor && $cub->reviewerid != $userid) {
$pfeed = true;
}
}
if ($pfeed) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= '<strong>' . get_string('peerfeedback', 'report_myfeedback') . '</strong>';
}
foreach ($asse as $as) {
if ($as->feedbackauthor && $as->reviewerid != $userid) {
$feedback .= (strip_tags($as->feedbackauthor) ? '<br/>' . strip_tags($as->feedbackauthor) : '');
}
}
foreach ($asse as $cub1) {
if ($cub1->feedbackauthor && $cub1->reviewerid == $userid) {
$self = true;
}
}
if ($self) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= '<strong>' . get_string('selfassessment', 'report_myfeedback') . '</strong>';
}
foreach ($asse as $as1) {
if ($as1->feedbackauthor && $as1->reviewerid == $userid) {
$feedback .= (strip_tags($as1->feedbackauthor) ? '<br/>' . strip_tags($as1->feedbackauthor) : '');
}
}
}
}
//get comments strategy type
$sql_c = "SELECT wg.id as gradeid, wa.reviewerid, a.description, peercomment
FROM {workshopform_accumulative} a
JOIN {workshop_grades} wg ON wg.dimensionid=a.id AND wg.strategy='comments'
JOIN {workshop_assessments} wa ON wg.assessmentid=wa.id AND wa.submissionid=?
JOIN {workshop_submissions} ws ON wa.submissionid=ws.id
AND ws.workshopid=? AND ws.example=0 AND ws.authorid = ?
ORDER BY wa.reviewerid";
$params_c = array($subid, $assignid, $userid);
$c = 0;
if ($commentscheck = $remotedb->get_records_sql($sql_c, $params_c)) {
foreach ($commentscheck as $com) {
if (strip_tags($com->description)) {
$c = 1;
}
}
if ($c) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= "<br/><strong>" . get_string('comments', 'report_myfeedback') . "</strong>";
}
foreach ($commentscheck as $ts) {
$feedback .= strip_tags($ts->description) ? "<br/><b>" . $ts->description : '';
$feedback .= strip_tags($ts->description) ? "<br/><strong>" . get_string('comment', 'report_myfeedback') . "</strong>: " . strip_tags($ts->peercomment) . "<br/>" : '';
}
}
//get accumulative strategy type
$sql_a = "SELECT wg.id as gradeid, wa.reviewerid, a.description, wg.grade as score, a.grade, peercomment
FROM {workshopform_accumulative} a
JOIN {workshop_grades} wg ON wg.dimensionid=a.id AND wg.strategy='accumulative'
JOIN {workshop_assessments} wa ON wg.assessmentid=wa.id AND wa.submissionid=?
JOIN {workshop_submissions} ws ON wa.submissionid=ws.id
AND ws.workshopid=? AND ws.example=0 AND ws.authorid = ?
ORDER BY wa.reviewerid";
$params_a = array($subid, $assignid, $userid);
$a = 0;
if ($accumulativecheck = $remotedb->get_records_sql($sql_a, $params_a)) {
foreach ($accumulativecheck as $acc) {
if (strip_tags($acc->description && $acc->score)) {
$a = 1;
}
}
if ($a) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= "<br/><b>" . get_string('accumulativetitle', 'report_myfeedback') . "</b>";
}
foreach ($accumulativecheck as $tiv) {
$feedback .= strip_tags($acc->description && $acc->score) ? "<br/><b>" . strip_tags($tiv->description) . "</b>: " . get_string('grade', 'report_myfeedback') . round($tiv->score) . "/" . round($tiv->grade) : '';
$feedback .= strip_tags($acc->description && $acc->score) ? "<br/><b>" . get_string('comment', 'report_myfeedback') . "</b>: " . strip_tags($tiv->peercomment) . "<br/>" : '';
}
}
//get the rubrics strategy type
$sql = "SELECT wg.id as gradeid, wa.reviewerid, r.description, l.definition, peercomment
FROM {workshopform_rubric} r
LEFT JOIN {workshopform_rubric_levels} l ON (l.dimensionid = r.id) AND r.workshopid=?
JOIN {workshop_grades} wg ON wg.dimensionid=r.id AND l.grade=wg.grade and wg.strategy='rubric'
JOIN {workshop_assessments} wa ON wg.assessmentid=wa.id AND wa.submissionid=?
JOIN {workshop_submissions} ws ON wa.submissionid=ws.id
AND ws.workshopid=? AND ws.example=0 AND ws.authorid = ?
ORDER BY wa.reviewerid";
$params = array($assignid, $subid, $assignid, $userid);
$r = 0;
if ($rubriccheck = $remotedb->get_records_sql($sql, $params)) {
foreach ($rubriccheck as $rub) {
if (strip_tags($rub->description && $rub->definition)) {
$r = 1;
}
}
if ($r) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= "<br/><span style=\"font-weight:bold;\"><img src=\"" .
$CFG->wwwroot . "/report/myfeedback/pix/rubric.png\">" . get_string('rubrictext', 'report_myfeedback') . "</span>";
}
foreach ($rubriccheck as $rec) {
$feedback .= strip_tags($rec->description && $rec->definition) ? "<br/><b>" . strip_tags($rec->description) . "</b>: " . strip_tags($rec->definition) : '';
$feedback .= strip_tags($rec->peercomment) ? "<br/><b>" . get_string('comment', 'report_myfeedback') . "</b>: " . strip_tags($rec->peercomment) . "<br/>" : '';
}
}
//get the numerrors strategy type
$sql_n = "SELECT wg.id as gradeid, wa.reviewerid, n.description, wg.grade, n.grade0, n.grade1, peercomment
FROM {workshopform_numerrors} n
JOIN {workshop_grades} wg ON wg.dimensionid=n.id AND wg.strategy='numerrors'
JOIN {workshop_assessments} wa ON wg.assessmentid=wa.id AND wa.submissionid=?
JOIN {workshop_submissions} ws ON wa.submissionid=ws.id
AND ws.workshopid=? AND ws.example=0 AND ws.authorid = ?
ORDER BY wa.reviewerid";
$params_n = array($subid, $assignid, $userid);
$n = 0;
if ($numerrorcheck = $remotedb->get_records_sql($sql_n, $params_n)) {
foreach ($numerrorcheck as $num) {
if ($num->gradeid) {
$n = 1;
}
}
if ($n) {
$feedback .= strip_tags($feedback) ? '<br/>' : '';
$feedback .= "<br/><b>" . get_string('numerrortitle', 'report_myfeedback') . "</b>";
}
foreach ($numerrorcheck as $err) {
$feedback .= $err->gradeid ? "<br/><b>" . strip_tags($err->description) . "</b>: " . ($err->grade < 1.0 ? strip_tags($err->grade0) : strip_tags($err->grade1)) : '';
$feedback .= $err->gradeid ? "<br/><b>" . get_string('comment', 'report_myfeedback') . "</b>: " . strip_tags($err->peercomment) . "<br/>" : '';
}
}
return $feedback;
}
/**
* Check whether the user has been granted an assignment extension
*
* @param int $userid The user id
* @param int $assignment The assignment id
* @return int Due date of the extension or false if no extension
*/
public function check_assign_extension($userid, $assignment) {
global $remotedb;
$sql = "SELECT max(extensionduedate) as extensionduedate
FROM {assign_user_flags}
WHERE userid=? AND assignment=?";
$params = array($userid, $assignment);
$extension = $remotedb->get_record_sql($sql, $params);
if ($extension) {
return $extension->extensionduedate;
}
return false;
}
/**
* Check if the user got an override to extend completion date/time
*
* @global stdClass $remotedb The database object
* @param int $assignid The quiz id
* @param int $userid The user id
* @return int Datetime of the override or false if no override
*/
public function check_quiz_extension($assignid, $userid) {
global $remotedb;
$sql = "SELECT max(timeclose) as timeclose
FROM {quiz_overrides}
WHERE quiz=? AND userid=?";
$params = array($assignid, $userid);
$override = $remotedb->get_record_sql($sql, $params);
if ($override) {
return $override->timeclose;
}
return false;
}
/**
* Check if user got an override to extend completion date/time
* as part of a group
*
* @global stdClass $remotedb The database object
* @param int $assignid The quiz id
* @param int $userid The user id
* @return int extension date or false if no extension
*/
public function check_quiz_group_extension($assignid, $userid) {
global $remotedb;
$sql = "SELECT max(qo.timeclose) as timeclose
FROM {quiz_overrides} qo
JOIN {groups_members} gm ON qo.groupid=gm.groupid
AND qo.quiz=? AND gm.userid=?";
$params = array($assignid, $userid);
$override = $remotedb->get_record_sql($sql, $params);
if ($override) {
return $override->timeclose;
}
return false;
}
/**
* Get the submitted date of the last attempt
*
* @global stdClass $remotedb The database object
* @param int $assignid The assignment id
* @param int $userid The user id
* @param int $grade The quiz grade of the user
* @param int $availablegrade The highest grade the user could get for that quiz
* @param int $sumgrades The amount of questions marked out of
* @return int The date of the attempt or false if not attempted.
*/
public function get_quiz_submissiondate($assignid, $userid, $grade, $availablegrade, $sumgrades) {
global $remotedb;
$a = $grade / $availablegrade * $sumgrades;
$sql = "SELECT id, timefinish, sumgrades
FROM {quiz_attempts}
WHERE quiz=? AND userid=?";
$params = array($assignid, $userid);
$attempts = $remotedb->get_records_sql($sql, $params);
if ($attempts) {
foreach ($attempts as $attempt) {
if ($a == $attempt->sumgrades) {
return $attempt->timefinish;
}
}
}
return false;
}
/**
* Get a user's quiz attempts for a particular quiz
*
* @param int $quizid The id of the quiz which comes from the gi.iteminstance
* @param int $userid The id of the user
* @param int $quizurlid The id of the quiz that can be used to access the quiz via the URL
* @param str $archivedomain_year The academic year eg (14-15)
* @param bool $archive Whether it's an archived academic year
* @param str $newwindowicon An icon image with tooltip showing that it opens in another window
* @param bool $reviewattempt whetehr the user can review the quiz attempt
* @param bool $sameuser Whether the logged-in user is the user quiz being referred to
* @return str Any comments left by a marker on a Turnitin Assignment via the Moodle Comments
* feature (not in Turnitin), each on a new line
*/
public function get_quiz_attempts_link($quizid, $userid, $quizurlid, $archivedomain_year, $archive, $newwindowicon, $reviewattempt, $sameuser) {
global $CFG, $remotedb;
$sqlcount = "SELECT count(attempt) as attempts, max(id) as id
FROM {quiz_attempts} qa
WHERE quiz=? and userid=?";
$params = array($quizid, $userid);
$attemptcount = $remotedb->get_records_sql($sqlcount, $params);
$out = array();
$url = '';
if ($attemptcount) {
foreach ($attemptcount as $attempt) {
$a = $attempt->attempts;
if ($a > 0) {
$attr = array();
$newicon = '';
$url = $CFG->wwwroot . "/mod/quiz/review.php?attempt=" . $attempt->id;
if ($archive) {// If an archive year then change the domain
$url = $archivedomain_year . "/mod/quiz/review.php?attempt=" . $attempt->id;
$attr = array("target" => "_blank");
$newicon = $newwindowicon;
}
//$attemptstext = ($attemptcount > 1) ? get_string('attempts', 'report_myfeedback') : get_string(
// 'attempt', 'report_myfeedback');
$attemptstext = ($a > 1) ? get_string('reviewlastof', 'report_myfeedback', $a) . $newicon : get_string('reviewaattempt', 'report_myfeedback', $a) . $newicon;
$out[] = html_writer::link($url, $attemptstext, $attr);
}
}
if (!$reviewattempt) {
if ($sameuser) {//Student can only see the attempt if it is set in review options so link to result page instead.
return "<a href=" . $CFG->wwwroot . "/mod/quiz/view.php?id=" . $quizurlid . ">" . get_string('feedback', 'report_myfeedback') . "</a>";
} else {//Tutor can still see the attempt if review is off.
return "<a href=" . $url . ">" . get_string('feedback', 'report_myfeedback') . "</a>";
}
}
}
$br = html_writer::empty_tag('br');
return implode($br, $out);
}
/**
* Get group assignment submission date - since it won't come through for a user in a group
* unless they were the one's to upload the file
*
* @param int $userid The id of the user
* @param int $assignid The id of the assignment
* @return str submission dates, each on a new line if there are multiple
*/
public function get_group_assign_submission_date($userid, $assignid) {
global $remotedb;
// Group submissions.
$sql = "SELECT max(su.timemodified) as subdate
FROM {assign_submission} su
JOIN {groups_members} gm ON su.groupid = gm.groupid AND gm.userid = ?
AND su.assignment=?";
$params = array($userid, $assignid);
$files = $remotedb->get_record_sql($sql, $params);
if ($files) {
return $files->subdate;
}
return get_string('no_submission', 'report_myfeedback');
}
/**
* Get the peercoments for workshop
*
* @param int $userid The id of the user
* @return str the comments made on all parts of the work
*/
public function get_workshop_comments($userid) {
global $remotedb;
// Group submissions.
$sql = "SELECT wg.peercomment
FROM {workshop_grades} wg
LEFT JOIN {workshop_submissions} su ON wg.assessmentid = su.id and su.authorid=?";
$params = array($userid);
$comments = $remotedb->get_recordset_sql($sql, $params, $limitfrom = 0, $limitnum = 0);
$out = array();
foreach ($comments as $comment) {
$out[] = $comment->peercomment;
}
$br = html_writer::empty_tag('br');
$comments->close();
return implode($br, $out);
}
/**
* Check if the grades and feedback have been viewed in the gradebook
* or results page since the last grade or feedback has been released
*
* @param int $contextid The context id of the course module
* @param int $assignmentid The course module id
* @param int $userid The id of the user
* @param int $courseid The id of the course
* @param str $itemname The name of the assessment/course module
* @return str date viewed or no if not viewed
*/
public function check_viewed_gradereport($contextid, $assignmentid, $userid, $courseid, $itemname) {
global $remotedb;
$sql = "SELECT min(timecreated) as timecreated
FROM {logstore_standard_log}
WHERE contextid=? AND contextinstanceid=? AND userid=? AND courseid=?
AND timecreated > ?";
$sqlone = "SELECT min(timecreated) as timecreated
FROM {logstore_standard_log}
WHERE component=? AND action=? AND userid=? AND courseid=?
AND timecreated > ?";
$sqltwo = "SELECT max(g.timemodified) as timemodified
FROM {grade_grades} g
JOIN {grade_items} gi ON g.itemid=gi.id AND g.userid=?
AND gi.courseid=? AND gi.itemname=?
JOIN {course_modules} cm ON gi.iteminstance=cm.instance AND cm.course=?
AND cm.id=?";
$paramstwo = array($userid, $courseid, $itemname, $courseid, $assignmentid);
$gradeadded = $remotedb->get_record_sql($sqltwo, $paramstwo);
if ($gradeadded) {
$params = array($contextid, $assignmentid, $userid, $courseid, $gradeadded->timemodified);
$viewreport = $remotedb->get_record_sql($sql, $params);
if ($viewreport && $viewreport->timecreated > $gradeadded->timemodified) {
return date('d-m-Y H:i', $viewreport->timecreated);
}
$paramsone = array('gradereport_user', 'viewed', $userid, $courseid, $gradeadded->timemodified);
$userreport = $remotedb->get_record_sql($sqlone, $paramsone);
if ($userreport && $userreport->timecreated > $gradeadded->timemodified) {
return date('d-m-Y H:i', $userreport->timecreated);
}
}
return 'no';
}
/**
* Check if the grades and feedback have been viewed in the gradebook
* since the last grade or feedback has been released but for manual items
*
* @param int $userid The id of the user
* @param int $courseid The id of the course
* @param int $gradeitemid The id of the manual grade item
* @return str date viewed or no if not viewed
*/
public function check_viewed_manualitem($userid, $courseid, $gradeitemid) {
global $remotedb;
$sqlone = "SELECT max(timecreated) as timecreated
FROM {logstore_standard_log}
WHERE component=? AND action=? AND userid=? AND courseid=?";
$sqltwo = "SELECT max(g.timemodified) as timemodified
FROM {grade_grades} g
JOIN {grade_items} gi ON g.itemid=gi.id AND g.userid=?
AND gi.courseid=? AND gi.id=?";
$paramsone = array('gradereport_user', 'viewed', $userid, $courseid);
$paramstwo = array($userid, $courseid, $gradeitemid);
$userreport = $remotedb->get_record_sql($sqlone, $paramsone);
$gradeadded = $remotedb->get_record_sql($sqltwo, $paramstwo);
if ($userreport) {
if ($gradeadded) {
$dateviewed = date('d-m-Y', $userreport->timecreated);
if ($gradeadded->timemodified < $userreport->timecreated) {
return $dateviewed;
}
}
}
return 'no';
}
/**
* Get the overall feedback for quiz for the user based on the grade
* they currently have in the gradebook for their best attempt
*
* @param int $quizid The id of the quiz the user attempted
* @param int $grade The grade on the quiz
* @return str the text for the overall feedback
*/
public function overallfeedback($quizid, $grade) {
global $remotedb;
$sql = "SELECT feedbacktext
FROM {quiz_feedback}
WHERE quizid=? and mingrade<=? and maxgrade>=?
limit 1";
$params = array($quizid, $grade, $grade);
$feedback = $remotedb->get_record_sql($sql, $params);
return $feedback->feedbacktext;
}
/**
* Get the Rubric feedback
*
* @param int $userid The id of the user who's feedback being viewed
* @param int $courseid The course the Rubric is being checked for
* @param int $iteminstance The instance of the module item
* @param int $itemmodule The module currently being queried
* @return str the text for the Rubric
*/
public function rubrictext($userid, $courseid, $iteminstance, $itemmodule) {
global $remotedb;
$sql = "SELECT DISTINCT rc.id, rc.description,rl.definition
FROM {gradingform_rubric_criteria} rc
JOIN {gradingform_rubric_levels} rl
ON rc.id=rl.criterionid
JOIN {gradingform_rubric_fillings} rf
ON rl.id=rf.levelid AND rc.id=rf.criterionid
JOIN {grading_instances} gin
ON rf.instanceid=gin.id
JOIN {assign_grades} ag
ON gin.itemid=ag.id
JOIN {grade_items} gi
ON ag.assignment=gi.iteminstance AND ag.userid=?
JOIN {grade_grades} gg
ON gi.id=gg.itemid AND gi.itemmodule=?
AND gi.courseid=? AND gg.userid=? AND gi.iteminstance=? AND status=?";
$params = array($userid, $itemmodule, $courseid, $userid, $iteminstance, 1);
$rubrics = $remotedb->get_recordset_sql($sql, $params);
$out = '';
if ($rubrics) {
foreach ($rubrics as $rubric) {
if ($rubric->description || $rubric->definition) {
$out .= "<strong>" . $rubric->description . ": </strong>" . $rubric->definition . "<br/>";
}
}
}
$rubrics->close();
return $out;
}
/**
* Get the Marking guide feedback
*
* @param int $userid The id of the user who's feedback being viewed
* @param int $courseid The course the Marking guide is being checked for
* @param int $iteminstance The instance of the module item
* @param int $itemmodule The module currently being queried
* @return str the text for the Marking guide
*/
public function marking_guide_text($userid, $courseid, $iteminstance, $itemmodule) {
global $remotedb;
$sql = "SELECT DISTINCT gc.shortname,gf.remark
FROM {gradingform_guide_criteria} gc
JOIN {gradingform_guide_fillings} gf
ON gc.id=gf.criterionid
JOIN {grading_instances} gin
ON gf.instanceid=gin.id
JOIN {assign_grades} ag
ON gin.itemid=ag.id
JOIN {grade_items} gi
ON ag.assignment=gi.iteminstance AND ag.userid=?
JOIN {grade_grades} gg
ON gi.id=gg.itemid AND gi.itemmodule=?
AND gi.courseid=? AND gg.userid=? AND gi.iteminstance=?";
$params = array($userid, $itemmodule, $courseid, $userid, $iteminstance);
$guides = $remotedb->get_recordset_sql($sql, $params);
$out = '';
if ($guides) {
foreach ($guides as $guide) {
if ($guide->shortname || $guide->remark) {
$out .= "<strong>" . $guide->shortname . ": </strong>" . $guide->remark . "<br/>";
}
}
}
$guides->close();
return $out;
}
/**
* Get the scales for a manual item
*
* @global stdClass $remotedb DB object
* @param int $itemid The grade item id
* @param int $userid The user id
* @param int $courseid The course id
* @param int $grade The user's grade for that manual item
* @return str The scale grade for the user
*/
public function get_grade_scale($itemid, $userid, $courseid, $grade) {
global $remotedb;
$sql = "SELECT DISTINCT gg.finalgrade, s.scale
FROM {grade_grades} gg
JOIN {grade_items} gi ON gg.itemid=gi.id AND gi.id=?
AND gg.userid=? AND gi.courseid=? AND gi.gradetype = 2
JOIN {scale} s ON gi.scaleid=s.id limit 1";
$params = array($itemid, $userid, $courseid);
$scales = $remotedb->get_record_sql($sql, $params);
$num = 0;
if ($scales) {
$scale = explode(',', $scales->scale);
$num = ($grade ? (int) $scales->finalgrade - 1 : 0);
return $scale[$num];
} else {
return '-';
}
}
/**
* Get the lowest scale grade for the scale
*
* @global stdClass $remotedb The DB object
* @param int $itemid The grade item id
* @param int $userid The user id
* @param int $courseid The course id
* @return str The lowest scale grade available
*/
public function get_min_grade_scale($itemid, $userid, $courseid) {
global $remotedb;
$sql = "SELECT DISTINCT s.scale
FROM {grade_grades} gg
JOIN {grade_items} gi ON gg.itemid=gi.id AND gi.id=?
AND gg.userid=? AND gi.courseid=? AND gi.gradetype = 2
JOIN {scale} s ON gi.scaleid=s.id limit 1";
$params = array($itemid, $userid, $courseid);
$scales = $remotedb->get_record_sql($sql, $params);
if ($scales) {
$scale = explode(',', $scales->scale);
$num = min(array_keys($scale));
return $scale[$num];
} else {
return '-';
}
}
/**
* Get the highest scale grade for the scale
*
* @global stdClass $remotedb The DB object
* @param int $itemid The grade item id
* @param int $userid The user id
* @param int $courseid The course id
* @return str The highest scale grade available
*/
public function get_available_grade_scale($itemid, $userid, $courseid) {
global $remotedb;
$sql = "SELECT DISTINCT s.scale
FROM {grade_grades} gg
JOIN {grade_items} gi ON gg.itemid=gi.id AND gi.id=?
AND gg.userid=? AND gi.courseid=? AND gi.gradetype = 2
JOIN {scale} s ON gi.scaleid=s.id limit 1";
$params = array($itemid, $userid, $courseid);
$scales = $remotedb->get_record_sql($sql, $params);
if ($scales) {
$scale = explode(',', $scales->scale);
$num = max(array_keys($scale));
return $scale[$num];
} else {
return '-';
}
}
/**
* Get All scale grades for the scale
*
* @global stdClass $remotedb The DB object
* @param int $itemid The grade item id
* @param int $userid The user id
* @param int $courseid The course id
* @return str All scale grade in the scale
*/
public function get_all_grade_scale($itemid, $userid, $courseid) {
global $remotedb;
$sql = "SELECT s.scale
FROM {grade_grades} gg
JOIN {grade_items} gi ON gg.itemid=gi.id AND gi.id=?
AND gg.userid=? AND gi.courseid=? AND gi.gradetype = 2
JOIN {scale} s ON gi.scaleid=s.id";
$params = array($itemid, $userid, $courseid);
$scales = $remotedb->get_records_sql($sql, $params);
$out = '';
if ($scales) {
foreach ($scales as $scale) {
$out .= $scale->scale . ", ";
}
return chop($out, ', ');
} else {
return '-';
}
}
/**
* Get the grade letter/word for a value grade set as letter
*
* @global stdClass $remotedb DB object
* @param int $courseid The course id
* @param int $grade The final grade the user got
* @return str The letter grade or word for the user
*/
public function get_grade_letter($courseid, $grade) {
global $remotedb;
$sql = "SELECT l.letter, con.id
FROM {grade_letters} l
JOIN {context} con ON l.contextid = con.id AND con.contextlevel=50
AND con.instanceid=? AND l.lowerboundary <=?
ORDER BY l.lowerboundary DESC limit 1";
$params = array($courseid, $grade);
$letters = $remotedb->get_record_sql($sql, $params);
if ($letters) {
$letter = $letters->letter;
} else {
$defaultletters = grade_get_letters();
$val = (int) $grade;
foreach ($defaultletters as $boundary => $value) {
if ($val >= $boundary) {
$letter = format_string($value);
break;
}
}
}
return $letter;
}