Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationServiceAggregator
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 8
506
0.00% covered (danger)
0.00%
0 / 1
 getSubServices
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 sendNotification
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getNotifications
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getNotification
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 changeStatus
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 notificationCount
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getVisibility
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 provideSchema
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
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) 2017 (original work) Open Assessment Technologies SA;
19 *
20 */
21
22namespace oat\tao\model\notification\implementation;
23
24use oat\generis\persistence\sql\SchemaCollection;
25use oat\generis\persistence\sql\SchemaProviderInterface;
26use oat\oatbox\service\exception\InvalidService;
27use oat\oatbox\service\exception\InvalidServiceManagerException;
28use oat\tao\model\notification\AbstractNotificationService;
29use oat\tao\model\notification\exception\NotListedNotification;
30use oat\tao\model\notification\Notification;
31use oat\tao\model\notification\NotificationServiceInterface;
32
33/**
34 * Class NotificationServiceAggregator
35 *
36 * @deprecated This class is used by client only. It will be moved to client specific extension
37 */
38class NotificationServiceAggregator extends AbstractNotificationService implements SchemaProviderInterface
39{
40    public const OPTION_RDS_NOTIFICATION_SERVICE = 'rds';
41
42    /**
43     * @throws InvalidService
44     * @throws InvalidServiceManagerException
45     */
46    public function getSubServices(): array
47    {
48        $subServices = $this->getOptions();
49        $services = [];
50        foreach ($subServices as $name => $subService) {
51            $services[] = $this->getSubService($name, NotificationServiceInterface::class);
52        }
53        return $services;
54    }
55
56    /**
57     * @throws InvalidService
58     * @throws InvalidServiceManagerException
59     */
60    public function sendNotification(Notification $notification): Notification
61    {
62        $subServices = $this->getSubServices();
63
64        /**
65         * @var NotificationServiceInterface $service
66         */
67        foreach ($subServices as $service) {
68            $service->sendNotification($notification);
69        }
70
71        return $notification;
72    }
73
74    /**
75     * @return Notification[]
76     * @throws InvalidService
77     * @throws InvalidServiceManagerException
78     * @throws NotListedNotification
79     */
80    public function getNotifications(string $userId): array
81    {
82        $subServices = $this->getSubServices();
83
84        /**
85         * @var NotificationServiceInterface $service
86         */
87        foreach ($subServices as $service) {
88            if (($list = $service->getNotifications($userId)) !== false) {
89                return $list;
90            }
91        }
92
93        throw new NotListedNotification();
94    }
95
96    /**
97     * @throws InvalidService
98     * @throws InvalidServiceManagerException
99     * @throws NotListedNotification
100     */
101    public function getNotification(string $id): Notification
102    {
103
104        $subServices = $this->getSubServices();
105
106        /**
107         * @var NotificationServiceInterface $service
108         */
109        foreach ($subServices as $service) {
110            if (($notification = $service->getNotification($id)) !== false) {
111                return $notification;
112            }
113        }
114
115        throw new NotListedNotification();
116    }
117
118    /**
119     * @throws InvalidService
120     * @throws InvalidServiceManagerException
121     * @throws NotListedNotification
122     */
123    public function changeStatus(Notification $notification): bool
124    {
125        $subServices = $this->getSubServices();
126
127        /**
128         * @var NotificationServiceInterface $service
129         */
130        foreach ($subServices as $service) {
131            if (($newNotification = $service->changeStatus($notification)) !== false) {
132                return $newNotification;
133            }
134        }
135
136        throw new NotListedNotification();
137    }
138
139    /**
140     * @throws InvalidService
141     * @throws InvalidServiceManagerException
142     * @throws NotListedNotification
143     */
144    public function notificationCount(string $userId): array
145    {
146        $subServices = $this->getSubServices();
147
148        /**
149         * @var NotificationServiceInterface $service
150         */
151        foreach ($subServices as $service) {
152            if (($newNotification = $service->notificationCount($userId)) !== false) {
153                return $newNotification;
154            }
155        }
156
157        throw new NotListedNotification();
158    }
159
160    /**
161     * @throws InvalidService
162     * @throws InvalidServiceManagerException
163     */
164    public function getVisibility(): bool
165    {
166        $subServices = $this->getSubServices();
167
168        /**
169         * @var NotificationServiceInterface $service
170         */
171        foreach ($subServices as $service) {
172            if ($service->getVisibility()) {
173                return true;
174            }
175        }
176
177        return false;
178    }
179
180    /**
181     * @throws InvalidService
182     * @throws InvalidServiceManagerException
183     */
184    public function provideSchema(SchemaCollection $schemaCollection): void
185    {
186        $subServices = $this->getSubServices();
187        foreach ($subServices as $service) {
188            if ($service instanceof SchemaProviderInterface) {
189                $service->provideSchema($schemaCollection);
190            }
191        }
192    }
193}