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
 * Event observers supported by this module.
19
 *
20
 * @package    tool_dataprivacy
21
 * @copyright   2018 Mihail Geshoski <mihail@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tool_dataprivacy\event;
26
 
27
use \tool_dataprivacy\api;
28
use \tool_dataprivacy\data_request;
29
 
30
defined('MOODLE_INTERNAL') || die();
31
 
32
/**
33
 * Event observers supported by this module.
34
 *
35
 * @package    tool_dataprivacy
36
 * @copyright   2018 Mihail Geshoski <mihail@moodle.com>
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class user_deleted_observer {
40
 
41
    /**
42
     * Create user data deletion request when the user is deleted.
43
     *
44
     * @param \core\event\user_deleted $event
45
     */
46
    public static function create_delete_data_request(\core\event\user_deleted $event) {
47
        // Automatic creation of deletion requests must be enabled.
48
        if (get_config('tool_dataprivacy', 'automaticdeletionrequests')) {
49
            $requesttypes = [api::DATAREQUEST_TYPE_DELETE];
50
            $requeststatuses = [api::DATAREQUEST_STATUS_COMPLETE, api::DATAREQUEST_STATUS_DELETED];
51
 
52
            $hasongoingdeleterequests = api::has_ongoing_request($event->objectid, $requesttypes[0]);
53
            $hascompleteddeleterequest = (api::get_data_requests_count($event->objectid, $requeststatuses,
54
                    $requesttypes) > 0) ? true : false;
55
 
56
            if (!$hasongoingdeleterequests && !$hascompleteddeleterequest) {
57
                api::create_data_request($event->objectid, $requesttypes[0],
58
                        get_string('datarequestcreatedupondelete', 'tool_dataprivacy'),
59
                        data_request::DATAREQUEST_CREATION_AUTO);
60
            }
61
        }
62
    }
63
}