From d9101da79e839984e0e782b48113dc61157d6688 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 26 May 2016 20:50:50 -0400 Subject: Mark notification as read when clicking on it --- app/Controller/WebNotification.php | 50 ------------------ app/Controller/WebNotificationController.php | 79 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 50 deletions(-) delete mode 100644 app/Controller/WebNotification.php create mode 100644 app/Controller/WebNotificationController.php (limited to 'app/Controller') diff --git a/app/Controller/WebNotification.php b/app/Controller/WebNotification.php deleted file mode 100644 index a62da0e3..00000000 --- a/app/Controller/WebNotification.php +++ /dev/null @@ -1,50 +0,0 @@ -getUserId(); - - $this->userUnreadNotification->markAllAsRead($user_id); - $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); - } - - /** - * Mark a notification as read - * - * @access public - */ - public function remove() - { - $user_id = $this->getUserId(); - $notification_id = $this->request->getIntegerParam('notification_id'); - - $this->userUnreadNotification->markAsRead($user_id, $notification_id); - $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); - } - - private function getUserId() - { - $user_id = $this->request->getIntegerParam('user_id'); - - if (! $this->userSession->isAdmin() && $user_id != $this->userSession->getId()) { - $user_id = $this->userSession->getId(); - } - - return $user_id; - } -} diff --git a/app/Controller/WebNotificationController.php b/app/Controller/WebNotificationController.php new file mode 100644 index 00000000..c7b9c8ff --- /dev/null +++ b/app/Controller/WebNotificationController.php @@ -0,0 +1,79 @@ +getUserId(); + + $this->userUnreadNotification->markAllAsRead($user_id); + $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); + } + + /** + * Mark a notification as read + * + * @access public + */ + public function remove() + { + $user_id = $this->getUserId(); + $notification_id = $this->request->getIntegerParam('notification_id'); + + $this->userUnreadNotification->markAsRead($user_id, $notification_id); + $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); + } + + /** + * Redirect to the task and mark notification as read + */ + public function redirect() + { + $user_id = $this->getUserId(); + $notification_id = $this->request->getIntegerParam('notification_id'); + + $notification = $this->userUnreadNotification->getById($notification_id); + $this->userUnreadNotification->markAsRead($user_id, $notification_id); + + if (empty($notification)) { + $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); + } elseif ($this->helper->text->contains($notification['event_name'], 'comment')) { + $this->response->redirect($this->helper->url->to( + 'task', + 'show', + array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id']), + 'comment-'.$notification['event_data']['comment']['id'] + )); + } else { + $this->response->redirect($this->helper->url->to( + 'task', + 'show', + array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id']) + )); + } + } + + private function getUserId() + { + $user_id = $this->request->getIntegerParam('user_id'); + + if (! $this->userSession->isAdmin() && $user_id != $this->userSession->getId()) { + $user_id = $this->userSession->getId(); + } + + return $user_id; + } +} -- cgit v1.2.3