-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpeer_util.php
647 lines (581 loc) · 24.7 KB
/
peer_util.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
<?php
use \Tsugi\Core\Cache;
use \Tsugi\UI\Output;
use \Tsugi\Util\LTI;
use \Tsugi\Util\U;
use \Tsugi\Core\LTIX;
use \Tsugi\Core\User;
use \Tsugi\Core\Mail;
use \Tsugi\Blob\BlobUtil;
use \Tsugi\UI\Lessons;
// Loads the assignment associated with this link
function loadAssignment()
{
global $CFG, $PDOX, $LINK;
$cacheloc = 'peer_assn';
$row = Cache::check($cacheloc, $LINK->id);
if ( $row != false && $row['json'] != 'null' ) return $row;
$stmt = $PDOX->queryDie(
"SELECT assn_id, json FROM {$CFG->dbprefix}peer_assn WHERE link_id = :ID",
array(":ID" => $LINK->id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$custom = LTIX::ltiCustomGet('config');
// Check custom for errors and make it pretty
if ( strlen($custom) > 1 ) {
$decode = json_decode($custom);
if ( $decode === null ) {
error_log('Bad custom_config\n'.$custom);
$custom = null;
} else {
$pretty = json_encode($decode,JSON_PRETTY_PRINT);
$custom = $pretty;
}
}
if ( ( ! $custom || U::isEmpty($custom) ) && isset($_GET["inherit"]) && isset($CFG->lessons) ) {
$l = new Lessons($CFG->lessons);
if ( $l ) {
$lti = $l->getLtiByRlid($_GET['inherit']);
if ( isset($lti->custom) ) foreach($lti->custom as $c ) {
if (isset($c->key) && isset($c->json) && $c->key == 'config' ) {
$custom = json_encode($c->json, JSON_PRETTY_PRINT);
}
}
}
}
if ( $row === false && strlen($custom) > 1 ) {
$stmt = $PDOX->queryReturnError(
"INSERT INTO {$CFG->dbprefix}peer_assn
(link_id, json, created_at, updated_at)
VALUES ( :ID, :JSON, NOW(), NOW())
ON DUPLICATE KEY UPDATE json = :JSON, updated_at = NOW()",
array(
':JSON' => $custom,
':ID' => $LINK->id)
);
Cache::clear("peer_assn");
$stmt = $PDOX->queryDie(
"SELECT assn_id, json FROM {$CFG->dbprefix}peer_assn WHERE link_id = :ID",
array(":ID" => $LINK->id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
}
if ( ! $row ) return $row;
$row['json'] = upgradeSubmission($row['json'] );
Cache::set($cacheloc, $LINK->id, $row);
return $row;
}
function loadSubmission($assn_id, $user_id)
{
global $CFG, $PDOX;
$cacheloc = 'peer_submit';
$cachekey = $assn_id . "::" . $user_id;
$submit_row = Cache::check($cacheloc, $cachekey);
if ( $submit_row != false ) return $submit_row;
$submit_row = false;
$stmt = $PDOX->queryDie(
"SELECT submit_id, json, note, reflect, inst_points, inst_note, inst_id, updated_at
FROM {$CFG->dbprefix}peer_submit AS S
WHERE assn_id = :AID AND S.user_id = :UID",
array(":AID" => $assn_id, ":UID" => $user_id)
);
$submit_row = $stmt->fetch(PDO::FETCH_ASSOC);
Cache::set($cacheloc, $cachekey, $submit_row);
return $submit_row;
}
// Upgrade a submission to cope with name changes
function upgradeSubmission($json_str)
{
global $CFG;
if ( U::isEmpty(trim($json_str)) ) return $json_str;
$json = json_decode($json_str);
if ( $json === null ) return $json_str;
// Add instructorpoints if they are not there
if ( ! isset($json->instructorpoints) ) $json->instructorpoints = 0;
// Convert maxpoints to peerpoints
if ( ( ! isset($json->peerpoints) ) && isset($json->maxpoints) ) $json->peerpoints = $json->maxpoints;
unset($json->maxpoints);
// Allow for things to be optional
if ( ! isset($json->totalpoints) ) $json->totalpoints = 0; // Probably an error
if ( ! isset($json->assesspoints) ) $json->assesspoints = 0;
if ( ! isset($json->maxassess) ) $json->maxassess = 0;
if ( ! isset($json->minassess) ) $json->minassess = 0;
if ( ! isset($json->peerpoints) ) $json->peerpoints = 0;
if ( ! isset($json->flag) ) $json->flag = true;
if ( ! isset($json->rating) ) $json->rating = 0;
if ( ! isset($json->gallery) ) $json->gallery = "off";
if ( ! isset($json->galleryformat) ) $json->galleryformat = "card";
if ( ! isset($json->resubmit) ) $json->resubmit = "off";
if ( ! isset($json->autopeer) ) $json->autopeer = 0;
if ( $json->autopeer === false ) $json->autopeer = 0;
if ( ! isset($json->notepublic) ) $json->notepublic = "false";
if ( ! isset($json->image_size) ) $json->image_size = 1;
if ( ! isset($json->pdf_size) ) $json->pdf_size = 0; // Max
// Fix urls
if ( isset($json->assignment) && is_string($json->assignment) && ! U::isEmpty($json->assignment) ) {
$json->assignment = str_replace('{apphome}', $CFG->apphome, $json->assignment);
}
return json_encode($json);
}
// Check for ungraded submissions
function loadUngraded($assn_id)
{
global $CFG, $PDOX, $USER;
$stmt = $PDOX->queryDie(
"SELECT S.submit_id, S.user_id, S.created_at, count(G.user_id) AS submit_count
FROM {$CFG->dbprefix}peer_submit AS S LEFT JOIN {$CFG->dbprefix}peer_grade AS G
ON S.submit_id = G.submit_id
WHERE S.assn_id = :AID AND S.user_id != :UID AND
S.submit_id NOT IN
( SELECT DISTINCT submit_id from {$CFG->dbprefix}peer_grade WHERE user_id = :UID)
GROUP BY S.submit_id, S.created_at
ORDER BY submit_count ASC, S.created_at ASC
LIMIT 10",
array(":AID" => $assn_id, ":UID" => $USER->id)
);
return $stmt->fetchAll();
}
function showSubmission($assn_json, $submit_json, $assn_id, $user_id)
{
global $CFG, $PDOX, $USER, $LINK, $CONTEXT, $OUTPUT;
echo('<div style="padding:5px">');
$blob_ids = isset($submit_json->blob_ids) ? $submit_json->blob_ids : array();
$urls = isset($submit_json->urls) ? $submit_json->urls : array();
$codes = isset($submit_json->codes) ? $submit_json->codes : array();
$htmls = isset($submit_json->htmls) ? $submit_json->htmls : array();
$content_items = isset($submit_json->content_items) ? $submit_json->content_items : array();
$blobno = 0;
$urlno = 0;
$codeno = 0;
$htmlno = 0;
$content_item_no = 0;
foreach ( $assn_json->parts as $part ) {
if ( $part->type == "image" ) {
// This test triggers when an assignment is reconfigured
// and old submissions have too few blobs
if ( $blobno >= count($blob_ids) ) continue;
$blob_id = $blob_ids[$blobno++];
if ( is_array($blob_id) ) $blob_id = $blob_id[0];
$url = BlobUtil::getAccessUrlForBlob($blob_id);
$title = 'Student image';
if( isset($part->title) && U::isNotEmpty($part->title) ) $title = $part->title;
echo (' <a href="#" onclick="$(\'#myModal_'.$blob_id.'\').modal();"');
echo ('alt="'.htmlent_utf8($title).'" title="'.htmlent_utf8($title).'">');
echo ('<img src="'.addSession($url).'" width="240" style="max-width: 100%"></a>'."\n");
?>
<div class="modal fade" id="myModal_<?php echo($blob_id); ?>">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo(htmlent_utf8($title)); ?></h4>
</div>
<div class="modal-body">
<img src="<?php echo(addSession($url)); ?>" style="width:100%">
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
} else if ( $part->type == "pdf" ) {
$blob_id = $blob_ids[$blobno++];
if ( is_array($blob_id) ) $blob_id = $blob_id[0];
$url = BlobUtil::getAccessUrlForBlob($blob_id);
$title = 'Student PDF';
if( isset($part->title) && U::isNotEmpty($part->title) ) $title = $part->title;
// Need session because target="_blank"
echo ('<p><a href="'.addSession(safe_href($url)).'" target="_blank">');
echo (htmlentities($title).'</a> (Will launch in new window)</p>'."\n");
} else if ( $part->type == "url" && $urlno < count($urls) ) {
$url = $urls[$urlno++];
echo ('<p><a href="'.safe_href($url).'" target="_blank">');
echo (htmlentities(safe_href($url)).'</a> (Will launch in new window)</p>'."\n");
} else if ( $part->type == "content_item" && $content_item_no < count($content_items) ) {
$content_item = $content_items[$content_item_no++];
$endpoint = $content_item->url;
$info = LTIX::getKeySecretForLaunch($endpoint);
if ( $info === false ) {
echo('<p style="color:red">Unable to load key/secret for '.htmlentities($endpoint)."</p>\n");
$content_item_no++;
continue;
}
$lu1 = LTIX::getLaunchUrl($endpoint, true);
$lu1 = addSession($lu1);
echo('<br/><button type="button" onclick="
$(\'#content_item_frame_'.$content_item_no.'\').attr(\'src\', \''.$lu1.'\');
showModalIframe(\''.$part->title.'\',
\'content_item_dialog_'.$content_item_no.'\',\'content_item_frame_'.$content_item_no.'\',
\''.$OUTPUT->getSpinnerUrl().'\');
return false;">View Media</button>'."\n");
?>
<div id="content_item_dialog_<?= $content_item_no ?>" title="Content Item Dialog" style="display:none;">
<iframe src="about:blank" id="content_item_frame_<?= $content_item_no ?>"
style="width:95%; height:500px;"
scrolling="auto" frameborder="1" transparency></iframe>
</div>
<?php
$content_item_no++;
} else if ( $part->type == "html" && $htmlno < count($htmls) ) {
$html_id = $htmls[$htmlno++];
$row = $PDOX->rowDie("
SELECT data FROM {$CFG->dbprefix}peer_text
WHERE text_id = :TID AND user_id = :UID AND assn_id = :AID",
array( ":TID" => $html_id,
":AID" => $assn_id,
":UID" => $user_id)
);
$json_url = addSession("load_html.php?html_id=$html_id&user_id=$user_id");
if ( $row === FALSE || U::isEmpty($row['data']) ) {
echo("<p>No HTML Found</p>\n");
} else {
echo ('<p>HTML: <a href="#" onclick="$(\'#myModal_html_'.$htmlno.'\').modal();">');
echo(htmlent_utf8($part->title)."</a> (click to view)</p>\n");
?>
<div class="modal fade" id="myModal_html_<?php echo($htmlno); ?>">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo(htmlent_utf8($part->title)); ?></h4>
</div>
<div class="modal-body" id="html_content_<?php echo($htmlno); ?>">
<img src="<?= $OUTPUT->getSpinnerUrl() ?>"/>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
html_loads.push(['html_content_<?php echo($htmlno); ?>', '<?= $json_url ?>']);
</script>
<?php
}
} else if ( $part->type == "code" && $codeno < count($codes) ) {
$code_id = $codes[$codeno++];
$row = $PDOX->rowDie("
SELECT data FROM {$CFG->dbprefix}peer_text
WHERE text_id = :TID AND user_id = :UID AND assn_id = :AID",
array( ":TID" => $code_id,
":AID" => $assn_id,
":UID" => $user_id)
);
if ( $row === FALSE || U::isEmpty($row['data']) ) {
echo("<p>No Code Found</p>\n");
} else {
echo ('<p>Code: <a href="#" onclick="$(\'#myModal_code_'.$codeno.'\').modal();">');
echo(htmlent_utf8($part->title)."</a> (click to view)</p>\n");
?>
<div class="modal fade" id="myModal_code_<?php echo($codeno); ?>">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo(htmlent_utf8($part->title)); ?></h4>
</div>
<div class="modal-body">
<!-- Don't indent or inadvertently add a newline once the pre starts -->
<pre class="line-numbers"><code
<?php if ( isset($part->language) ) { ?>
class="language-<?php echo($part->language); ?>"
<?php } ?>
><?php echo (htmlentities($row['data'])); ?>
</code>
</pre>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
}
}
}
echo("<br/> <br/>\n");
if ( $blobno > 0 ) {
echo("<p>Click on each image/pdf to see a larger view of the image.</p>\n");
}
if ( isset($submit_json->notes) && is_string($submit_json->notes) && strlen($submit_json->notes) > 1 ) {
echo("<p>Notes: ".htmlent_utf8($submit_json->notes)."</p>\n");
}
echo('<div style="padding:3px">');
}
function load_htmls() {
global $CFG;
?>
<script src="<?= $CFG->staticroot ?>/js/HtmlSanitizer.js"></script>
<script type="text/javascript">
$(document).ready( function () {
for(i=0; i<html_loads.length; i++) {
var divname = html_loads[i][0];
$.get(html_loads[i][1], function(data) {
var html = HtmlSanitizer.SanitizeHtml(data);
$('#'+divname).html(html);
})
}
});
</script>
<?php
}
function computeGrade($assn_id, $assn_json, $user_id)
{
global $CFG, $PDOX;
// $submit_row = loadSubmission($assn_id, $USER->id);
if ( $assn_json->totalpoints == 0 ) return 0;
$sql = "SELECT S.assn_id, S.json AS json, S.user_id AS user_id,
inst_points, email, displayname,
S.submit_id as submit_id, S.created_at AS created_at,
MAX(points) as max_points, COUNT(points) as count_points
FROM {$CFG->dbprefix}peer_submit as S
JOIN {$CFG->dbprefix}peer_grade AS G
ON S.submit_id = G.submit_id
JOIN {$CFG->dbprefix}lti_user AS U
ON S.user_id = U.user_id
WHERE S.assn_id = :AID AND S.user_id = :UID";
$stmt = $PDOX->queryDie($sql,
array(":AID" => $assn_id, ":UID" => $user_id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( $row === false || $row['user_id']+0 == 0 ) return -1;
$displayname = $row['displayname'];
$submit_json_str = $row['json'];
$submit_json = false;
if ( U::isNotEmpty($submit_json_str) ) {
$submit_json = json_decode($submit_json_str);
}
// Compute the overall points
$inst_points = $row['inst_points'] + 0;
$assnpoints = $row['max_points']+0;
// Handle when the student has waited "long enough" for a peer-grade
$created_at = strtotime($row['created_at']." UTC");
$diff = time() - $created_at;
if ( isset($assn_json->autopeer) && $assn_json->autopeer > 0 &&
$diff > $assn_json->autopeer && $assnpoints < $assn_json->peerpoints) {
// TODO: Turn this into an event
error_log('Auto-peer '.time().' '.$diff.' '.$row['displayname']);
$assnpoints = $assn_json->peerpoints;
}
if ( $assnpoints < 0 ) $assnpoints = 0;
if ( $assnpoints > $assn_json->peerpoints ) $assnpoints = $assn_json->peerpoints;
$peer_marks = retrievePeerMarks($assn_id, $user_id);
$sql = "SELECT count(G.user_id) as grade_count
FROM {$CFG->dbprefix}peer_submit as S
JOIN {$CFG->dbprefix}peer_grade AS G
ON S.submit_id = G.submit_id
WHERE S.assn_id = :AID AND G.user_id = :UID";
$stmt = $PDOX->queryDie($sql,
array(":AID" => $assn_id, ":UID" => $user_id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$gradecount = 0;
if ( $row ) $gradecount = $row['grade_count']+0;
if ( $peer_marks > $gradecount ) $gradecount = $peer_marks;
if ( $gradecount < 0 ) $gradecount = 0;
if ( $gradecount > $assn_json->minassess ) $gradecount = $assn_json->minassess;
$gradepoints = $gradecount * $assn_json->assesspoints;
// Handle if student is exempt from peer grading
if ( $submit_json && isset($submit_json->peer_exempt) ) {
$gradepoints = $assn_json->minassess * $assn_json->assesspoints;
error_log('Accessible override '.time().' '.$displayname.' points='.$gradepoints);
}
$retval = ($inst_points + $assnpoints + $gradepoints) / $assn_json->totalpoints;
if ( $retval > 1.0 ) $retval = 1.0;
return $retval;
}
// Load the count of grades for this user for an assignment
function loadMyGradeCount($assn_id) {
global $CFG, $PDOX, $USER;
$cacheloc = 'peer_grade';
$cachekey = $assn_id . "::" . $USER->id;
$grade_count = Cache::check($cacheloc, $cachekey);
if ( $grade_count != false ) return $grade_count;
$peer_marks = retrievePeerMarks($assn_id, $USER->id);
$stmt = $PDOX->queryDie(
"SELECT COUNT(grade_id) AS grade_count
FROM {$CFG->dbprefix}peer_submit AS S
JOIN {$CFG->dbprefix}peer_grade AS G
ON S.submit_id = G.submit_id
WHERE S.assn_id = :AID AND G.user_id = :UID",
array( ':AID' => $assn_id, ':UID' => $USER->id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( $row !== false ) {
$grade_count = U::get($row, 'grade_count', '0') + 0;
} else {
$grade_count = $peer_marks;
}
if ( $peer_marks > $grade_count ) $grade_count = $peer_marks;
Cache::set($cacheloc, $cachekey, $grade_count);
return $grade_count;
}
// Retrieve grades for a submission
// Not cached because another user may have added a grade
// a moment ago
function retrieveSubmissionGrades($submit_id)
{
global $CFG, $PDOX;
if ( $submit_id === false ) return false;
$grades_received = $PDOX->allRowsDie(
"SELECT grade_id, points, note, displayname, email, rating
FROM {$CFG->dbprefix}peer_grade AS G
JOIN {$CFG->dbprefix}lti_user as U
ON G.user_id = U.user_id
WHERE G.submit_id = :SID
ORDER BY points DESC",
array( ':SID' => $submit_id)
);
return $grades_received;
}
// Check the peer_marks in case entries have been deleted
function retrievePeerMarks($assn_id, $user_id) {
global $CFG, $PDOX;
$sql = "SELECT peer_marks FROM {$CFG->dbprefix}peer_submit
WHERE assn_id = :AID AND user_id = :UID";
// TODO: Make queryDie after we are sure the model is upgraded
$stmt = $PDOX->queryReturnError($sql,
// $stmt = $PDOX->queryDie($sql,
array(":AID" => $assn_id, ":UID" => $user_id)
);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$peer_marks = U::get($row, 'peer_marks', '0') + 0;
return $peer_marks;
}
function retrieveGradesGiven($assn_id, $user_id)
{
global $CFG, $PDOX;
$grades_given = $PDOX->allRowsDie(
"SELECT grade_id, points, G.note AS note, displayname, email, G.rating AS rating
FROM {$CFG->dbprefix}peer_grade AS G
JOIN {$CFG->dbprefix}peer_submit AS S
ON G.submit_id = S.submit_id
JOIN {$CFG->dbprefix}lti_user as U
ON S.user_id = U.user_id
WHERE G.user_id = :UID AND S.assn_id = :AID",
array( ':AID' => $assn_id, ':UID' => $user_id)
);
return $grades_given;
}
function mailDeleteSubmit($user_id, $assn_json, $note)
{
global $CFG, $PDOX, $CONTEXT, $LINK, $USER;
if ( (!isset($CFG->maildomain)) || $CFG->maildomain === false ) return false;
$LAUNCH = LTIX::requireData();
$user_row = User::loadUserInfoBypass($user_id);
if ( $user_row === false ) return false;
$to = $user_row['email'];
if ( U::isEmpty($to) || strpos($to,'@') === false ) return false;
$name = $user_row['displayname'];
$token = Mail::computeCheck($user_id);
$subject = 'From '.$CFG->servicename.', Your Peer Graded Entry Has Been Reset';
$E = "\n";
if ( isset($CFG->maileol) ) $E = $CFG->maileol;
$message = "This is an automated message. Your peer-graded entry has been reset.$E$E";
if ( isset($CONTEXT->title) ) $message .= 'Course Title: '.$CONTEXT->title.$E;
if ( isset($LINK->title) ) $message .= 'Assignment: '.$LINK->title.$E;
// if ( isset($USER->displayname) ) $message .= 'Staff member doing reset: '.$USER->displayname.$E;
$fixnote = trim($note);
if ( U::isNotEmpty($fixnote) ) {
if ( $E != "\n" ) $fixnote = str_replace("\n",$E,$fixnote);
$message .= "Notes regarding this action:".$E.$fixnote.$E;
}
$message .= "{$E}You may now re-submit your peer-graded assignment.$E";
$stmt = $PDOX->queryDie(
"INSERT INTO {$CFG->dbprefix}mail_sent
(context_id, link_id, user_to, user_from, subject, body, created_at)
VALUES ( :CID, :LID, :UTO, :UFR, :SUB, :BOD, NOW() )",
array( ":CID" => $CONTEXT->id, ":LID" => $LINK->id,
":UTO" => $user_id, ":UFR" => $USER->id,
":SUB" => $subject, ":BOD" => $message)
);
// echo $to, $subject, $message, $user_id, $token;
$retval = Mail::send($to, $subject, $message, $user_id, $token);
return $retval;
}
function getDefaultJson()
{
$json = '{ "title" : "Assignment title",
"description" : "This is a sample assignment configuration showing the various kinds of items you can ask for in the assignment.",
"grading" : "Don\'t take off points for little mistakes. If they seem to have done the assignment give them full credit. Feel free to make suggestions if there are small mistakes. Please keep your comments positive and useful. If you do not take grading seriously, the instructors may delete your response and you will lose points.",
"parts" : [
{ "title" : "URL of your home page",
"type" : "url"
},
{ "title" : "Some HTML using the CKEditor",
"type" : "html"
},
{ "title" : "Source code of index.php with your name",
"type" : "code",
"language" : "php"
},
{ "title" : "Image (JPG or PNG) of your home page (Maximum 1MB per file)",
"type" : "image"
}
],
"gallery" : "off",
"galleryformat" : "card",
"totalpoints" : 10,
"instructorpoints" : 0,
"peerpoints" : 6,
"rating" : 0,
"assesspoints" : 2,
"minassess" : 2,
"maxassess" : 5,
"flag" : true
}';
$json = json_decode($json);
if ( $json === null ) die("Bad JSON constant");
$json = json_encode($json);
// $json = \Tsugi\Util\LTI::jsonIndent($json);
return $json;
}
function pointsDetail($assn_json) {
$r = "The total number of points for this assignment is $assn_json->totalpoints.\n";
if ( isset($assn_json->instructorpoints) && $assn_json->instructorpoints > 0 ) {
$r .= "You will get up to $assn_json->instructorpoints points from your instructor.\n";
}
if ( isset($assn_json->peerpoints) && $assn_json->peerpoints > 0 ) {
$r .= "Your peers will give you a grade from 0 - $assn_json->peerpoints".".\n";
}
if ( isset($assn_json->assesspoints) && $assn_json->assesspoints > 0 ) {
$r .= "You will get $assn_json->assesspoints for each peer assignment you assess.\n";
}
if ( isset($assn_json->minassess) && $assn_json->minassess > 0 ) {
$r .= "You need to grade a minimum of $assn_json->minassess peer assignments.\n";
}
if ( isset($assn_json->maxassess) && $assn_json->maxassess > $assn_json->minassess) {
$r .= "You can grade up to $assn_json->maxassess peer assignments if you like but grading extra assignment will not increase your score.\n";
}
return $r;
}
function deleteSubmission($assn_row, $submit_row) {
global $PDOX, $USER, $CFG;
$p = $CFG->dbprefix;
$assn_id = $assn_row['assn_id'];
$submit_id = $submit_row['submit_id'];
$json = isset($submit_row['json']) ? $submit_row['json'] : false;
if ( $json && U::isNotEmpty($json) ) $json = json_decode($json);
if ( $json ) $blob_ids = isset($json->blob_ids) ? $json->blob_ids : false;
if ( is_array($blob_ids) ) {
foreach($blob_ids as $blob_id ) {
echo("Delete blob $blob_id \n");
BlobUtil::deleteBlob($blob_id);
}
}
if ( $json ) $pdf_ids = isset($json->pdf_ids) ? $json->pdf_ids : false;
if ( is_array($pdf_ids) ) {
foreach($pdf_ids as $blob_id ) {
echo("Delete blob $blob_id \n");
BlobUtil::deleteBlob($blob_id);
}
}
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_submit
WHERE submit_id = :SID",
array( ':SID' => $submit_id)
);
// Since text items are connected to the assignment not submission
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_text
WHERE assn_id = :AID AND user_id = :UID",
array( ':AID' => $assn_id, ':UID' => $USER->id)
);
Cache::clear('peer_grade');
Cache::clear('peer_submit');
}