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
 * The report_participation report viewed event.
19
 *
20
 * @package    report_participation
21
 * @copyright  2013 Ankit Agarwal
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
namespace report_participation\event;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * The report_participation report viewed event class.
30
 *
31
 * @property-read array $other {
32
 *      Extra information about the event.
33
 *
34
 *      - int instanceid: Id of instance.
35
 *      - int roleid: Role id for whom report is viewed.
36
 *      - int groupid: (optional) group id.
37
 *      - int timefrom: (optional) time from which report is viewed.
38
 *      - string action: (optional) action viewed.
39
 * }
40
 *
41
 * @package    report_participation
42
 * @since      Moodle 2.7
43
 * @copyright  2013 Ankit Agarwal
44
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 */
46
class report_viewed extends \core\event\base {
47
 
48
    /**
49
     * Init method.
50
     *
51
     * @return void
52
     */
53
    protected function init() {
54
        $this->data['crud'] = 'r';
55
        $this->data['edulevel'] = self::LEVEL_TEACHING;
56
    }
57
 
58
    /**
59
     * Return localised event name.
60
     *
61
     * @return string
62
     */
63
    public static function get_name() {
64
        return get_string('eventreportviewed', 'report_participation');
65
    }
66
 
67
    /**
68
     * Returns description of what happened.
69
     *
70
     * @return string
71
     */
72
    public function get_description() {
73
        return "The user with id '$this->userid' viewed the course participation report for the course with id '$this->courseid'.";
74
    }
75
 
76
    /**
77
     * Returns relevant URL.
78
     *
79
     * @return \moodle_url
80
     */
81
    public function get_url() {
82
        return new \moodle_url('/report/participation/index.php', array('id' => $this->courseid,
83
            'instanceid' => $this->other['instanceid'], 'roleid' => $this->other['roleid']));
84
    }
85
 
86
    /**
87
     * Custom validation.
88
     *
89
     * @throws \coding_exception
90
     * @return void
91
     */
92
    protected function validate_data() {
93
        parent::validate_data();
94
        if (empty($this->other['instanceid'])) {
95
            throw new \coding_exception('The \'instanceid\' value must be set in other.');
96
        }
97
 
98
        if (empty($this->other['roleid'])) {
99
            throw new \coding_exception('The \'roleid\' value must be set in other.');
100
        }
101
 
102
        if (!isset($this->other['groupid'])) {
103
            throw new \coding_exception('The \'groupid\' value must be set in other.');
104
        }
105
 
106
        if (!isset($this->other['timefrom'])) {
107
            throw new \coding_exception('The \'timefrom\' value must be set in other.');
108
        }
109
 
110
        if (!isset($this->other['action'])) {
111
            throw new \coding_exception('The \'action\' value must be set in other.');
112
        }
113
 
114
    }
115
 
116
    public static function get_other_mapping() {
117
        $othermapped = array();
118
        // This is a badly named variable - it represents "cm->id" not "cm->instance".
119
        $othermapped['instanceid'] = array('db' => 'course_modules', 'restore' => 'course_module');
120
 
121
        $othermapped['roleid'] = array('db' => 'role', 'restore' => 'role');
122
        $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
123
 
124
        return $othermapped;
125
 
126
    }
127
}
128