Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * draft_file_added
21
 *
22
 * Event fired when a file is added to the draft area.
23
 *
24
 * @property-read array $other {
25
 *      Extra information about the event.
26
 *
27
 *      - string itemid: itemid of the file
28
 *      - string filename: Name of the file added to the draft area.
29
 *      - string filesize: The file size.
30
 *      - string filepath: The filepath.
31
 *      - string contenthash: The file contenthash.
1441 ariadna 32
 *      - float avscantime: (optional) if present, the time taken to do any AV scanning, in seconds.
1 efrain 33
 * }
34
 *
35
 * @package   core
36
 * @since     Moodle 4.2
37
 * @copyright 2023 The Open University.
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class draft_file_added extends base {
41
 
42
    protected function init() {
43
        $this->data['objecttable'] = 'files';
44
        $this->data['crud'] = 'c';
45
        $this->data['edulevel'] = self::LEVEL_OTHER;
46
    }
47
 
48
    public static function get_name() {
49
        return get_string('eventfileaddedtodraftarea', 'files');
50
    }
51
 
52
    public function get_description() {
53
        $humansize = display_size($this->other['filesize']);
54
        return "The user with id '{$this->userid}' has uploaded file '{$this->other['filepath']}{$this->other['filename']}' " .
55
            "to the draft file area with item id {$this->other['itemid']}. Size: {$humansize}. ".
56
            "Content hash: {$this->other['contenthash']}.";
57
    }
58
 
59
    protected function validate_data() {
60
        parent::validate_data();
61
 
62
        if (!isset($this->other['itemid'])) {
63
            throw new \coding_exception('The \'itemid\' must be set in other.');
64
        }
65
 
66
        if (!isset($this->other['filename'])) {
67
            throw new \coding_exception('The \'filename\' value must be set in other.');
68
        }
69
 
70
        if (!isset($this->other['filesize'])) {
71
            throw new \coding_exception('The \'filesize\' value must be set in other.');
72
        }
73
 
74
        if (!isset($this->other['filepath'])) {
75
            throw new \coding_exception('The \'filepath\' value must be set in other.');
76
        }
77
 
78
        if (!isset($this->other['contenthash'])) {
79
            throw new \coding_exception('The \'contenthash\' value must be set in other.');
80
        }
1441 ariadna 81
 
82
        if (isset($this->data['other']['avscantime'])) {
83
            if (!is_numeric($this->data['other']['avscantime'])) {
84
                throw new \coding_exception('If given, \'avscantime\' in other must be a number.');
85
            }
86
            $this->data['other']['avscantime'] = (float) $this->data['other']['avscantime'];
87
        }
88
 
1 efrain 89
    }
90
}