Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
notification_delivered
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 7
110
0.00% covered (danger)
0.00%
0 / 1
 for_user
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 init
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 get_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_description
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 get_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validate_data
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 get_other_mapping
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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
17namespace message_notifyhub\event;
18
19/**
20 * The hub delivered a notification through one channel.
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 channel: message output that delivered it
30 * }
31 */
32class notification_delivered 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 $channel
40     * @return self
41     */
42    public static function for_user(int $userid, string $component, string $name, string $channel): self {
43        return self::create([
44            'context' => \context_system::instance(),
45            'relateduserid' => $userid,
46            'other' => ['component' => $component, 'name' => $name, 'channel' => $channel],
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:delivered', 'message_notifyhub');
59    }
60
61    #[\Override]
62    public function get_description() {
63        return "The notification hub delivered the notification '{$this->other['component']}/{$this->other['name']}' " .
64            "to the user with id '{$this->relateduserid}' through '{$this->other['channel']}'.";
65    }
66
67    #[\Override]
68    public function get_url() {
69        return new \moodle_url('/message/output/notifyhub/index.php');
70    }
71
72    #[\Override]
73    protected function validate_data() {
74        parent::validate_data();
75        if (!isset($this->relateduserid)) {
76            throw new \coding_exception('The \'relateduserid\' must be set.');
77        }
78        foreach (['component', 'name', 'channel'] as $key) {
79            if (!isset($this->other[$key])) {
80                throw new \coding_exception("The '$key' value must be set in other.");
81            }
82        }
83    }
84
85    #[\Override]
86    public static function get_other_mapping() {
87        return false;
88    }
89}