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 * Enrol instance created event. 19 * 20 * @package core 21 * @copyright 2015 Marina Glancy 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core\event; 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Enrol instance created event class. 30 * 31 * @property-read array $other { 32 * Extra information about event. 33 * 34 * - string enrol: name of enrol method 35 * } 36 * 37 * @package core 38 * @since Moodle 2.9 39 * @copyright 2015 Marina Glancy 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class enrol_instance_created extends base { 43 44 /** 45 * Api to Create new event from enrol object. 46 * 47 * @param \stdClass $enrol record from DB table 'enrol' 48 * @return \core\event\base returns instance of new event 49 */ 50 public static final function create_from_record($enrol) { 51 $event = static::create(array( 52 'context' => \context_course::instance($enrol->courseid), 53 'objectid' => $enrol->id, 54 'other' => array('enrol' => $enrol->enrol) 55 )); 56 return $event; 57 } 58 59 /** 60 * Returns description of what happened. 61 * 62 * @return string 63 */ 64 public function get_description() { 65 return "The user with id '$this->userid' created the instance of enrolment method '" . 66 $this->other['enrol'] . "' with id '$this->objectid'."; 67 } 68 69 /** 70 * Return localised event name. 71 * 72 * @return string 73 */ 74 public static function get_name() { 75 return get_string('eventenrolinstancecreated', 'enrol'); 76 } 77 78 /** 79 * Get URL related to the action 80 * 81 * @return \moodle_url 82 */ 83 public function get_url() { 84 return new \moodle_url('/enrol/instances.php', array('id' => $this->courseid)); 85 } 86 87 /** 88 * Init method. 89 * 90 * @return void 91 */ 92 protected function init() { 93 $this->data['crud'] = 'c'; 94 $this->data['edulevel'] = self::LEVEL_OTHER; 95 $this->data['objecttable'] = 'enrol'; 96 } 97 98 /** 99 * custom validations 100 * 101 * Throw \coding_exception notice in case of any problems. 102 */ 103 protected function validate_data() { 104 parent::validate_data(); 105 if (!isset($this->other['enrol'])) { 106 throw new \coding_exception('The \'enrol\' value must be set in other.'); 107 } 108 } 109 110 public static function get_objectid_mapping() { 111 return array('db' => 'enrol', 'restore' => 'enrol'); 112 } 113 114 public static function get_other_mapping() { 115 // Nothing to map. 116 return false; 117 } 118 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body