Differences Between: [Versions 311 and 402] [Versions 311 and 403]
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 * Replace add_to_log() statement. 104 * 105 * @return array of parameters to be passed to legacy add_to_log() function. 106 */ 107 protected function get_legacy_logdata() { 108 return array($this->courseid, 'feedback', 'delete', 'view.php?id=' . $this->other['cmid'], $this->other['instanceid'], 109 $this->other['instanceid']); 110 } 111 112 /** 113 * Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response. 114 * 115 * @deprecated since 2.7 116 * 117 * @param int|\stdClass $userorid ID of the user. 118 * @return bool True if the user can view the event, false otherwise. 119 */ 120 public function can_view($userorid = null) { 121 global $USER; 122 debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER); 123 124 if (empty($userorid)) { 125 $userorid = $USER; 126 } 127 if ($this->anonymous) { 128 return is_siteadmin($userorid); 129 } else { 130 return has_capability('mod/feedback:viewreports', $this->context, $userorid); 131 } 132 } 133 134 /** 135 * Custom validations 136 * 137 * @throws \coding_exception in case of any problems. 138 */ 139 protected function validate_data() { 140 parent::validate_data(); 141 142 if (!isset($this->relateduserid)) { 143 throw new \coding_exception('The \'relateduserid\' must be set.'); 144 } 145 if (!isset($this->other['anonymous'])) { 146 throw new \coding_exception('The \'anonymous\' value must be set in other.'); 147 } 148 if (!isset($this->other['cmid'])) { 149 throw new \coding_exception('The \'cmid\' value must be set in other.'); 150 } 151 if (!isset($this->other['instanceid'])) { 152 throw new \coding_exception('The \'instanceid\' value must be set in other.'); 153 } 154 } 155 156 public static function get_objectid_mapping() { 157 return array('db' => 'feedback_completed', 'restore' => 'feedback_completed'); 158 } 159 160 public static function get_other_mapping() { 161 $othermapped = array(); 162 $othermapped['cmid'] = array('db' => 'course_modules', 'restore' => 'course_module'); 163 $othermapped['instanceid'] = array('db' => 'feedback', 'restore' => 'feedback'); 164 165 return $othermapped; 166 } 167 } 168
title
Description
Body
title
Description
Body
title
Description
Body
title
Body