See Release Notes
Long Term Support Release
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 assignfeedback_file 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 assignfeedback_file\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\request\contextlist; 33 use \mod_assign\privacy\assign_plugin_request_data; 34 use mod_assign\privacy\useridlist; 35 36 /** 37 * Privacy class for requesting user data. 38 * 39 * @package assignfeedback_file 40 * @copyright 2018 Adrian Greeve <adrian@moodle.com> 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class provider implements 44 \core_privacy\local\metadata\provider, 45 \mod_assign\privacy\assignfeedback_provider, 46 \mod_assign\privacy\assignfeedback_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_files', 'privacy:metadata:filepurpose'); 56 return $collection; 57 } 58 59 /** 60 * No need to fill in this method as all information can be acquired from the assign_grades table in the mod assign 61 * provider. 62 * 63 * @param int $userid The user ID. 64 * @param contextlist $contextlist The context list. 65 */ 66 public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist) { 67 // This uses the assign_grade table. 68 } 69 70 /** 71 * This also does not need to be filled in as this is already collected in the mod assign provider. 72 * 73 * @param useridlist $useridlist A list of user IDs 74 */ 75 public static function get_student_user_ids(useridlist $useridlist) { 76 // Not required. 77 } 78 79 /** 80 * If you have tables that contain userids and you can generate entries in your tables without creating an 81 * entry in the assign_grades table then please fill in this method. 82 * 83 * @param \core_privacy\local\request\userlist $userlist The userlist object 84 */ 85 public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) { 86 // Not required. 87 } 88 89 /** 90 * Export all user data for this plugin. 91 * 92 * @param assign_plugin_request_data $exportdata Data used to determine which context and user to export and other useful 93 * information to help with exporting. 94 */ 95 public static function export_feedback_user_data(assign_plugin_request_data $exportdata) { 96 $currentpath = $exportdata->get_subcontext(); 97 $currentpath[] = get_string('privacy:path', 'assignfeedback_file'); 98 $assign = $exportdata->get_assign(); 99 $plugin = $assign->get_plugin_by_type('assignfeedback', 'file'); 100 $gradeid = $exportdata->get_pluginobject()->id; 101 $filefeedback = $plugin->get_file_feedback($gradeid); 102 if ($filefeedback) { 103 $fileareas = $plugin->get_file_areas(); 104 foreach ($fileareas as $filearea => $notused) { 105 \core_privacy\local\request\writer::with_context($exportdata->get_context()) 106 ->export_area_files($currentpath, 'assignfeedback_file', $filearea, $gradeid); 107 } 108 } 109 } 110 111 /** 112 * Any call to this method should delete all user data for the context defined in the deletion_criteria. 113 * 114 * @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin. 115 */ 116 public static function delete_feedback_for_context(assign_plugin_request_data $requestdata) { 117 118 $assign = $requestdata->get_assign(); 119 $plugin = $assign->get_plugin_by_type('assignfeedback', 'file'); 120 $fileareas = $plugin->get_file_areas(); 121 $fs = get_file_storage(); 122 foreach ($fileareas as $filearea => $notused) { 123 // Delete feedback files. 124 $fs->delete_area_files($requestdata->get_context()->id, 'assignfeedback_file', $filearea); 125 } 126 $plugin->delete_instance(); 127 } 128 129 /** 130 * Calling this function should delete all user data associated with this grade. 131 * 132 * @param assign_plugin_request_data $requestdata Data useful for deleting user data. 133 */ 134 public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { 135 $requestdata->set_userids([$requestdata->get_user()->id]); 136 $requestdata->populate_submissions_and_grades(); 137 self::delete_feedback_for_grades($requestdata); 138 } 139 140 141 /** 142 * Deletes all feedback for the grade ids / userids provided in a context. 143 * assign_plugin_request_data contains: 144 * - context 145 * - assign object 146 * - grade ids (pluginids) 147 * - user ids 148 * @param assign_plugin_request_data $deletedata A class that contains the relevant information required for deletion. 149 */ 150 public static function delete_feedback_for_grades(assign_plugin_request_data $deletedata) { 151 global $DB; 152 153 if (empty($deletedata->get_gradeids())) { 154 return; 155 } 156 157 $assign = $deletedata->get_assign(); 158 $plugin = $assign->get_plugin_by_type('assignfeedback', 'file'); 159 $fileareas = $plugin->get_file_areas(); 160 $fs = get_file_storage(); 161 list($sql, $params) = $DB->get_in_or_equal($deletedata->get_gradeids(), SQL_PARAMS_NAMED); 162 $params['assignment'] = $deletedata->get_assignid(); 163 foreach ($fileareas as $filearea => $notused) { 164 // Delete feedback files. 165 $fs->delete_area_files_select($deletedata->get_context()->id, 'assignfeedback_file', $filearea, $sql, $params); 166 } 167 168 // Delete table entries. 169 $DB->delete_records_select('assignfeedback_file', "assignment = :assignment AND grade $sql", $params); 170 } 171 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body