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 * User competency grade rated in course event. 19 * 20 * @package core_competency 21 * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core\event; 26 27 use core\event\base; 28 use core_competency\user_competency_course; 29 use context_course; 30 defined('MOODLE_INTERNAL') || die(); 31 32 /** 33 * User competency grade rated in course event class. 34 * 35 * @property-read array $other { 36 * Extra information about event. 37 * 38 * - int competencyid: id of competency. 39 * - int grade: grade name of the user competency 40 * } 41 * 42 * @package core_competency 43 * @since Moodle 3.1 44 * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> 45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 46 */ 47 class competency_user_competency_rated_in_course extends base { 48 49 /** 50 * Convenience method to instantiate the event. 51 * 52 * @param user_competency_course $usercompetencycourse The user competency course. 53 * @return self 54 */ 55 public static function create_from_user_competency_course(user_competency_course $usercompetencycourse) { 56 if (!$usercompetencycourse->get('id')) { 57 throw new \coding_exception('The user competency course ID must be set.'); 58 } 59 60 $params = array( 61 'objectid' => $usercompetencycourse->get('id'), 62 'relateduserid' => $usercompetencycourse->get('userid'), 63 'other' => array( 64 'competencyid' => $usercompetencycourse->get('competencyid'), 65 'grade' => $usercompetencycourse->get('grade') 66 ) 67 ); 68 $coursecontext = context_course::instance($usercompetencycourse->get('courseid')); 69 $params['contextid'] = $coursecontext->id; 70 $params['courseid'] = $usercompetencycourse->get('courseid'); 71 72 $event = static::create($params); 73 $event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record()); 74 return $event; 75 } 76 77 /** 78 * Returns description of what happened. 79 * 80 * @return string 81 */ 82 public function get_description() { 83 return "The user with id '$this->userid' rated the user competency with id '$this->objectid' with " 84 . "'" . $this->other['grade'] . "' rating " 85 . "in course with id '$this->courseid'"; 86 } 87 88 /** 89 * Return localised event name. 90 * 91 * @return string 92 */ 93 public static function get_name() { 94 return get_string('eventusercompetencyratedincourse', 'core_competency'); 95 } 96 97 /** 98 * Get URL related to the action 99 * 100 * @return \moodle_url 101 */ 102 public function get_url() { 103 return \core_competency\url::user_competency_in_course($this->relateduserid, $this->other['competencyid'], 104 $this->courseid); 105 } 106 107 /** 108 * Init method. 109 * 110 * @return void 111 */ 112 protected function init() { 113 $this->data['crud'] = 'u'; 114 $this->data['edulevel'] = self::LEVEL_TEACHING; 115 $this->data['objecttable'] = user_competency_course::TABLE; 116 } 117 118 /** 119 * Get_objectid_mapping method. 120 * 121 * @return string the name of the restore mapping the objectid links to 122 */ 123 public static function get_objectid_mapping() { 124 return base::NOT_MAPPED; 125 } 126 127 /** 128 * Custom validation. 129 * 130 * Throw \coding_exception notice in case of any problems. 131 */ 132 protected function validate_data() { 133 if (!isset($this->other) || !isset($this->other['competencyid'])) { 134 throw new \coding_exception('The \'competencyid\' value must be set.'); 135 } 136 137 if (!$this->courseid) { 138 throw new \coding_exception('The \'courseid\' value must be set.'); 139 } 140 141 if (!$this->relateduserid) { 142 throw new \coding_exception('The \'relateduserid\' value must be set.'); 143 } 144 145 if (!isset($this->other['grade'])) { 146 throw new \coding_exception('The \'grade\' value must be set.'); 147 } 148 } 149 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body