|
28 | 28 | defined('MOODLE_INTERNAL') || die(); |
29 | 29 |
|
30 | 30 | use \core_privacy\local\request\approved_contextlist; |
31 | | -use \core_privacy\local\request\deletion_criteria; |
32 | 31 | use \core_privacy\local\request\writer; |
33 | | -use \core_privacy\local\request\helper as request_helper; |
34 | 32 | use \core_privacy\local\metadata\collection; |
35 | | -use \core_privacy\local\request\transform; |
| 33 | +use core_privacy\local\request\approved_userlist; |
| 34 | +use core_privacy\local\request\userlist; |
36 | 35 |
|
37 | 36 | /** |
38 | 37 | * Description of provider |
@@ -329,27 +328,41 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { |
329 | 328 | $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST); |
330 | 329 |
|
331 | 330 | // 1. Delete all reports this user made in this annotator. |
332 | | - $DB->delete_records('pdfannotator_reports', ['pdfannotatorid' => $instanceid, 'userid' => $userid]); |
| 331 | + $DB->delete_records( |
| 332 | + 'pdfannotator_reports', |
| 333 | + ['pdfannotatorid' => $instanceid, 'userid' => $userid] |
| 334 | + ); |
333 | 335 |
|
334 | 336 | // 2. Delete all votes this user made in this annotator. |
335 | | - $sql = "SELECT v.id FROM {pdfannotator_votes} v WHERE v.userid = ? AND v.commentid IN (SELECT c.id FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ?)"; |
| 337 | + $sql = "SELECT v.id |
| 338 | + FROM {pdfannotator_votes} v |
| 339 | + WHERE v.userid = ? AND v.commentid IN |
| 340 | + (SELECT c.id |
| 341 | + FROM {pdfannotator_comments} c |
| 342 | + WHERE c.pdfannotatorid = ?)"; |
336 | 343 | $votes = $DB->get_records_sql($sql , array($userid, $instanceid)); |
337 | 344 | foreach ($votes as $vote) { |
338 | 345 | $DB->delete_records('pdfannotator_votes', array("id" => $vote->id)); |
339 | 346 | } |
340 | 347 |
|
341 | 348 | // 3. Delete all subscriptions this user made in this annotator. |
342 | | - $sql = "SELECT s.id FROM {pdfannotator_subscriptions} s WHERE s.userid = ? AND s.annotationid IN " |
343 | | - . "(SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)"; |
| 349 | + $sql = "SELECT s.id |
| 350 | + FROM {pdfannotator_subscriptions} s |
| 351 | + WHERE s.userid = ? AND s.annotationid IN |
| 352 | + (SELECT a.id |
| 353 | + FROM {pdfannotator_annotations} a |
| 354 | + WHERE a.pdfannotatorid = ?)"; |
344 | 355 | $subscriptions = $DB->get_records_sql($sql, array($userid, $instanceid)); |
345 | 356 | foreach ($subscriptions as $subscription) { |
346 | 357 | $DB->delete_records('pdfannotator_subscriptions', array("id" => $subscription->id)); |
347 | 358 | } |
348 | 359 |
|
349 | 360 | // 4. Select all comments this user made in this annotator. |
350 | | - $comments = $DB->get_records_sql("SELECT c.* FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ? AND c.userid = ?", array($instanceid, $userid)); |
| 361 | + $sql = "SELECT c.* |
| 362 | + FROM {pdfannotator_comments} c |
| 363 | + WHERE c.pdfannotatorid = ? AND c.userid = ?"; |
| 364 | + $comments = $DB->get_records_sql($sql, array($instanceid, $userid)); |
351 | 365 | foreach ($comments as $comment) { |
352 | | - |
353 | 366 | // Delete question comments, their underlying annotation as well as all answers and subscriptions. |
354 | 367 | if ($comment->isquestion) { |
355 | 368 | self::delete_annotation($comment->annotationid); |
@@ -389,6 +402,8 @@ public static function delete_annotation($annotationid) { |
389 | 402 | // 1.2 Delete any votes for these comments. |
390 | 403 | $DB->delete_records('pdfannotator_votes', array("commentid" => $comment->id)); |
391 | 404 |
|
| 405 | + // Delete any pictures of the comment. |
| 406 | + $DB->delete_records('files', array("component" => "mod_pdfannotator", "filearea" => "post", "itemid" => $comment->id)); |
392 | 407 | } |
393 | 408 |
|
394 | 409 | // 1.3 Now delete all comments. |
@@ -508,7 +523,7 @@ public static function get_users_in_context(userlist $userlist) { |
508 | 523 | * Deletes data for users in given userlist's context. |
509 | 524 | * @param approved_userlist $userlist |
510 | 525 | */ |
511 | | - public static function delete_data_for_users(\core_privacy\local\request\approved_userlist $userlist) { |
| 526 | + public static function delete_data_for_users(approved_userlist $userlist) { |
512 | 527 | global $DB; |
513 | 528 |
|
514 | 529 | $context = $userlist->get_context(); |
@@ -551,5 +566,13 @@ public static function delete_data_for_users(\core_privacy\local\request\approve |
551 | 566 | $DB->delete_records_select('pdfannotator_annotations', $sql, $params); |
552 | 567 | $DB->delete_records_select('pdfannotator_reports', $sql, $params); |
553 | 568 | $DB->delete_records_select('pdfannotator_comments', $sql, $params); |
| 569 | + |
| 570 | + // Delete pictures in comments. |
| 571 | + $DB->execute("DELETE FORM {files} imgs |
| 572 | + WHERE imgs.component = 'mod_pdfannotator' |
| 573 | + AND imgs.filearea = 'post' |
| 574 | + AND imgs.userid {$userinsql} |
| 575 | + AND imgs.itemid {$commentinsql}", |
| 576 | + array_merge($userinparams, $commentinparams)); |
554 | 577 | } |
555 | 578 | } |
0 commit comments