MDL-61307 core_privacy: Add legacy polyfill for contrib plugins
[moodle.git] / privacy / classes / local / legacy_polyfill.php
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/>.
17 /**
18  * This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up.
19  *
20  * @package core_privacy
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 namespace core_privacy\local;
26 use \core_privacy\local\metadata\collection;
27 use \core_privacy\local\request\contextlist;
28 use \core_privacy\local\request\approved_contextlist;
29 use \core_privacy\local\request\deletion_criteria;
31 defined('MOODLE_INTERNAL') || die();
33 /**
34  * The trait used to provide a backwards compatability for third-party plugins.
35  *
36  * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
37  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38  */
39 trait legacy_polyfill {
41     /**
42      * Get the language string identifier with the component's language
43      * file to explain why this plugin stores no data.
44      *
45      * @return  string
46      */
47     public static function get_reason() : string {
48         return static::_get_reason();
49     }
51     /**
52      * Get the list of items.
53      *
54      * @param   collection     $collection The initialised collection to add items to.
55      * @return  collection     A listing of user data stored through this system.
56      */
57     public static function get_metadata(collection $collection) : collection  {
58         return static::_get_metadata($collection);
59     }
61     /**
62      * Export all user preferences for the plugin.
63      *
64      * @param   int         $userid The userid of the user whose data is to be exported.
65      */
66     public static function export_user_preferences(int $userid) {
67         return static::_export_user_preferences($userid);
68     }
70     /**
71      * Get the list of contexts that contain user information for the specified user.
72      *
73      * @param   int         $userid     The user to search.
74      * @return  contextlist   $contextlist  The contextlist containing the list of contexts used in this plugin.
75      */
76     public static function get_contexts_for_userid(int $userid) : contextlist {
77         return static::_get_contexts_for_userid($userid);
78     }
80     /**
81      * Export all user data for the specified user, in the specified contexts.
82      *
83      * @param   approved_contextlist    $contextlist    The approved contexts to export information for.
84      */
85     public static function export_user_data(approved_contextlist $contextlist) {
86         return static::_export_user_data($contextlist);
87     }
89     /**
90      * Delete all use data which matches the specified deletion_criteria.
91      *
92      * @param   deletion_criteria       $criteria   An object containing specific deletion criteria to delete for.
93      */
94     public static function delete_for_context(deletion_criteria $criteria) {
95         return static::_delete_for_context($criteria);
96     }
98     /**
99      * Delete all user data for the specified user, in the specified contexts.
100      *
101      * @param   approved_contextlist    $contextlist    The approved contexts and user information to delete information for.
102      */
103     public static function delete_user_data(approved_contextlist $contextlist) {
104         return static::_delete_user_data($contextlist);
105     }