getUserService()->getCurrentUser(); /** * @var oat\tao\model\notification\NotificationServiceInterface $notificationService */ $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); try { $count = $notificationService->notificationCount($user->getUri()); } catch (NotListedNotification $e) { return $this->returnError($e->getUserMessage()); } return $this->returnJson($count); } public function getList() { $user = $this->getUserService()->getCurrentUser(); /** * @var oat\tao\model\notification\NotificationServiceInterface $notificationService */ $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); try { $list = $notificationService->getNotifications($user->getUri()); } catch (NotListedNotification $e) { return $this->returnError($e->getUserMessage()); } return $this->returnJson($list); } public function getDetail() { if ($this->hasRequestParameter('id')) { $id = $this->getRequestParameter('id'); /** * @var oat\tao\model\notification\NotificationServiceInterface $notificationService */ $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); try { $list = $notificationService->getNotification($id); } catch (NotListedNotification $e) { return $this->returnError($e->getUserMessage()); } return $this->returnJson($list); } return $this->returnError(__('require notification ID')); } public function getUiList() { $user = $this->getUserService()->getCurrentUser(); /** * @var oat\tao\model\notification\NotificationServiceInterface $notificationService */ $notificationService = $this->getServiceLocator()->get(NotificationServiceInterface::SERVICE_ID); try { $list = $notificationService->getNotifications($user->getUri()); } catch (NotListedNotification $e) { return $this->returnError($e->getUserMessage()); } /** * @var Notification $notif */ foreach ($list as $notif) { if ($notif->getStatus() === Notification::CREATED_STATUS) { $notif->setStatus(Notification::READ_STATUS); $notificationService->changeStatus($notif); $notif->setStatus(Notification::CREATED_STATUS); } } $this->setData('notif-list', $list); $this->setView('notification/list.tpl'); } /** * @return tao_models_classes_UserService */ protected function getUserService() { return $this->getServiceLocator()->get(tao_models_classes_UserService::SERVICE_ID); } }