2
// This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18
* Event to be triggered when a feedback response is submitted.
20
* @package mod_feedback
21
* @copyright 2013 Ankit Agarwal
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
25
namespace mod_feedback\event;
26
defined('MOODLE_INTERNAL') || die();
29
* Class response_submitted
31
* Class for event to be triggered when a feedback response is submitted.
33
* @package mod_feedback
35
* @copyright 2013 Ankit Agarwal
36
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
38
class response_submitted extends \core\event\base {
41
* Set basic properties for the event.
43
protected function init() {
46
require_once($CFG->dirroot.'/mod/feedback/lib.php');
47
$this->data['objecttable'] = 'feedback_completed';
48
$this->data['crud'] = 'c';
49
$this->data['level'] = self::LEVEL_PARTICIPATING;
53
* Returns localised general event name.
57
public static function get_name() {
58
return get_string('eventresponsesubmitted', 'mod_feedback');
62
* Returns non-localised event description with id's for admin use only.
66
public function get_description() {
67
return 'The user ' . $this->other['relateduserid']. ' submited a feedback';
71
* Returns relevant URL based on the anonymous mode of the response.
74
public function get_url() {
75
if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
76
return new \moodle_url('/mod/feedback/show_entries.php' , array('id' => $this->other['cmid'],
77
'do_show' => 'showoneentry' , 'userid' => $this->relateduserid));
79
return new \moodle_url('/mod/feedback/show_entries_anonym.php', array('id' => $this->other['cmid'],
80
'do_show' => 'showoneentry', 'showall', 'showcompleted' => $this->objectid));
85
* Replace add_to_log() statement. Do this only for the case when anonymous mode is off,
86
* since this is what was happening before.
88
* @return array of parameters to be passed to legacy add_to_log() function.
90
protected function get_legacy_logdata() {
91
if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
94
return array($this->courseid, 'feedback', 'submit', 'view.php?id=' . $this->other['cmid'],
95
$this->other['instanceid'], $this->other['cmid'], $this->relateduserid);
100
* Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
102
* @param int|\stdClass $userorid ID of the user.
103
* @return bool True if the user can view the event, false otherwise.
105
public function can_view($userorid = null) {
108
if (empty($userorid)) {
111
if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
112
return is_siteadmin($userorid);
114
return has_capability('mod/feedback:viewreports', $this->context, $userorid);
119
* Custom validations.
121
* @throws \coding_exception in case of any problems.
123
protected function validate_data() {
124
if (!isset($this->other['anonymous'])) {
125
throw new \coding_exception("Field other['anonymous'] cannot be empty");
127
if (!isset($this->other['cmid'])) {
128
throw new \coding_exception("Field other['cmid'] cannot be empty");
130
if (!isset($this->other['instanceid'])) {
131
throw new \coding_exception("Field other['instanceid'] cannot be empty");