Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
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 submitted 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 submitted event class. 30 * 31 * This event is triggered when a feedback response is submitted. 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_submitted extends \core\event\base { 47 48 /** 49 * Set basic properties for the event. 50 */ 51 protected function init() { 52 global $CFG; 53 54 require_once($CFG->dirroot.'/mod/feedback/lib.php'); 55 $this->data['objecttable'] = 'feedback_completed'; 56 $this->data['crud'] = 'c'; 57 $this->data['edulevel'] = self::LEVEL_PARTICIPATING; 58 } 59 60 /** 61 * Creates an instance from the record from db table feedback_completed 62 * 63 * @param stdClass $completed 64 * @param stdClass|cm_info $cm 65 * @return self 66 */ 67 public static function create_from_record($completed, $cm) { 68 $event = self::create(array( 69 'relateduserid' => $completed->userid, 70 'objectid' => $completed->id, 71 'context' => \context_module::instance($cm->id), 72 'anonymous' => ($completed->anonymous_response == FEEDBACK_ANONYMOUS_YES), 73 'other' => array( 74 'cmid' => $cm->id, 75 'instanceid' => $completed->feedback, 76 'anonymous' => $completed->anonymous_response // Deprecated. 77 ) 78 )); 79 $event->add_record_snapshot('feedback_completed', $completed); 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('eventresponsesubmitted', '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' submitted response for 'feedback' activity with " 99 . "course module id '$this->contextinstanceid'."; 100 } 101 102 /** 103 * Returns relevant URL based on the anonymous mode of the response. 104 * @return \moodle_url 105 */ 106 public function get_url() { 107 if ($this->anonymous) { 108 return new \moodle_url('/mod/feedback/show_entries.php', array('id' => $this->other['cmid'], 109 'showcompleted' => $this->objectid)); 110 } else { 111 return new \moodle_url('/mod/feedback/show_entries.php' , array('id' => $this->other['cmid'], 112 'userid' => $this->userid, 'showcompleted' => $this->objectid)); 113 } 114 } 115 116 /** 117 * Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response. 118 * 119 * @deprecated since 2.7 120 * 121 * @param int|\stdClass $userorid ID of the user. 122 * @return bool True if the user can view the event, false otherwise. 123 */ 124 public function can_view($userorid = null) { 125 global $USER; 126 debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER); 127 128 if (empty($userorid)) { 129 $userorid = $USER; 130 } 131 if ($this->anonymous) { 132 return is_siteadmin($userorid); 133 } else { 134 return has_capability('mod/feedback:viewreports', $this->context, $userorid); 135 } 136 } 137 138 /** 139 * Custom validations. 140 * 141 * @throws \coding_exception in case of any problems. 142 */ 143 protected function validate_data() { 144 parent::validate_data(); 145 146 if (!isset($this->relateduserid)) { 147 throw new \coding_exception('The \'relateduserid\' must be set.'); 148 } 149 if (!isset($this->other['anonymous'])) { 150 throw new \coding_exception('The \'anonymous\' value must be set in other.'); 151 } 152 if (!isset($this->other['cmid'])) { 153 throw new \coding_exception('The \'cmid\' value must be set in other.'); 154 } 155 if (!isset($this->other['instanceid'])) { 156 throw new \coding_exception('The \'instanceid\' value must be set in other.'); 157 } 158 } 159 160 public static function get_objectid_mapping() { 161 return array('db' => 'feedback_completed', 'restore' => 'feedback_completed'); 162 } 163 164 public static function get_other_mapping() { 165 $othermapped = array(); 166 $othermapped['cmid'] = array('db' => 'course_modules', 'restore' => 'course_module'); 167 $othermapped['instanceid'] = array('db' => 'feedback', 'restore' => 'feedback'); 168 169 return $othermapped; 170 } 171 } 172
title
Description
Body
title
Description
Body
title
Description
Body
title
Body