Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| notification_undelivered | |
0.00% |
0 / 19 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 1 |
| for_user | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| init | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| get_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_description | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| get_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validate_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| get_other_mapping | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | // This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. |
| 16 | |
| 17 | namespace message_notifyhub\event; |
| 18 | |
| 19 | /** |
| 20 | * No channel delivered a notification the hub was asked to deliver. |
| 21 | * |
| 22 | * @package message_notifyhub |
| 23 | * @copyright 2026 DevLMS |
| 24 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 25 | * |
| 26 | * @property-read array $other { |
| 27 | * - string component: component that sent the notification |
| 28 | * - string name: notification type |
| 29 | * - string tried: channels tried, comma separated, empty when none was usable |
| 30 | * } |
| 31 | */ |
| 32 | class notification_undelivered extends \core\event\base { |
| 33 | /** |
| 34 | * Build the event. |
| 35 | * |
| 36 | * @param int $userid Recipient. |
| 37 | * @param string $component |
| 38 | * @param string $name |
| 39 | * @param string[] $tried |
| 40 | * @return self |
| 41 | */ |
| 42 | public static function for_user(int $userid, string $component, string $name, array $tried): self { |
| 43 | return self::create([ |
| 44 | 'context' => \context_system::instance(), |
| 45 | 'relateduserid' => $userid, |
| 46 | 'other' => ['component' => $component, 'name' => $name, 'tried' => implode(',', $tried)], |
| 47 | ]); |
| 48 | } |
| 49 | |
| 50 | #[\Override] |
| 51 | protected function init() { |
| 52 | $this->data['crud'] = 'c'; |
| 53 | $this->data['edulevel'] = self::LEVEL_OTHER; |
| 54 | } |
| 55 | |
| 56 | #[\Override] |
| 57 | public static function get_name() { |
| 58 | return get_string('event:undelivered', 'message_notifyhub'); |
| 59 | } |
| 60 | |
| 61 | #[\Override] |
| 62 | public function get_description() { |
| 63 | $tried = $this->other['tried'] === '' ? 'no channel was usable' : "tried '{$this->other['tried']}'"; |
| 64 | return "The notification hub could not deliver the notification '{$this->other['component']}/{$this->other['name']}' " . |
| 65 | "to the user with id '{$this->relateduserid}': $tried."; |
| 66 | } |
| 67 | |
| 68 | #[\Override] |
| 69 | public function get_url() { |
| 70 | return new \moodle_url('/message/output/notifyhub/index.php'); |
| 71 | } |
| 72 | |
| 73 | #[\Override] |
| 74 | protected function validate_data() { |
| 75 | parent::validate_data(); |
| 76 | if (!isset($this->relateduserid)) { |
| 77 | throw new \coding_exception('The \'relateduserid\' must be set.'); |
| 78 | } |
| 79 | foreach (['component', 'name', 'tried'] as $key) { |
| 80 | if (!isset($this->other[$key])) { |
| 81 | throw new \coding_exception("The '$key' value must be set in other."); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #[\Override] |
| 87 | public static function get_other_mapping() { |
| 88 | return false; |
| 89 | } |
| 90 | } |