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 namespace core\event; 18 19 /** 20 * URL blocked event class. 21 * 22 * @property-read array $other { 23 * Extra information about event. 24 * 25 * - string url: blocked url 26 * - string reason: reason for blocking 27 * - bool redirect: blocked url was a redirect 28 * } 29 * 30 * @package core 31 * @copyright 2022 Catalyst IT 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class url_blocked extends base { 35 36 /** 37 * Returns description of what happened. 38 * 39 * @return string 40 */ 41 public function get_description() { 42 return sprintf( 43 'Blocked %s%s: %s', 44 $this->other['url'], 45 $this->other['redirect'] ? ' (redirect)' : '', 46 $this->other['reason'] 47 ); 48 } 49 50 /** 51 * Return localised event name. 52 * 53 * @return string 54 */ 55 public static function get_name() { 56 return get_string('eventurlblocked', 'core'); 57 } 58 59 /** 60 * Init method. 61 * 62 * @return void 63 */ 64 protected function init() { 65 global $USER; 66 67 $this->data['crud'] = 'c'; 68 $this->data['edulevel'] = self::LEVEL_OTHER; 69 $this->context = empty($USER->id) ? \context_system::instance() : \context_user::instance($USER->id); 70 } 71 72 /** 73 * Custom validation. 74 * 75 * It is recommended to set the properties: 76 * - $other['tokenid'] 77 * - $other['username'] 78 * 79 * However they are not mandatory as they are not always known. 80 * 81 * Please note that the token CANNOT be specified, it is considered 82 * as a password and should never be displayed. 83 * 84 * @throws \coding_exception 85 * @return void 86 */ 87 protected function validate_data() { 88 parent::validate_data(); 89 if (!isset($this->other['url'])) { 90 throw new \coding_exception("The 'url' value must be set in other."); 91 } 92 } 93 94 /** 95 * Used when restoring course logs. 96 * 97 */ 98 public static function get_other_mapping() { 99 } 100 101 /** 102 * Validate all properties right before triggering the event. 103 * 104 * Emits debugging. 105 * 106 * @throws \coding_exception 107 */ 108 protected function validate_before_trigger() { 109 parent::validate_before_trigger(); 110 111 debugging( 112 sprintf('%s [user %d]', $this->get_description(), $this->userid), 113 DEBUG_NONE 114 ); 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body