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 mod_feedback response deleted event.
19
 *
20
 * @package    mod_feedback
21
 * @copyright  2013 Ankit Agarwal
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
23
 */
24
 
25
namespace mod_feedback\event;
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * The mod_feedback response deleted event class.
30
 *
31
 * This event is triggered when a feedback response is deleted.
32
 *
33
 * @property-read array $other {
34
 *      Extra information about event.
35
 *
36
 *      - int anonymous: if feedback is anonymous.
37
 *      - int cmid: course module id.
38
 *      - int instanceid: id of instance.
39
 * }
40
 *
41
 * @package    mod_feedback
42
 * @since      Moodle 2.6
43
 * @copyright  2013 Ankit Agarwal
44
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
45
 */
46
class response_deleted extends \core\event\base {
47
 
48
    /**
49
     * Set basic properties for the event.
50
     */
51
    protected function init() {
52
        $this->data['objecttable'] = 'feedback_completed';
53
        $this->data['crud'] = 'd';
54
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
55
    }
56
 
57
    /**
58
     * Creates an instance from the record from db table feedback_completed
59
     *
60
     * @param stdClass $completed
61
     * @param stdClass|cm_info $cm
62
     * @param stdClass $feedback
63
     * @return self
64
     */
65
    public static function create_from_record($completed, $cm, $feedback) {
66
        $event = self::create(array(
67
            'relateduserid' => $completed->userid,
68
            'objectid' => $completed->id,
69
            'courseid' => $cm->course,
70
            'context' => \context_module::instance($cm->id),
71
            'anonymous' => ($completed->anonymous_response == FEEDBACK_ANONYMOUS_YES),
72
            'other' => array(
73
                'cmid' => $cm->id,
74
                'instanceid' => $feedback->id,
75
                'anonymous' => $completed->anonymous_response) // Deprecated.
76
        ));
77
 
78
        $event->add_record_snapshot('feedback_completed', $completed);
79
        $event->add_record_snapshot('feedback', $feedback);
80
        return $event;
81
    }
82
 
83
    /**
84
     * Returns localised general event name.
85
     *
86
     * @return string
87
     */
88
    public static function get_name() {
89
        return get_string('eventresponsedeleted', 'mod_feedback');
90
    }
91
 
92
    /**
93
     * Returns non-localised event description with id's for admin use only.
94
     *
95
     * @return string
96
     */
97
    public function get_description() {
98
        return "The user with id '$this->userid' deleted the feedback for the user with id '$this->relateduserid' " .
99
            "for the feedback activity with course module id '$this->contextinstanceid'.";
100
    }
101
 
102
    /**
103
     * Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
104
     *
105
     * @deprecated since 2.7
106
     *
107
     * @param int|\stdClass $userorid ID of the user.
108
     * @return bool True if the user can view the event, false otherwise.
109
     */
110
    public function can_view($userorid = null) {
111
        global $USER;
112
        debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);
113
 
114
        if (empty($userorid)) {
115
            $userorid = $USER;
116
        }
117
        if ($this->anonymous) {
118
            return is_siteadmin($userorid);
119
        } else {
120
            return has_capability('mod/feedback:viewreports', $this->context, $userorid);
121
        }
122
    }
123
 
124
    /**
125
     * Custom validations
126
     *
127
     * @throws \coding_exception in case of any problems.
128
     */
129
    protected function validate_data() {
130
        parent::validate_data();
131
 
132
        if (!isset($this->relateduserid)) {
133
            throw new \coding_exception('The \'relateduserid\' must be set.');
134
        }
135
        if (!isset($this->other['anonymous'])) {
136
            throw new \coding_exception('The \'anonymous\' value must be set in other.');
137
        }
138
        if (!isset($this->other['cmid'])) {
139
            throw new \coding_exception('The \'cmid\' value must be set in other.');
140
        }
141
        if (!isset($this->other['instanceid'])) {
142
            throw new \coding_exception('The \'instanceid\' value must be set in other.');
143
        }
144
    }
145
 
146
    public static function get_objectid_mapping() {
147
        return array('db' => 'feedback_completed', 'restore' => 'feedback_completed');
148
    }
149
 
150
    public static function get_other_mapping() {
151
        $othermapped = array();
152
        $othermapped['cmid'] = array('db' => 'course_modules', 'restore' => 'course_module');
153
        $othermapped['instanceid'] = array('db' => 'feedback', 'restore' => 'feedback');
154
 
155
        return $othermapped;
156
    }
157
}
158