Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| unsubscribe | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| execute_parameters | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute_returns | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 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_webpush\external; |
| 18 | |
| 19 | use core_external\external_api; |
| 20 | use core_external\external_function_parameters; |
| 21 | use core_external\external_single_structure; |
| 22 | use core_external\external_value; |
| 23 | use message_webpush\local\subscriptions; |
| 24 | |
| 25 | /** |
| 26 | * Stop sending the user's notifications to the browser they are in. |
| 27 | * |
| 28 | * @package message_webpush |
| 29 | * @copyright 2026 DevLMS |
| 30 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 31 | */ |
| 32 | class unsubscribe extends external_api { |
| 33 | /** |
| 34 | * Parameters. |
| 35 | * |
| 36 | * @return external_function_parameters |
| 37 | */ |
| 38 | public static function execute_parameters(): external_function_parameters { |
| 39 | return new external_function_parameters([ |
| 40 | 'endpoint' => new external_value(PARAM_RAW_TRIMMED, 'PushSubscription.endpoint, checked against the push service list'), |
| 41 | ]); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Remove the user's own browser. |
| 46 | * |
| 47 | * @param string $endpoint |
| 48 | * @return array |
| 49 | */ |
| 50 | public static function execute(string $endpoint): array { |
| 51 | global $USER; |
| 52 | $params = self::validate_parameters(self::execute_parameters(), ['endpoint' => $endpoint]); |
| 53 | self::validate_context(\context_system::instance()); |
| 54 | return ['removed' => subscriptions::remove_endpoint($USER->id, $params['endpoint'])]; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns. |
| 59 | * |
| 60 | * @return external_single_structure |
| 61 | */ |
| 62 | public static function execute_returns(): external_single_structure { |
| 63 | return new external_single_structure([ |
| 64 | 'removed' => new external_value(PARAM_BOOL, 'A browser of this user was removed'), |
| 65 | ]); |
| 66 | } |
| 67 | } |