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
namespace core\event;
18
 
19
/**
20
 * Event fired when a file is deleted from the draft area.
21
 *
22
 * @property-read array $other {
23
 *      Extra information about the event.
24
 *
25
 *      - string itemid: itemid of the file
26
 *      - string filename: Name of the file deleted from the draft area.
27
 *      - string filesize: The file size.
28
 *      - string filepath: The filepath.
29
 *      - string contenthash: The file contenthash.
30
 * }
31
 *
32
 * @package   core
33
 * @since     Moodle 4.2
34
 * @copyright 2023 The Open University.
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class draft_file_deleted extends base {
38
 
39
    protected function init() {
40
        $this->data['objecttable'] = 'files';
41
        $this->data['crud'] = 'd';
42
        $this->data['edulevel'] = self::LEVEL_OTHER;
43
    }
44
 
45
    public static function get_name() {
46
        return get_string('eventfiledeletedfromdraftarea', 'files');
47
    }
48
 
49
    public function get_description() {
50
        $humansize = display_size($this->other['filesize']);
51
        $filetype = 'file';
52
        if ($this->other['filename'] == '.') {
53
            $filetype = 'folder';
54
        }
55
        return "The user with id '{$this->userid}' has deleted {$filetype} '{$this->other['filepath']}" .
56
            "{$this->other['filename']}' from the draft file area with item id {$this->other['itemid']}. Size: {$humansize}. ".
57
            "Content hash: {$this->other['contenthash']}.";
58
    }
59
 
60
    protected function validate_data() {
61
        parent::validate_data();
62
 
63
        if (!isset($this->other['itemid'])) {
64
            throw new \coding_exception('The \'itemid\' must be set in other.');
65
        }
66
 
67
        if (!isset($this->other['filename'])) {
68
            throw new \coding_exception('The \'filename\' value must be set in other.');
69
        }
70
 
71
        if (!isset($this->other['filesize'])) {
72
            throw new \coding_exception('The \'filesize\' value must be set in other.');
73
        }
74
 
75
        if (!isset($this->other['filepath'])) {
76
            throw new \coding_exception('The \'filepath\' value must be set in other.');
77
        }
78
 
79
        if (!isset($this->other['contenthash'])) {
80
            throw new \coding_exception('The \'contenthash\' value must be set in other.');
81
        }
82
    }
83
}