Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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    core_plagiarism
  21   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_plagiarism\privacy;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use \core_privacy\local\metadata\collection;
  30  
  31  /**
  32   * Provider for the plagiarism API.
  33   *
  34   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class provider implements
  38          // The Plagiarism subsystem does not store any data itself.
  39          // It has no database tables, and it purely acts as a conduit to the various plagiarism plugins.
  40          \core_privacy\local\metadata\provider,
  41  
  42          // The Plagiarism subsystem will be called by other components and will forward requests to each plagiarism plugin implementing its APIs.
  43          \core_privacy\local\request\subsystem\plugin_provider,
  44          \core_privacy\local\request\shared_userlist_provider
  45      {
  46  
  47      /**
  48       * Returns meta data about this system.
  49       *
  50       * @param   collection     $collection The initialised collection to add items to.
  51       * @return  collection     A listing of user data stored through this system.
  52       */
  53      public static function get_metadata(collection $collection) : collection {
  54          $collection->link_plugintype('plagiarism', 'privacy:metadata:plagiarism');
  55  
  56          return $collection;
  57      }
  58  
  59      /**
  60       * Export all plagiarism data from each plagiarism plugin for the specified userid and context.
  61       *
  62       * @param   int         $userid The user to export.
  63       * @param   \context    $context The context to export.
  64       * @param   array       $subcontext The subcontext within the context to export this information to.
  65       * @param   array       $linkarray The weird and wonderful link array used to display information for a specific item
  66       */
  67      public static function export_plagiarism_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
  68          static::call_plugin_method('export_plagiarism_user_data', [$userid, $context, $subcontext, $linkarray]);
  69      }
  70  
  71      /**
  72       * Deletes all user content for a context in all plagiarism plugins.
  73       *
  74       * @param  \context $context The context to delete user data for.
  75       */
  76      public static function delete_plagiarism_for_context(\context $context) {
  77          static::call_plugin_method('delete_plagiarism_for_context', [$context]);
  78      }
  79  
  80      /**
  81       * Deletes all user content for a user in a context in all plagiarism plugins.
  82       *
  83       * @param  int      $userid    The user to delete
  84       * @param  \context $context   The context to refine the deletion.
  85       */
  86      public static function delete_plagiarism_for_user(int $userid, \context $context) {
  87          static::call_plugin_method('delete_plagiarism_for_user', [$userid, $context]);
  88      }
  89  
  90      /**
  91       * Deletes all user content for a user in a context in all plagiarism plugins.
  92       *
  93       * @param  array    $userids   The users to delete
  94       * @param  \context $context   The context to refine the deletion.
  95       */
  96      public static function delete_plagiarism_for_users(array $userids, \context $context) {
  97          static::call_plugin_method('delete_plagiarism_for_users', [$userids, $context]);
  98      }
  99  
 100      /**
 101       * Internal method for looping through all of the plagiarism plugins and calling a method.
 102       *
 103       * @param  string $methodname Name of the method to call on the plugins.
 104       * @param  array $params     The parameters that go with the method being called.
 105       */
 106      protected static function call_plugin_method($methodname, $params) {
 107          // Note: Even if plagiarism is _now_ disabled, there may be legacy data to export.
 108          \core_privacy\manager::plugintype_class_callback('plagiarism', plagiarism_provider::class, $methodname, $params);
 109      }
 110  }