Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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    assignsubmission_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 assignsubmission_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\writer;
33
use \core_privacy\local\request\contextlist;
34
use \mod_assign\privacy\assign_plugin_request_data;
35
 
36
/**
37
 * Privacy class for requesting user data.
38
 *
39
 * @package    assignsubmission_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\assignsubmission_provider,
46
        \mod_assign\privacy\assignsubmission_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
     * This is covered by mod_assign provider and the query on assign_submissions.
61
     *
62
     * @param  int $userid The user ID that we are finding contexts for.
63
     * @param  contextlist $contextlist A context list to add sql and params to for contexts.
64
     */
65
    public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) {
66
        // This is already fetched from mod_assign.
67
    }
68
 
69
    /**
70
     * This is also covered by the mod_assign provider and it's queries.
71
     *
72
     * @param  \mod_assign\privacy\useridlist $useridlist An object for obtaining user IDs of students.
73
     */
74
    public static function get_student_user_ids(\mod_assign\privacy\useridlist $useridlist) {
75
        // No need.
76
    }
77
 
78
    /**
79
     * If you have tables that contain userids and you can generate entries in your tables without creating an
80
     * entry in the assign_submission table then please fill in this method.
81
     *
82
     * @param  userlist $userlist The userlist object
83
     */
84
    public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) {
85
        // Not required.
86
    }
87
 
88
    /**
89
     * Export all user data for this plugin.
90
     *
91
     * @param  assign_plugin_request_data $exportdata Data used to determine which context and user to export and other useful
92
     * information to help with exporting.
93
     */
94
    public static function export_submission_user_data(assign_plugin_request_data $exportdata) {
95
        // We currently don't show submissions to teachers when exporting their data.
96
        $context = $exportdata->get_context();
97
        if ($exportdata->get_user() != null) {
98
            return null;
99
        }
100
        $user = new \stdClass();
101
        $assign = $exportdata->get_assign();
102
        $plugin = $assign->get_plugin_by_type('assignsubmission', 'file');
103
        $files = $plugin->get_files($exportdata->get_pluginobject(), $user);
104
        foreach ($files as $file) {
105
            $userid = $exportdata->get_pluginobject()->userid;
106
            writer::with_context($exportdata->get_context())->export_file($exportdata->get_subcontext(), $file);
107
 
108
            // Plagiarism data.
109
            $coursecontext = $context->get_course_context();
110
            \core_plagiarism\privacy\provider::export_plagiarism_user_data($userid, $context, $exportdata->get_subcontext(), [
111
                'cmid' => $context->instanceid,
112
                'course' => $coursecontext->instanceid,
113
                'userid' => $userid,
114
                'file' => $file
115
            ]);
116
        }
117
    }
118
 
119
    /**
120
     * Any call to this method should delete all user data for the context defined in the deletion_criteria.
121
     *
122
     * @param  assign_plugin_request_data $requestdata Information useful for deleting user data.
123
     */
124
    public static function delete_submission_for_context(assign_plugin_request_data $requestdata) {
125
        global $DB;
126
 
127
        \core_plagiarism\privacy\provider::delete_plagiarism_for_context($requestdata->get_context());
128
 
129
        $fs = get_file_storage();
130
        $fs->delete_area_files($requestdata->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA);
131
 
132
        // Delete records from assignsubmission_file table.
133
        $DB->delete_records('assignsubmission_file', ['assignment' => $requestdata->get_assign()->get_instance()->id]);
134
    }
135
 
136
    /**
137
     * A call to this method should delete user data (where practical) using the userid and submission.
138
     *
139
     * @param  assign_plugin_request_data $deletedata Details about the user and context to focus the deletion.
140
     */
141
    public static function delete_submission_for_userid(assign_plugin_request_data $deletedata) {
142
        global $DB;
143
 
144
        \core_plagiarism\privacy\provider::delete_plagiarism_for_user($deletedata->get_user()->id, $deletedata->get_context());
145
 
146
        $submissionid = $deletedata->get_pluginobject()->id;
147
 
148
        $fs = get_file_storage();
149
        $fs->delete_area_files($deletedata->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA,
150
                $submissionid);
151
 
152
        $DB->delete_records('assignsubmission_file', ['assignment' => $deletedata->get_assignid(), 'submission' => $submissionid]);
153
    }
154
 
155
    /**
156
     * Deletes all submissions for the submission ids / userids provided in a context.
157
     * assign_plugin_request_data contains:
158
     * - context
159
     * - assign object
160
     * - submission ids (pluginids)
161
     * - user ids
162
     * @param  assign_plugin_request_data $deletedata A class that contains the relevant information required for deletion.
163
     */
164
    public static function delete_submissions(assign_plugin_request_data $deletedata) {
165
        global $DB;
166
 
167
        \core_plagiarism\privacy\provider::delete_plagiarism_for_users($deletedata->get_userids(), $deletedata->get_context());
168
 
169
        if (empty($deletedata->get_submissionids())) {
170
            return;
171
        }
172
        $fs = get_file_storage();
173
        list($sql, $params) = $DB->get_in_or_equal($deletedata->get_submissionids(), SQL_PARAMS_NAMED);
174
        $fs->delete_area_files_select($deletedata->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA,
175
                $sql, $params);
176
 
177
        $params['assignid'] = $deletedata->get_assignid();
178
        $DB->delete_records_select('assignsubmission_file', "assignment = :assignid AND submission $sql", $params);
179
    }
180
}