diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/TaskOverdueNotification.php | 2 | ||||
-rw-r--r-- | app/Controller/App.php | 16 | ||||
-rw-r--r-- | app/Controller/User.php | 9 | ||||
-rw-r--r-- | app/Controller/Webnotification.php | 39 | ||||
-rw-r--r-- | app/Core/NotificationInterface.php | 22 | ||||
-rw-r--r-- | app/Helper/Form.php | 20 | ||||
-rw-r--r-- | app/Helper/User.php | 11 | ||||
-rw-r--r-- | app/Model/EmailNotification.php | 123 | ||||
-rw-r--r-- | app/Model/Notification.php | 365 | ||||
-rw-r--r-- | app/Model/NotificationFilter.php | 199 | ||||
-rw-r--r-- | app/Model/NotificationType.php | 73 | ||||
-rw-r--r-- | app/Model/OverdueNotification.php | 60 | ||||
-rw-r--r-- | app/Model/WebNotification.php | 156 | ||||
-rw-r--r-- | app/Schema/Mysql.php | 39 | ||||
-rw-r--r-- | app/Schema/Postgres.php | 37 | ||||
-rw-r--r-- | app/Schema/Sqlite.php | 37 | ||||
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 5 | ||||
-rw-r--r-- | app/Template/app/notifications.php | 61 | ||||
-rw-r--r-- | app/Template/app/sidebar.php | 3 | ||||
-rw-r--r-- | app/Template/header.php | 4 | ||||
-rw-r--r-- | app/Template/user/create_local.php | 2 | ||||
-rw-r--r-- | app/Template/user/create_remote.php | 2 | ||||
-rw-r--r-- | app/Template/user/notifications.php | 27 | ||||
-rw-r--r-- | app/Template/user/sidebar.php | 2 |
24 files changed, 998 insertions, 316 deletions
diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php index 3d254ae4..2428ad35 100644 --- a/app/Console/TaskOverdueNotification.php +++ b/app/Console/TaskOverdueNotification.php @@ -19,7 +19,7 @@ class TaskOverdueNotification extends Base protected function execute(InputInterface $input, OutputInterface $output) { - $tasks = $this->notification->sendOverdueTaskNotifications(); + $tasks = $this->overdueNotification->sendOverdueTaskNotifications(); if ($input->getOption('show')) { $this->showTable($output, $tasks); 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 @@ -188,6 +188,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 * * @access public 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 @@ +<?php + +namespace Controller; + +/** + * Web notification controller + * + * @package controller + * @author Frederic Guillot + */ +class Webnotification extends Base +{ + /** + * Mark all notifications as read + * + * @access public + */ + public function flush() + { + $user_id = $this->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))); + } +} diff --git a/app/Core/NotificationInterface.php b/app/Core/NotificationInterface.php new file mode 100644 index 00000000..5dca74e5 --- /dev/null +++ b/app/Core/NotificationInterface.php @@ -0,0 +1,22 @@ +<?php + +namespace Core; + +/** + * Notification Interface + * + * @package core + * @author Frederic Guillot + */ +interface NotificationInterface +{ + /** + * Send notification to someone + * + * @access public + * @param array $user + * @param string $event_name + * @param array $event_data + */ + public function send(array $user, $event_name, array $event_data); +} diff --git a/app/Helper/Form.php b/app/Helper/Form.php index 83e3b113..a37cc81a 100644 --- a/app/Helper/Form.php +++ b/app/Helper/Form.php @@ -104,6 +104,26 @@ class Form extends \Core\Base } /** + * Display a checkboxes group + * + * @access public + * @param string $name Field name + * @param array $options Options + * @param array $values Form values + * @return string + */ + public function checkboxes($name, array $options, array $values = array()) + { + $html = ''; + + foreach ($options as $value => $label) { + $html .= $this->checkbox($name.'['.$value.']', $label, $value, isset($values[$name]) && in_array($value, $values[$name])); + } + + return $html; + } + + /** * Display a checkbox field * * @access public diff --git a/app/Helper/User.php b/app/Helper/User.php index 3108a79a..6b7d6f73 100644 --- a/app/Helper/User.php +++ b/app/Helper/User.php @@ -11,6 +11,17 @@ namespace Helper; class User extends \Core\Base { /** + * Return true if the logged user as unread notifications + * + * @access public + * @return boolean + */ + public function hasNotifications() + { + return $this->webNotification->hasNotifications($this->userSession->getId()); + } + + /** * Get initials from a user * * @access public diff --git a/app/Model/EmailNotification.php b/app/Model/EmailNotification.php new file mode 100644 index 00000000..39b60fc1 --- /dev/null +++ b/app/Model/EmailNotification.php @@ -0,0 +1,123 @@ +<?php + +namespace Model; + +use Core\NotificationInterface; + +/** + * Email Notification model + * + * @package model + * @author Frederic Guillot + */ +class EmailNotification extends Base implements NotificationInterface +{ + /** + * Send email notification to someone + * + * @access public + * @param array $user + * @param string $event_name + * @param array $event_data + */ + public function send(array $user, $event_name, array $event_data) + { + if (! empty($user['email'])) { + $this->emailClient->send( + $user['email'], + $user['name'] ?: $user['username'], + $this->getMailSubject($event_name, $event_data), + $this->getMailContent($event_name, $event_data) + ); + } + } + + /** + * Get the mail content for a given template name + * + * @access public + * @param string $event_name Event name + * @param array $event_data Event data + * @return string + */ + public function getMailContent($event_name, array $event_data) + { + return $this->template->render( + 'notification/'.str_replace('.', '_', $event_name), + $event_data + array('application_url' => $this->config->get('application_url')) + ); + } + + /** + * Get the mail subject for a given template name + * + * @access public + * @param string $event_name Event name + * @param array $event_data Event data + * @return string + */ + public function getMailSubject($event_name, array $event_data) + { + switch ($event_name) { + case File::EVENT_CREATE: + $subject = $this->getStandardMailSubject(e('New attachment'), $event_data); + break; + case Comment::EVENT_CREATE: + $subject = $this->getStandardMailSubject(e('New comment'), $event_data); + break; + case Comment::EVENT_UPDATE: + $subject = $this->getStandardMailSubject(e('Comment updated'), $event_data); + break; + case Subtask::EVENT_CREATE: + $subject = $this->getStandardMailSubject(e('New subtask'), $event_data); + break; + case Subtask::EVENT_UPDATE: + $subject = $this->getStandardMailSubject(e('Subtask updated'), $event_data); + break; + case Task::EVENT_CREATE: + $subject = $this->getStandardMailSubject(e('New task'), $event_data); + break; + case Task::EVENT_UPDATE: + $subject = $this->getStandardMailSubject(e('Task updated'), $event_data); + break; + case Task::EVENT_CLOSE: + $subject = $this->getStandardMailSubject(e('Task closed'), $event_data); + break; + case Task::EVENT_OPEN: + $subject = $this->getStandardMailSubject(e('Task opened'), $event_data); + break; + case Task::EVENT_MOVE_COLUMN: + $subject = $this->getStandardMailSubject(e('Column change'), $event_data); + break; + case Task::EVENT_MOVE_POSITION: + $subject = $this->getStandardMailSubject(e('Position change'), $event_data); + break; + case Task::EVENT_MOVE_SWIMLANE: + $subject = $this->getStandardMailSubject(e('Swimlane change'), $event_data); + break; + case Task::EVENT_ASSIGNEE_CHANGE: + $subject = $this->getStandardMailSubject(e('Assignee change'), $event_data); + break; + case Task::EVENT_OVERDUE: + $subject = e('[%s] Overdue tasks', $event_data['project_name']); + break; + default: + $subject = e('Notification'); + } + + return $subject; + } + + /** + * Get the mail subject for a given label + * + * @access private + * @param string $label Label + * @param array $data Template data + * @return string + */ + private function getStandardMailSubject($label, array $data) + { + return sprintf('[%s][%s] %s (#%d)', $data['task']['project_name'], $label, $data['task']['title'], $data['task']['id']); + } +} diff --git a/app/Model/Notification.php b/app/Model/Notification.php index 9628e344..dbd60a2f 100644 --- a/app/Model/Notification.php +++ b/app/Model/Notification.php @@ -13,71 +13,6 @@ use Core\Translator; class Notification extends Base { /** - * SQL table name - * - * @var string - */ - const TABLE = 'user_has_notifications'; - - /** - * User filters - * - * @var integer - */ - const FILTER_NONE = 1; - const FILTER_ASSIGNEE = 2; - const FILTER_CREATOR = 3; - const FILTER_BOTH = 4; - - /** - * Send overdue tasks - * - * @access public - */ - public function sendOverdueTaskNotifications() - { - $tasks = $this->taskFinder->getOverdueTasks(); - - foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - - // Get the list of users that should receive notifications for each projects - $users = $this->notification->getUsersWithNotificationEnabled($project_id); - - foreach ($users as $user) { - $this->sendUserOverdueTaskNotifications($user, $project_tasks); - } - } - - return $tasks; - } - - /** - * Send overdue tasks for a given user - * - * @access public - * @param array $user - * @param array $tasks - */ - public function sendUserOverdueTaskNotifications(array $user, array $tasks) - { - $user_tasks = array(); - - foreach ($tasks as $task) { - if ($this->notification->shouldReceiveNotification($user, array('task' => $task))) { - $user_tasks[] = $task; - } - } - - if (! empty($user_tasks)) { - $this->sendEmailNotification( - $user, - Task::EVENT_OVERDUE, - array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) - ); - } - } - - /** * Send notifications to people * * @access public @@ -89,26 +24,31 @@ class Notification extends Base $logged_user_id = $this->userSession->isLogged() ? $this->userSession->getId() : 0; $users = $this->notification->getUsersWithNotificationEnabled($event_data['task']['project_id'], $logged_user_id); - foreach ($users as $user) { - if ($this->shouldReceiveNotification($user, $event_data)) { - $this->sendEmailNotification($user, $event_name, $event_data); + if (! empty($users)) { + + foreach ($users as $user) { + if ($this->notificationFilter->shouldReceiveNotification($user, $event_data)) { + $this->sendUserNotification($user, $event_name, $event_data); + } } - } - // Restore locales - $this->config->setupTranslations(); + // Restore locales + $this->config->setupTranslations(); + } } /** - * Send email notification to someone + * Send notification to someone * * @access public * @param array $user User * @param string $event_name * @param array $event_data */ - public function sendEmailNotification(array $user, $event_name, array $event_data) + public function sendUserNotification(array $user, $event_name, array $event_data) { + Translator::unload(); + // Use the user language otherwise use the application language (do not use the session language) if (! empty($user['language'])) { Translator::load($user['language']); @@ -117,288 +57,131 @@ class Notification extends Base Translator::load($this->config->get('application_language', 'en_US')); } - $this->emailClient->send( - $user['email'], - $user['name'] ?: $user['username'], - $this->getMailSubject($event_name, $event_data), - $this->getMailContent($event_name, $event_data) - ); + foreach ($this->notificationType->getUserSelectedTypes($user['id']) as $type) { + $className = strtolower($type).'Notification'; + $this->$className->send($user, $event_name, $event_data); + } } /** - * Return true if the user should receive notification + * Get a list of people with notifications enabled * * @access public - * @param array $user - * @param array $event_data - * @return boolean + * @param integer $project_id Project id + * @param integer $exclude_user_id User id to exclude + * @return array */ - public function shouldReceiveNotification(array $user, array $event_data) + public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) { - $filters = array( - 'filterNone', - 'filterAssignee', - 'filterCreator', - 'filterBoth', - ); - - foreach ($filters as $filter) { - if ($this->$filter($user, $event_data)) { - return $this->filterProject($user, $event_data); - } + if ($this->projectPermission->isEverybodyAllowed($project_id)) { + return $this->getEverybodyWithNotificationEnabled($exclude_user_id); } - return false; + return $this->getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id); } /** - * Return true if the user will receive all notifications + * Enable notification for someone * * @access public - * @param array $user + * @param integer $user_id * @return boolean */ - public function filterNone(array $user) + public function enableNotification($user_id) { - return $user['notifications_filter'] == self::FILTER_NONE; + return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 1)); } /** - * Return true if the user is the assignee and selected the filter "assignee" + * Disable notification for someone * * @access public - * @param array $user - * @param array $event_data + * @param integer $user_id * @return boolean */ - public function filterAssignee(array $user, array $event_data) + public function disableNotification($user_id) { - return $user['notifications_filter'] == self::FILTER_ASSIGNEE && $event_data['task']['owner_id'] == $user['id']; + return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 0)); } /** - * Return true if the user is the creator and enabled the filter "creator" + * Save settings for the given user * * @access public - * @param array $user - * @param array $event_data - * @return boolean + * @param integer $user_id User id + * @param array $values Form values */ - public function filterCreator(array $user, array $event_data) + public function saveSettings($user_id, array $values) { - return $user['notifications_filter'] == self::FILTER_CREATOR && $event_data['task']['creator_id'] == $user['id']; - } + // $this->db->startTransaction(); - /** - * Return true if the user is the assignee or the creator and selected the filter "both" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterBoth(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_BOTH && - ($event_data['task']['creator_id'] == $user['id'] || $event_data['task']['owner_id'] == $user['id']); + if (isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1) { + $this->enableNotification($user_id); + + $filter = empty($values['notifications_filter']) ? NotificationFilter::FILTER_BOTH : $values['notifications_filter']; + $projects = empty($values['notification_projects']) ? array() : array_keys($values['notification_projects']); + $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); + + $this->notificationFilter->saveUserFilter($user_id, $filter); + $this->notificationFilter->saveUserSelectedProjects($user_id, $projects); + $this->notificationType->saveUserSelectedTypes($user_id, $types); + } + else { + $this->disableNotification($user_id); + } + + // $this->db->closeTransaction(); } /** - * Return true if the user want to receive notification for the selected project + * Read user settings to display the form * * @access public - * @param array $user - * @param array $event_data - * @return boolean + * @param integer $user_id User id + * @return array */ - public function filterProject(array $user, array $event_data) + public function readSettings($user_id) { - $projects = $this->db->table(self::TABLE)->eq('user_id', $user['id'])->findAllByColumn('project_id'); - - if (! empty($projects)) { - return in_array($event_data['task']['project_id'], $projects); - } - - return true; + $values = $this->db->table(User::TABLE)->eq('id', $user_id)->columns('notifications_enabled', 'notifications_filter')->findOne(); + $values['notification_types'] = $this->notificationType->getUserSelectedTypes($user_id); + $values['notification_projects'] = $this->notificationFilter->getUserSelectedProjects($user_id); + return $values; } /** - * Get a list of people with notifications enabled + * Get a list of project members with notification enabled * - * @access public + * @access private * @param integer $project_id Project id * @param integer $exclude_user_id User id to exclude * @return array */ - public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) + private function getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id) { - if ($this->projectPermission->isEverybodyAllowed($project_id)) { - - return $this->db - ->table(User::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') - ->eq('notifications_enabled', '1') - ->neq('email', '') - ->neq(User::TABLE.'.id', $exclude_user_id) - ->findAll(); - } - return $this->db ->table(ProjectPermission::TABLE) ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') ->join(User::TABLE, 'id', 'user_id') ->eq('project_id', $project_id) ->eq('notifications_enabled', '1') - ->neq('email', '') ->neq(User::TABLE.'.id', $exclude_user_id) ->findAll(); } /** - * Get the mail content for a given template name - * - * @access public - * @param string $event_name Event name - * @param array $event_data Event data - * @return string - */ - public function getMailContent($event_name, array $event_data) - { - return $this->template->render( - 'notification/'.str_replace('.', '_', $event_name), - $event_data + array('application_url' => $this->config->get('application_url')) - ); - } - - /** - * Get the mail subject for a given template name - * - * @access public - * @param string $event_name Event name - * @param array $event_data Event data - * @return string - */ - public function getMailSubject($event_name, array $event_data) - { - switch ($event_name) { - case File::EVENT_CREATE: - $subject = $this->getStandardMailSubject(e('New attachment'), $event_data); - break; - case Comment::EVENT_CREATE: - $subject = $this->getStandardMailSubject(e('New comment'), $event_data); - break; - case Comment::EVENT_UPDATE: - $subject = $this->getStandardMailSubject(e('Comment updated'), $event_data); - break; - case Subtask::EVENT_CREATE: - $subject = $this->getStandardMailSubject(e('New subtask'), $event_data); - break; - case Subtask::EVENT_UPDATE: - $subject = $this->getStandardMailSubject(e('Subtask updated'), $event_data); - break; - case Task::EVENT_CREATE: - $subject = $this->getStandardMailSubject(e('New task'), $event_data); - break; - case Task::EVENT_UPDATE: - $subject = $this->getStandardMailSubject(e('Task updated'), $event_data); - break; - case Task::EVENT_CLOSE: - $subject = $this->getStandardMailSubject(e('Task closed'), $event_data); - break; - case Task::EVENT_OPEN: - $subject = $this->getStandardMailSubject(e('Task opened'), $event_data); - break; - case Task::EVENT_MOVE_COLUMN: - $subject = $this->getStandardMailSubject(e('Column change'), $event_data); - break; - case Task::EVENT_MOVE_POSITION: - $subject = $this->getStandardMailSubject(e('Position change'), $event_data); - break; - case Task::EVENT_MOVE_SWIMLANE: - $subject = $this->getStandardMailSubject(e('Swimlane change'), $event_data); - break; - case Task::EVENT_ASSIGNEE_CHANGE: - $subject = $this->getStandardMailSubject(e('Assignee change'), $event_data); - break; - case Task::EVENT_OVERDUE: - $subject = e('[%s] Overdue tasks', $event_data['project_name']); - break; - default: - $subject = e('Notification'); - } - - return $subject; - } - - /** - * Get the mail subject for a given label + * Get a list of project members with notification enabled * * @access private - * @param string $label Label - * @param array $data Template data - * @return string - */ - private function getStandardMailSubject($label, array $data) - { - return sprintf('[%s][%s] %s (#%d)', $data['task']['project_name'], $label, $data['task']['title'], $data['task']['id']); - } - - /** - * Save settings for the given user - * - * @access public - * @param integer $user_id User id - * @param array $values Form values - */ - public function saveSettings($user_id, array $values) - { - // Delete all selected projects - $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); - - if (isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1) { - - // Activate notifications - $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( - 'notifications_enabled' => '1', - 'notifications_filter' => empty($values['notifications_filter']) ? self::FILTER_BOTH : $values['notifications_filter'], - )); - - // Save selected projects - if (! empty($values['projects'])) { - - foreach ($values['projects'] as $project_id => $checkbox_value) { - $this->db->table(self::TABLE)->insert(array( - 'user_id' => $user_id, - 'project_id' => $project_id, - )); - } - } - } - else { - - // Disable notifications - $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( - 'notifications_enabled' => '0' - )); - } - } - - /** - * Read user settings to display the form - * - * @access public - * @param integer $user_id User id + * @param integer $exclude_user_id User id to exclude * @return array */ - public function readSettings($user_id) + private function getEverybodyWithNotificationEnabled($exclude_user_id) { - $values = $this->db->table(User::TABLE)->eq('id', $user_id)->columns('notifications_enabled', 'notifications_filter')->findOne(); - $projects = $this->db->table(self::TABLE)->eq('user_id', $user_id)->findAllByColumn('project_id'); - - foreach ($projects as $project_id) { - $values['project_'.$project_id] = true; - } - - return $values; + return $this->db + ->table(User::TABLE) + ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') + ->eq('notifications_enabled', '1') + ->neq(User::TABLE.'.id', $exclude_user_id) + ->findAll(); } } diff --git a/app/Model/NotificationFilter.php b/app/Model/NotificationFilter.php new file mode 100644 index 00000000..62795512 --- /dev/null +++ b/app/Model/NotificationFilter.php @@ -0,0 +1,199 @@ +<?php + +namespace Model; + +/** + * Notification Filter model + * + * @package model + * @author Frederic Guillot + */ +class NotificationFilter extends Base +{ + /** + * SQL table name + * + * @var string + */ + const PROJECT_TABLE = 'user_has_notifications'; + + /** + * User filters + * + * @var integer + */ + const FILTER_NONE = 1; + const FILTER_ASSIGNEE = 2; + const FILTER_CREATOR = 3; + const FILTER_BOTH = 4; + + /** + * Get the list of filters + * + * @access public + * @return array + */ + public function getFilters() + { + return array( + self::FILTER_NONE => t('All tasks'), + self::FILTER_ASSIGNEE => t('Only for tasks assigned to me'), + self::FILTER_CREATOR => t('Only for tasks created by me'), + self::FILTER_BOTH => t('Only for tasks created by me and assigned to me'), + ); + } + + /** + * Get user selected filter + * + * @access public + * @param integer $user_id + * @return integer + */ + public function getUserSelectedFilter($user_id) + { + return $this->db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); + } + + /** + * Save selected filter for a user + * + * @access public + * @param integer $user_id + * @param string $filter + */ + public function saveUserFilter($user_id, $filter) + { + $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( + 'notifications_filter' => $filter, + )); + } + + /** + * Get user selected projects + * + * @access public + * @param integer $user_id + * @return array + */ + public function getUserSelectedProjects($user_id) + { + return $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->findAllByColumn('project_id'); + } + + /** + * Save selected projects for a user + * + * @access public + * @param integer $user_id + * @param integer[] $project_ids + */ + public function saveUserSelectedProjects($user_id, array $project_ids) + { + $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove(); + + foreach ($project_ids as $project_id) { + $this->db->table(self::PROJECT_TABLE)->insert(array( + 'user_id' => $user_id, + 'project_id' => $project_id, + )); + } + } + + /** + * Return true if the user should receive notification + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function shouldReceiveNotification(array $user, array $event_data) + { + $filters = array( + 'filterNone', + 'filterAssignee', + 'filterCreator', + 'filterBoth', + ); + + foreach ($filters as $filter) { + if ($this->$filter($user, $event_data)) { + return $this->filterProject($user, $event_data); + } + } + + return false; + } + + /** + * Return true if the user will receive all notifications + * + * @access public + * @param array $user + * @return boolean + */ + public function filterNone(array $user) + { + return $user['notifications_filter'] == self::FILTER_NONE; + } + + /** + * Return true if the user is the assignee and selected the filter "assignee" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterAssignee(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_ASSIGNEE && $event_data['task']['owner_id'] == $user['id']; + } + + /** + * Return true if the user is the creator and enabled the filter "creator" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterCreator(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_CREATOR && $event_data['task']['creator_id'] == $user['id']; + } + + /** + * Return true if the user is the assignee or the creator and selected the filter "both" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterBoth(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_BOTH && + ($event_data['task']['creator_id'] == $user['id'] || $event_data['task']['owner_id'] == $user['id']); + } + + /** + * Return true if the user want to receive notification for the selected project + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterProject(array $user, array $event_data) + { + $projects = $this->getUserSelectedProjects($user['id']); + + if (! empty($projects)) { + return in_array($event_data['task']['project_id'], $projects); + } + + return true; + } +} diff --git a/app/Model/NotificationType.php b/app/Model/NotificationType.php new file mode 100644 index 00000000..3fd5c157 --- /dev/null +++ b/app/Model/NotificationType.php @@ -0,0 +1,73 @@ +<?php + +namespace Model; + +/** + * Notification Type model + * + * @package model + * @author Frederic Guillot + */ +class NotificationType extends Base +{ + /** + * SQL table name + * + * @var string + */ + const TABLE = 'user_has_notification_types'; + + /** + * Types + * + * @var string + */ + const TYPE_WEB = 'web'; + const TYPE_EMAIL = 'email'; + + /** + * Get all notification types + * + * @access public + * @return array + */ + public function getTypes() + { + return array( + self::TYPE_EMAIL => t('Email'), + self::TYPE_WEB => t('Web'), + ); + } + + /** + * Get selected notification types for a given user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getUserSelectedTypes($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type'); + } + + /** + * Save notification types for a given user + * + * @access public + * @param integer $user_id + * @param string[] $types + * @return boolean + */ + public function saveUserSelectedTypes($user_id, array $types) + { + $results = array(); + $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); + + foreach ($types as $type) { + $results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type)); + } + + return ! in_array(false, $results); + } +} diff --git a/app/Model/OverdueNotification.php b/app/Model/OverdueNotification.php new file mode 100644 index 00000000..19bd0987 --- /dev/null +++ b/app/Model/OverdueNotification.php @@ -0,0 +1,60 @@ +<?php + +namespace Model; + +/** + * Task Overdue Notification model + * + * @package model + * @author Frederic Guillot + */ +class OverdueNotification extends Base +{ + /** + * Send overdue tasks + * + * @access public + */ + public function sendOverdueTaskNotifications() + { + $tasks = $this->taskFinder->getOverdueTasks(); + + foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { + + // Get the list of users that should receive notifications for each projects + $users = $this->notification->getUsersWithNotificationEnabled($project_id); + + foreach ($users as $user) { + $this->sendUserOverdueTaskNotifications($user, $project_tasks); + } + } + + return $tasks; + } + + /** + * Send overdue tasks for a given user + * + * @access public + * @param array $user + * @param array $tasks + */ + public function sendUserOverdueTaskNotifications(array $user, array $tasks) + { + $user_tasks = array(); + + foreach ($tasks as $task) { + if ($this->notificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + $user_tasks[] = $task; + } + } + + if (! empty($user_tasks)) { + $this->notification->sendUserNotification( + $user, + Task::EVENT_OVERDUE, + array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) + ); + } + } +} diff --git a/app/Model/WebNotification.php b/app/Model/WebNotification.php new file mode 100644 index 00000000..4f4e8afb --- /dev/null +++ b/app/Model/WebNotification.php @@ -0,0 +1,156 @@ +<?php + +namespace Model; + +use Core\NotificationInterface; + +/** + * Web Notification model + * + * @package model + * @author Frederic Guillot + */ +class WebNotification extends Base implements NotificationInterface +{ + /** + * SQL table name + * + * @var string + */ + const TABLE = 'user_has_unread_notifications'; + + /** + * Add unread notification to someone + * + * @access public + * @param array $user + * @param string $event_name + * @param array $event_data + */ + public function send(array $user, $event_name, array $event_data) + { + $this->db->table(self::TABLE)->insert(array( + 'user_id' => $user['id'], + 'date_creation' => time(), + 'event_name' => $event_name, + 'event_data' => json_encode($event_data), + )); + } + + /** + * Get all notifications for a user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getAll($user_id) + { + $events = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('date_creation')->findAll(); + + foreach ($events as &$event) { + $event['event_data'] = json_decode($event['event_data'], true); + $event['title'] = $this->getTitleFromEvent($event['event_name'], $event['event_data']); + } + + return $events; + } + + /** + * Mark a notification as read + * + * @access public + * @param integer $user_id + * @param integer $notification_id + * @return boolean + */ + public function markAsRead($user_id, $notification_id) + { + return $this->db->table(self::TABLE)->eq('id', $notification_id)->eq('user_id', $user_id)->remove(); + } + + /** + * Mark all notifications as read for a user + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function markAllAsRead($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); + } + + /** + * Return true if the user as unread notifications + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasNotifications($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists(); + } + + /** + * Get title from event + * + * @access public + * @param string $event_name + * @param array $event_data + * @return string + */ + public function getTitleFromEvent($event_name, array $event_data) + { + switch ($event_name) { + case File::EVENT_CREATE: + $title = t('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']); + break; + case Comment::EVENT_CREATE: + $title = t('New comment on task #%d', $event_data['comment']['task_id']); + break; + case Comment::EVENT_UPDATE: + $title = t('Comment updated on task #%d', $event_data['comment']['task_id']); + break; + case Subtask::EVENT_CREATE: + $title = t('New subtask on task #%d', $event_data['subtask']['task_id']); + break; + case Subtask::EVENT_UPDATE: + $title = t('Subtask updated on task #%d', $event_data['subtask']['task_id']); + break; + case Task::EVENT_CREATE: + $title = t('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']); + break; + case Task::EVENT_UPDATE: + $title = t('Task updated #%d', $event_data['task']['id']); + break; + case Task::EVENT_CLOSE: + $title = t('Task #%d closed', $event_data['task']['id']); + break; + case Task::EVENT_OPEN: + $title = t('Task #%d opened', $event_data['task']['id']); + break; + case Task::EVENT_MOVE_COLUMN: + $title = t('Column changed for task #%d', $event_data['task']['id']); + break; + case Task::EVENT_MOVE_POSITION: + $title = t('New position for task #%d', $event_data['task']['id']); + break; + case Task::EVENT_MOVE_SWIMLANE: + $title = t('Swimlane changed for task #%d', $event_data['task']['id']); + break; + case Task::EVENT_ASSIGNEE_CHANGE: + $title = t('Assignee changed on task #%d', $event_data['task']['id']); + break; + case Task::EVENT_OVERDUE: + $nb = count($event_data['tasks']); + $title = $nb > 1 ? t('%d overdue tasks', $nb) : t('Task #%d is overdue', $event_data['tasks'][0]['id']); + break; + default: + $title = e('Notification'); + } + + return $title; + } +} diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index a1cef344..92225279 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,44 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 88; +const VERSION = 89; + +function version_89($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, + date_creation BIGINT NOT NULL, + event_name VARCHAR(50) NOT NULL, + event_data TEXT NOT NULL, + PRIMARY KEY(id), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8 + "); + + $pdo->exec(" + CREATE TABLE user_has_notification_types ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, + notification_type VARCHAR(50), + PRIMARY KEY(id), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8 + "); + + $pdo->exec('CREATE UNIQUE INDEX user_has_notification_types_user_idx ON user_has_notification_types(user_id, notification_type)'); + + // Migrate people who have notification enabled before + $rq = $pdo->prepare('SELECT id FROM users WHERE notifications_enabled=1'); + $rq->execute(); + $user_ids = $rq->fetchAll(PDO::FETCH_COLUMN, 0); + + foreach ($user_ids as $user_id) { + $rq = $pdo->prepare('INSERT INTO user_has_notification_types (user_id, notification_type) VALUES (?, ?)'); + $rq->execute(array($user_id, 'email')); + } +} function version_88($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index f7263e75..d55297a9 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,42 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 68; +const VERSION = 69; + +function version_69($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL, + date_creation BIGINT NOT NULL, + event_name VARCHAR(50) NOT NULL, + event_data TEXT NOT NULL, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec(" + CREATE TABLE user_has_notification_types ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL, + notification_type VARCHAR(50), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec('CREATE UNIQUE INDEX user_has_notification_types_user_idx ON user_has_notification_types(user_id, notification_type)'); + + // Migrate people who have notification enabled before + $rq = $pdo->prepare('SELECT id FROM users WHERE notifications_enabled=1'); + $rq->execute(); + $user_ids = $rq->fetchAll(PDO::FETCH_COLUMN, 0); + + foreach ($user_ids as $user_id) { + $rq = $pdo->prepare('INSERT INTO user_has_notification_types (user_id, notification_type) VALUES (?, ?)'); + $rq->execute(array($user_id, 'email')); + } +} function version_68($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 064d0f3c..633c90a7 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -6,7 +6,42 @@ use Core\Security; use PDO; use Model\Link; -const VERSION = 84; +const VERSION = 85; + +function version_85($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + date_creation INTEGER NOT NULL, + event_name TEXT NOT NULL, + event_data TEXT NOT NULL, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec(" + CREATE TABLE user_has_notification_types ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + notification_type TEXT, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec('CREATE UNIQUE INDEX user_has_notification_types_user_idx ON user_has_notification_types(user_id, notification_type)'); + + // Migrate people who have notification enabled before + $rq = $pdo->prepare('SELECT id FROM users WHERE notifications_enabled=1'); + $rq->execute(); + $user_ids = $rq->fetchAll(PDO::FETCH_COLUMN, 0); + + foreach ($user_ids as $user_id) { + $rq = $pdo->prepare('INSERT INTO user_has_notification_types (user_id, notification_type) VALUES (?, ?)'); + $rq->execute(array($user_id, 'email')); + } +} function version_84($pdo) { diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index b671dace..8a959638 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -33,6 +33,11 @@ class ClassProvider implements ServiceProviderInterface 'LastLogin', 'Link', 'Notification', + 'NotificationType', + 'NotificationFilter', + 'OverdueNotification', + 'WebNotification', + 'EmailNotification', 'Project', 'ProjectActivity', 'ProjectAnalytic', diff --git a/app/Template/app/notifications.php b/app/Template/app/notifications.php new file mode 100644 index 00000000..4f7dd353 --- /dev/null +++ b/app/Template/app/notifications.php @@ -0,0 +1,61 @@ +<div class="page-header"> + <h2><?= t('My notifications') ?></h2> + +<?php if (empty($notifications)): ?> + <p class="alert"><?= t('No new notifications.') ?></p> +</div> +<?php else: ?> + <ul> + <li> + <i class="fa fa-check-square-o fa-fw"></i> + <?= $this->url->link(t('Mark all as read'), 'webnotification', 'flush', array('user_id' => $user['id'])) ?> + </li> + </ul> +</div> + + <table class="table-fixed table-small"> + <tr> + <th><?= t('Notification') ?></th> + <th class="column-20"><?= t('Date') ?></th> + <th class="column-15"><?= t('Action') ?></th> + </tr> + <?php foreach ($notifications as $notification): ?> + <tr> + <td> + <?php if ($this->text->contains($notification['event_name'], 'subtask')): ?> + <i class="fa fa-tasks fa-fw"></i> + <?php elseif ($this->text->contains($notification['event_name'], 'task.move')): ?> + <i class="fa fa-arrows-alt fa-fw"></i> + <?php elseif ($this->text->contains($notification['event_name'], 'task.overdue')): ?> + <i class="fa fa-calendar-times-o fa-fw"></i> + <?php elseif ($this->text->contains($notification['event_name'], 'task')): ?> + <i class="fa fa-newspaper-o fa-fw"></i> + <?php elseif ($this->text->contains($notification['event_name'], 'comment')): ?> + <i class="fa fa-comments-o fa-fw"></i> + <?php elseif ($this->text->contains($notification['event_name'], 'file')): ?> + <i class="fa fa-file-o fa-fw"></i> + <?php endif ?> + + <?php if ($this->text->contains($notification['event_name'], 'comment')): ?> + <?= $this->url->link($notification['title'], 'task', 'show', array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id']), false, '', '', false, 'comment-'.$notification['event_data']['comment']['id']) ?> + <?php elseif ($this->text->contains($notification['event_name'], 'task.overdue')): ?> + <?php if (count($notification['event_data']['tasks']) > 1): ?> + <?= $notification['title'] ?> + <?php else: ?> + <?= $this->url->link($notification['title'], 'task', 'show', array('task_id' => $notification['event_data']['tasks'][0]['id'], 'project_id' => $notification['event_data']['tasks'][0]['project_id'])) ?> + <?php endif ?> + <?php else: ?> + <?= $this->url->link($notification['title'], 'task', 'show', array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id'])) ?> + <?php endif ?> + </td> + <td> + <?= dt('%B %e, %Y at %k:%M %p', $notification['date_creation']) ?> + </td> + <td> + <i class="fa fa-check fa-fw"></i> + <?= $this->url->link(t('Mark as read'), 'webnotification', 'remove', array('user_id' => $user['id'], 'notification_id' => $notification['id'])) ?> + </td> + </tr> + <?php endforeach ?> + </table> +<?php endif ?>
\ No newline at end of file diff --git a/app/Template/app/sidebar.php b/app/Template/app/sidebar.php index c1de0dbe..552a9c27 100644 --- a/app/Template/app/sidebar.php +++ b/app/Template/app/sidebar.php @@ -19,6 +19,9 @@ <li <?= $this->app->getRouterAction() === 'activity' ? 'class="active"' : '' ?>> <?= $this->url->link(t('My activity stream'), 'app', 'activity', array('user_id' => $user['id'])) ?> </li> + <li <?= $this->app->getRouterAction() === 'notifications' ? 'class="active"' : '' ?>> + <?= $this->url->link(t('My notifications'), 'app', 'notifications', array('user_id' => $user['id'])) ?> + </li> <?= $this->hook->render('template:dashboard:sidebar') ?> </ul> <div class="sidebar-collapse"><a href="#" title="<?= t('Hide sidebar') ?>"><i class="fa fa-chevron-left"></i></a></div> diff --git a/app/Template/header.php b/app/Template/header.php index 0bcfdbbc..19ffbbf5 100644 --- a/app/Template/header.php +++ b/app/Template/header.php @@ -25,6 +25,10 @@ </li> <?php endif ?> <li> + <?php if ($this->user->hasNotifications()): ?> + <?= $this->url->link('<i class="fa fa-bell web-notification-icon"></i>', 'app', 'notifications', array('user_id' => $this->user->getId()), false, '', t('Unread notifications')) ?> + <?php endif ?> + <?= $this->url->link(t('Logout'), 'auth', 'logout') ?> <span class="username hide-tablet">(<?= $this->user->getProfileLink() ?>)</span> </li> diff --git a/app/Template/user/create_local.php b/app/Template/user/create_local.php index 3c8b43b0..98c38f0d 100644 --- a/app/Template/user/create_local.php +++ b/app/Template/user/create_local.php @@ -37,7 +37,7 @@ <?= $this->form->label(t('Language'), 'language') ?> <?= $this->form->select('language', $languages, $values, $errors) ?><br/> - <?= $this->form->checkbox('notifications_enabled', t('Enable notifications'), 1, isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1 ? true : false) ?> + <?= $this->form->checkbox('notifications_enabled', t('Enable email notifications'), 1, isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1 ? true : false) ?> <?= $this->form->checkbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?> <?= $this->form->checkbox('is_project_admin', t('Project Administrator'), 1, isset($values['is_project_admin']) && $values['is_project_admin'] == 1 ? true : false) ?> </div> diff --git a/app/Template/user/create_remote.php b/app/Template/user/create_remote.php index 559d3d72..49d1548c 100644 --- a/app/Template/user/create_remote.php +++ b/app/Template/user/create_remote.php @@ -40,7 +40,7 @@ <?= $this->form->label(t('Language'), 'language') ?> <?= $this->form->select('language', $languages, $values, $errors) ?><br/> - <?= $this->form->checkbox('notifications_enabled', t('Enable notifications'), 1, isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1 ? true : false) ?> + <?= $this->form->checkbox('notifications_enabled', t('Enable email notifications'), 1, isset($values['notifications_enabled']) && $values['notifications_enabled'] == 1 ? true : false) ?> <?= $this->form->checkbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?> <?= $this->form->checkbox('is_project_admin', t('Project Administrator'), 1, isset($values['is_project_admin']) && $values['is_project_admin'] == 1 ? true : false) ?> <?= $this->form->checkbox('disable_login_form', t('Disallow login form'), 1, isset($values['disable_login_form']) && $values['disable_login_form'] == 1) ?> diff --git a/app/Template/user/notifications.php b/app/Template/user/notifications.php index a425705d..7223013c 100644 --- a/app/Template/user/notifications.php +++ b/app/Template/user/notifications.php @@ -1,33 +1,24 @@ <div class="page-header"> - <h2><?= t('Email notifications') ?></h2> + <h2><?= t('Notifications') ?></h2> </div> <form method="post" action="<?= $this->url->href('user', 'notifications', array('user_id' => $user['id'])) ?>" autocomplete="off"> <?= $this->form->csrf() ?> - <?= $this->form->checkbox('notifications_enabled', t('Enable email notifications'), '1', $notifications['notifications_enabled'] == 1) ?><br> + <?= $this->form->checkbox('notifications_enabled', t('Enable notifications'), '1', $notifications['notifications_enabled'] == 1) ?><br> <hr> - - <?= t('I want to receive notifications for:') ?> - - <?= $this->form->radios('notifications_filter', array( - \Model\Notification::FILTER_NONE => t('All tasks'), - \Model\Notification::FILTER_ASSIGNEE => t('Only for tasks assigned to me'), - \Model\Notification::FILTER_CREATOR => t('Only for tasks created by me'), - \Model\Notification::FILTER_BOTH => t('Only for tasks created by me and assigned to me'), - ), $notifications) ?><br> + <h4><?= t('Notification methods:') ?></h4> + <?= $this->form->checkboxes('notification_types', $types, $notifications) ?> <hr> + <h4><?= t('I want to receive notifications for:') ?></h4> + <?= $this->form->radios('notifications_filter', $filters, $notifications) ?> + <hr> <?php if (! empty($projects)): ?> - <p><?= t('I want to receive notifications only for those projects:') ?><br/><br/></p> - - <div class="form-checkbox-group"> - <?php foreach ($projects as $project_id => $project_name): ?> - <?= $this->form->checkbox('projects['.$project_id.']', $project_name, '1', isset($notifications['project_'.$project_id])) ?><br> - <?php endforeach ?> - </div> + <h4><?= t('I want to receive notifications only for those projects:') ?></h4> + <?= $this->form->checkboxes('notification_projects', $projects, $notifications) ?> <?php endif ?> <div class="form-actions"> diff --git a/app/Template/user/sidebar.php b/app/Template/user/sidebar.php index 640c8b80..ca1e0621 100644 --- a/app/Template/user/sidebar.php +++ b/app/Template/user/sidebar.php @@ -51,7 +51,7 @@ <?= $this->url->link(t('Public access'), 'user', 'share', array('user_id' => $user['id'])) ?> </li> <li <?= $this->app->getRouterController() === 'user' && $this->app->getRouterAction() === 'notifications' ? 'class="active"' : '' ?>> - <?= $this->url->link(t('Email notifications'), 'user', 'notifications', array('user_id' => $user['id'])) ?> + <?= $this->url->link(t('Notifications'), 'user', 'notifications', array('user_id' => $user['id'])) ?> </li> <li <?= $this->app->getRouterController() === 'user' && $this->app->getRouterAction() === 'external' ? 'class="active"' : '' ?>> <?= $this->url->link(t('External accounts'), 'user', 'external', array('user_id' => $user['id'])) ?> |