Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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    gradingform_rubric
  21   * @copyright  2018 Sara Arjona <sara@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace gradingform_rubric\privacy;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use \core_privacy\local\metadata\collection;
  30  
  31  /**
  32   * Privacy class for requesting user data.
  33   *
  34   * @copyright  2018 Sara Arjona <sara@moodle.com>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class provider implements
  38          \core_privacy\local\metadata\provider,
  39          \core_grading\privacy\gradingform_provider_v2 {
  40  
  41      /**
  42       * Returns meta data about this system.
  43       *
  44       * @param  collection $collection The initialised collection to add items to.
  45       * @return collection A listing of user data stored through this system.
  46       */
  47      public static function get_metadata(collection $collection) : collection {
  48          $collection->add_database_table('gradingform_rubric_fillings', [
  49              'instanceid' => 'privacy:metadata:instanceid',
  50              'criterionid' => 'privacy:metadata:criterionid',
  51              'levelid' => 'privacy:metadata:levelid',
  52              'remark' => 'privacy:metadata:remark'
  53          ], 'privacy:metadata:fillingssummary');
  54          return $collection;
  55      }
  56  
  57      /**
  58       * Export user data relating to an instance ID.
  59       *
  60       * @param  \context $context Context to use with the export writer.
  61       * @param  int $instanceid The instance ID to export data for.
  62       * @param  array $subcontext The directory to export this data to.
  63       */
  64      public static function export_gradingform_instance_data(\context $context, int $instanceid, array $subcontext) {
  65          global $DB;
  66          // Get records from the provided params.
  67          $params = ['instanceid' => $instanceid];
  68          $sql = "SELECT rc.description, rl.definition, rl.score, rf.remark
  69                    FROM {gradingform_rubric_fillings} rf
  70                    JOIN {gradingform_rubric_criteria} rc ON rc.id = rf.criterionid
  71                    JOIN {gradingform_rubric_levels} rl ON rf.levelid = rl.id
  72                   WHERE rf.instanceid = :instanceid";
  73          $records = $DB->get_records_sql($sql, $params);
  74          if ($records) {
  75              $subcontext = array_merge($subcontext, [get_string('rubric', 'gradingform_rubric'), $instanceid]);
  76              \core_privacy\local\request\writer::with_context($context)->export_data($subcontext, (object) $records);
  77          }
  78      }
  79  
  80      /**
  81       * Deletes all user data related to the provided instance IDs.
  82       *
  83       * @param  array  $instanceids The instance IDs to delete information from.
  84       */
  85      public static function delete_gradingform_for_instances(array $instanceids) {
  86          global $DB;
  87          $DB->delete_records_list('gradingform_rubric_fillings', 'instanceid', $instanceids);
  88      }
  89  }