Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

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