Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AbstractNotificationService | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| sendNotifications | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| notify | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program 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 this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\notifications; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use oat\tao\model\notifiers\NotifierInterface; |
| 26 | |
| 27 | /** |
| 28 | * Notifies when an update |
| 29 | * |
| 30 | * Class AbstractNotificationService |
| 31 | * @author Andrey Niahrou <Andrei.Niahrou@1pt.com> |
| 32 | * @package oat\tao\model\extension |
| 33 | */ |
| 34 | abstract class AbstractNotificationService extends ConfigurableService |
| 35 | { |
| 36 | public const OPTION_NOTIFIERS = 'notifiers'; |
| 37 | |
| 38 | /** |
| 39 | * @param Notification $notification |
| 40 | */ |
| 41 | public function sendNotifications(Notification $notification): void |
| 42 | { |
| 43 | if (!$this->hasOption(self::OPTION_NOTIFIERS) || !count($this->getOption(self::OPTION_NOTIFIERS))) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | $notifiers = $this->getOption(self::OPTION_NOTIFIERS); |
| 48 | $this->notify($notification, $notifiers); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param Notification $notification |
| 53 | * @param array $notifiers |
| 54 | */ |
| 55 | private function notify(Notification $notification, array $notifiers): void |
| 56 | { |
| 57 | foreach ($notifiers as $notifierConfig) { |
| 58 | /**@var $notifier NotifierInterface */ |
| 59 | |
| 60 | $notifier = new $notifierConfig['class'](...$notifierConfig['params']); |
| 61 | |
| 62 | $notifier->notify($notification->getMessage(), $notification->getDescription()); |
| 63 | } |
| 64 | } |
| 65 | } |