From 73a5b9bc75d40a30e7c9674b292957657ac01f63 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 17 Oct 2015 09:51:15 -0400 Subject: Make user notifications pluggable --- app/Controller/App.php | 2 +- app/Controller/User.php | 10 ++++---- app/Controller/WebNotification.php | 50 ++++++++++++++++++++++++++++++++++++++ app/Controller/Webnotification.php | 39 ----------------------------- 4 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 app/Controller/WebNotification.php delete mode 100644 app/Controller/Webnotification.php (limited to 'app/Controller') diff --git a/app/Controller/App.php b/app/Controller/App.php index 50ac1d32..3f3f0176 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -198,7 +198,7 @@ class App extends Base $this->response->html($this->layout('app/notifications', array( 'title' => t('My notifications'), - 'notifications' => $this->webNotification->getAll($user['id']), + 'notifications' => $this->userUnreadNotification->getAll($user['id']), 'user' => $user, ))); } diff --git a/app/Controller/User.php b/app/Controller/User.php index 15e9a0ee..7444ed82 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -96,7 +96,7 @@ class User extends Base $this->projectPermission->addMember($project_id, $user_id); if (! empty($values['notifications_enabled'])) { - $this->notificationType->saveUserSelectedTypes($user_id, array(NotificationType::TYPE_EMAIL)); + $this->userNotificationType->saveSelectedTypes($user_id, array(NotificationType::TYPE_EMAIL)); } $this->session->flash(t('User created successfully.')); @@ -201,16 +201,16 @@ class User extends Base if ($this->request->isPost()) { $values = $this->request->getValues(); - $this->notification->saveSettings($user['id'], $values); + $this->userNotification->saveSettings($user['id'], $values); $this->session->flash(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('user', 'notifications', array('user_id' => $user['id']))); } $this->response->html($this->layout('user/notifications', array( 'projects' => $this->projectPermission->getMemberProjects($user['id']), - 'notifications' => $this->notification->readSettings($user['id']), - 'types' => $this->notificationType->getTypes(), - 'filters' => $this->notificationFilter->getFilters(), + 'notifications' => $this->userNotification->readSettings($user['id']), + 'types' => $this->userNotificationType->getTypes(), + 'filters' => $this->userNotificationFilter->getFilters(), 'user' => $user, ))); } diff --git a/app/Controller/WebNotification.php b/app/Controller/WebNotification.php new file mode 100644 index 00000000..dca5cb46 --- /dev/null +++ b/app/Controller/WebNotification.php @@ -0,0 +1,50 @@ +getUserId(); + + $this->userUnreadNotification->markAllAsRead($user_id); + $this->response->redirect($this->helper->url->to('app', '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('app', '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/Webnotification.php b/app/Controller/Webnotification.php deleted file mode 100644 index 52e3f266..00000000 --- a/app/Controller/Webnotification.php +++ /dev/null @@ -1,39 +0,0 @@ -userSession->getId(); - - $this->webNotification->markAllAsRead($user_id); - $this->response->redirect($this->helper->url->to('app', 'notifications', array('user_id' => $user_id))); - } - - /** - * Mark a notification as read - * - * @access public - */ - public function remove() - { - $user_id = $this->userSession->getId(); - $notification_id = $this->request->getIntegerParam('notification_id'); - - $this->webNotification->markAsRead($user_id, $notification_id); - $this->response->redirect($this->helper->url->to('app', 'notifications', array('user_id' => $user_id))); - } -} -- cgit v1.2.3