[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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_assign abstract base event. 19 * 20 * @package mod_assign 21 * @copyright 2014 Mark Nelson 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace mod_assign\event; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * The mod_assign abstract base event class. 31 * 32 * Most mod_assign events can extend this class. 33 * 34 * @package mod_assign 35 * @since Moodle 2.7 36 * @copyright 2014 Mark Nelson 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 abstract class base extends \core\event\base { 40 41 /** @var \assign */ 42 protected $assign; 43 44 /** 45 * Legacy log data. 46 * 47 * @var array 48 */ 49 protected $legacylogdata; 50 51 /** 52 * Set assign instance for this event. 53 * @param \assign $assign 54 * @throws \coding_exception 55 */ 56 public function set_assign(\assign $assign) { 57 if ($this->is_triggered()) { 58 throw new \coding_exception('set_assign() must be done before triggerring of event'); 59 } 60 if ($assign->get_context()->id != $this->get_context()->id) { 61 throw new \coding_exception('Invalid assign isntance supplied!'); 62 } 63 $this->assign = $assign; 64 } 65 66 /** 67 * Get assign instance. 68 * 69 * NOTE: to be used from observers only. 70 * 71 * @throws \coding_exception 72 * @return \assign 73 */ 74 public function get_assign() { 75 if ($this->is_restored()) { 76 throw new \coding_exception('get_assign() is intended for event observers only'); 77 } 78 if (!isset($this->assign)) { 79 debugging('assign property should be initialised in each event', DEBUG_DEVELOPER); 80 global $CFG; 81 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 82 $cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST); 83 $course = get_course($cm->course); 84 $this->assign = new \assign($this->get_context(), $cm, $course); 85 } 86 return $this->assign; 87 } 88 89 90 /** 91 * Returns relevant URL. 92 * 93 * @return \moodle_url 94 */ 95 public function get_url() { 96 return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid)); 97 } 98 99 /** 100 * Sets the legacy event log data. 101 * 102 * @param string $action The current action 103 * @param string $info A detailed description of the change. But no more than 255 characters. 104 * @param string $url The url to the assign module instance. 105 */ 106 public function set_legacy_logdata($action = '', $info = '', $url = '') { 107 $fullurl = 'view.php?id=' . $this->contextinstanceid; 108 if ($url != '') { 109 $fullurl .= '&' . $url; 110 } 111 112 $this->legacylogdata = array($this->courseid, 'assign', $action, $fullurl, $info, $this->contextinstanceid); 113 } 114 115 /** 116 * Return legacy data for add_to_log(). 117 * 118 * @return array 119 */ 120 protected function get_legacy_logdata() { 121 if (isset($this->legacylogdata)) { 122 return $this->legacylogdata; 123 } 124 125 return null; 126 } 127 128 /** 129 * Custom validation. 130 * 131 * @throws \coding_exception 132 */ 133 protected function validate_data() { 134 parent::validate_data(); 135 136 if ($this->contextlevel != CONTEXT_MODULE) { 137 throw new \coding_exception('Context level must be CONTEXT_MODULE.'); 138 } 139 } 140 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |