From d67d7c54e65e80d1b484490e42dbecb969aa7686 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 3 Oct 2015 12:09:27 -0400 Subject: Add web notifications --- app/Controller/App.php | 16 ++++++++++++++++ app/Controller/User.php | 9 +++++++++ app/Controller/Webnotification.php | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 app/Controller/Webnotification.php (limited to 'app/Controller') diff --git a/app/Controller/App.php b/app/Controller/App.php index 80c04801..8a1a6e2b 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -187,6 +187,22 @@ class App extends Base ))); } + /** + * My notifications + * + * @access public + */ + public function notifications() + { + $user = $this->getUser(); + + $this->response->html($this->layout('app/notifications', array( + 'title' => t('My notifications'), + 'notifications' => $this->webNotification->getAll($user['id']), + 'user' => $user, + ))); + } + /** * Render Markdown text and reply with the HTML Code * diff --git a/app/Controller/User.php b/app/Controller/User.php index 04e57417..0b39619d 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -2,6 +2,8 @@ namespace Controller; +use Model\NotificationType; + /** * User controller * @@ -92,6 +94,11 @@ class User extends Base if ($user_id !== false) { $this->projectPermission->addMember($project_id, $user_id); + + if (! empty($values['notifications_enabled'])) { + $this->notificationType->saveUserSelectedTypes($user_id, array(NotificationType::TYPE_EMAIL)); + } + $this->session->flash(t('User created successfully.')); $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user_id))); } @@ -202,6 +209,8 @@ class User extends Base $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(), 'user' => $user, ))); } diff --git a/app/Controller/Webnotification.php b/app/Controller/Webnotification.php new file mode 100644 index 00000000..a481e9b8 --- /dev/null +++ b/app/Controller/Webnotification.php @@ -0,0 +1,39 @@ +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