1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Privacy class for requesting user data. 19 * 20 * @package assignsubmission_comments 21 * @copyright 2018 Adrian Greeve <adrian@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace assignsubmission_comments\privacy; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 30 31 use \core_privacy\local\metadata\collection; 32 use \core_privacy\local\metadata\provider as metadataprovider; 33 use \core_comment\privacy\provider as comments_provider; 34 use \core_privacy\local\request\contextlist; 35 use \mod_assign\privacy\assign_plugin_request_data; 36 37 /** 38 * Privacy class for requesting user data. 39 * 40 * @package assignsubmission_comments 41 * @copyright 2018 Adrian Greeve <adrian@moodle.com> 42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 43 */ 44 class provider implements metadataprovider, 45 \mod_assign\privacy\assignsubmission_provider, 46 \mod_assign\privacy\assignsubmission_user_provider { 47 48 /** 49 * Return meta data about this plugin. 50 * 51 * @param collection $collection A list of information to add to. 52 * @return collection Return the collection after adding to it. 53 */ 54 public static function get_metadata(collection $collection) : collection { 55 $collection->link_subsystem('core_comment', 'privacy:metadata:commentpurpose'); 56 return $collection; 57 } 58 59 /** 60 * It is possible to make a comment as a teacher without creating an entry in the submission table, so this is required 61 * to find those entries. 62 * 63 * @param int $userid The user ID that we are finding contexts for. 64 * @param contextlist $contextlist A context list to add sql and params to for contexts. 65 */ 66 public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) { 67 $sql = "SELECT contextid 68 FROM {comments} 69 WHERE component = :component 70 AND commentarea = :commentarea 71 AND userid = :userid"; 72 $params = ['userid' => $userid, 'component' => 'assignsubmission_comments', 'commentarea' => 'submission_comments']; 73 $contextlist->add_from_sql($sql, $params); 74 } 75 76 /** 77 * Due to the fact that we can't rely on the queries in the mod_assign provider we have to add some additional sql. 78 * 79 * @param \mod_assign\privacy\useridlist $useridlist An object for obtaining user IDs of students. 80 */ 81 public static function get_student_user_ids(\mod_assign\privacy\useridlist $useridlist) { 82 $params = ['assignid' => $useridlist->get_assignid(), 'commentuserid' => $useridlist->get_teacherid(), 83 'commentuserid2' => $useridlist->get_teacherid()]; 84 $sql = "SELECT DISTINCT c.userid AS id 85 FROM {comments} c 86 JOIN (SELECT c.itemid 87 FROM {comments} c 88 JOIN {assign_submission} s ON s.id = c.itemid AND s.assignment = :assignid 89 WHERE c.userid = :commentuserid) aa ON aa.itemid = c.itemid 90 WHERE c.userid NOT IN (:commentuserid2)"; 91 $useridlist->add_from_sql($sql, $params); 92 } 93 94 /** 95 * If you have tables that contain userids and you can generate entries in your tables without creating an 96 * entry in the assign_submission table then please fill in this method. 97 * 98 * @param \core_privacy\local\request\userlist $userlist The userlist object 99 */ 100 public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) { 101 $context = $userlist->get_context(); 102 if ($context->contextlevel != CONTEXT_MODULE) { 103 return; 104 } 105 comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments', 106 $context->id); 107 } 108 109 /** 110 * Export all user data for this plugin. 111 * 112 * @param assign_plugin_request_data $exportdata Data used to determine which context and user to export and other useful 113 * information to help with exporting. 114 */ 115 public static function export_submission_user_data(assign_plugin_request_data $exportdata) { 116 $component = 'assignsubmission_comments'; 117 $commentarea = 'submission_comments'; 118 119 $userid = ($exportdata->get_user() != null); 120 $submission = $exportdata->get_pluginobject(); 121 122 // For the moment we are only showing the comments made by this user. 123 comments_provider::export_comments($exportdata->get_context(), $component, $commentarea, $submission->id, 124 $exportdata->get_subcontext(), $userid); 125 } 126 127 /** 128 * Delete all the comments made for this context. 129 * 130 * @param assign_plugin_request_data $requestdata Data to fulfill the deletion request. 131 */ 132 public static function delete_submission_for_context(assign_plugin_request_data $requestdata) { 133 comments_provider::delete_comments_for_all_users($requestdata->get_context(), 'assignsubmission_comments', 134 'submission_comments'); 135 } 136 137 /** 138 * A call to this method should delete user data (where practical) using the userid and submission. 139 * 140 * @param assign_plugin_request_data $exportdata Details about the user and context to focus the deletion. 141 */ 142 public static function delete_submission_for_userid(assign_plugin_request_data $exportdata) { 143 // Create an approved context list to delete the comments. 144 $contextlist = new \core_privacy\local\request\approved_contextlist($exportdata->get_user(), 'assignsubmission_comments', 145 [$exportdata->get_context()->id]); 146 comments_provider::delete_comments_for_user($contextlist, 'assignsubmission_comments', 'submission_comments'); 147 } 148 149 /** 150 * Deletes all submissions for the submission ids / userids provided in a context. 151 * assign_plugin_request_data contains: 152 * - context 153 * - assign object 154 * - submission ids (pluginids) 155 * - user ids 156 * @param assign_plugin_request_data $deletedata A class that contains the relevant information required for deletion. 157 */ 158 public static function delete_submissions(assign_plugin_request_data $deletedata) { 159 $userlist = new \core_privacy\local\request\approved_userlist($deletedata->get_context(), 'assignsubmission_comments', 160 $deletedata->get_userids()); 161 comments_provider::delete_comments_for_users($userlist, 'assignsubmission_comments', 'submission_comments'); 162 } 163 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body