Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_Notification | |
0.00% |
0 / 33 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
| getCount | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getList | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getDetail | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getUiList | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getUserService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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-2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\tao\model\notification\NotificationServiceInterface; |
| 23 | use oat\tao\model\notification\Notification; |
| 24 | use oat\tao\model\notification\exception\NotListedNotification; |
| 25 | |
| 26 | class tao_actions_Notification extends \tao_actions_CommonModule |
| 27 | { |
| 28 | public function getCount() |
| 29 | { |
| 30 | $user = $this->getUserService()->getCurrentUser(); |
| 31 | |
| 32 | /** |
| 33 | * @var oat\tao\model\notification\NotificationServiceInterface $notificationService |
| 34 | */ |
| 35 | $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); |
| 36 | try { |
| 37 | $count = $notificationService->notificationCount($user->getUri()); |
| 38 | } catch (NotListedNotification $e) { |
| 39 | return $this->returnError($e->getUserMessage()); |
| 40 | } |
| 41 | return $this->returnJson($count); |
| 42 | } |
| 43 | |
| 44 | public function getList() |
| 45 | { |
| 46 | $user = $this->getUserService()->getCurrentUser(); |
| 47 | |
| 48 | /** |
| 49 | * @var oat\tao\model\notification\NotificationServiceInterface $notificationService |
| 50 | */ |
| 51 | $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); |
| 52 | try { |
| 53 | $list = $notificationService->getNotifications($user->getUri()); |
| 54 | } catch (NotListedNotification $e) { |
| 55 | return $this->returnError($e->getUserMessage()); |
| 56 | } |
| 57 | return $this->returnJson($list); |
| 58 | } |
| 59 | |
| 60 | public function getDetail() |
| 61 | { |
| 62 | if ($this->hasRequestParameter('id')) { |
| 63 | $id = $this->getRequestParameter('id'); |
| 64 | /** |
| 65 | * @var oat\tao\model\notification\NotificationServiceInterface $notificationService |
| 66 | */ |
| 67 | $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); |
| 68 | try { |
| 69 | $list = $notificationService->getNotification($id); |
| 70 | } catch (NotListedNotification $e) { |
| 71 | return $this->returnError($e->getUserMessage()); |
| 72 | } |
| 73 | return $this->returnJson($list); |
| 74 | } |
| 75 | return $this->returnError(__('require notification ID')); |
| 76 | } |
| 77 | |
| 78 | public function getUiList() |
| 79 | { |
| 80 | $user = $this->getUserService()->getCurrentUser(); |
| 81 | |
| 82 | /** |
| 83 | * @var oat\tao\model\notification\NotificationServiceInterface $notificationService |
| 84 | */ |
| 85 | $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); |
| 86 | try { |
| 87 | $list = $notificationService->getNotifications($user->getUri()); |
| 88 | } catch (NotListedNotification $e) { |
| 89 | return $this->returnError($e->getUserMessage()); |
| 90 | } |
| 91 | /** |
| 92 | * @var Notification $notif |
| 93 | */ |
| 94 | foreach ($list as $notif) { |
| 95 | if ($notif->getStatus() === Notification::CREATED_STATUS) { |
| 96 | $notif->setStatus(Notification::READ_STATUS); |
| 97 | $notificationService->changeStatus($notif); |
| 98 | $notif->setStatus(Notification::CREATED_STATUS); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | $this->setData('notif-list', $list); |
| 103 | $this->setView('notification/list.tpl'); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return tao_models_classes_UserService |
| 108 | */ |
| 109 | protected function getUserService() |
| 110 | { |
| 111 | return $this->getServiceLocator()->get(tao_models_classes_UserService::SERVICE_ID); |
| 112 | } |
| 113 | } |