From abdfa46cfcc06175dea10b5e285fe5b2331b6ead Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 1 Jul 2016 12:33:18 -0400 Subject: Fixed empty title for web notification with only one overdue task --- app/Console/TaskOverdueNotificationCommand.php | 2 +- app/Controller/WebNotificationController.php | 4 +-- app/Model/NotificationModel.php | 37 ++++++++++++++++++++++++++ app/Template/dashboard/notifications.php | 6 ++--- 4 files changed, 42 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/Console/TaskOverdueNotificationCommand.php b/app/Console/TaskOverdueNotificationCommand.php index 225a6a1a..36276615 100644 --- a/app/Console/TaskOverdueNotificationCommand.php +++ b/app/Console/TaskOverdueNotificationCommand.php @@ -149,7 +149,7 @@ class TaskOverdueNotificationCommand extends BaseCommand $this->userNotificationModel->sendUserNotification( $user, TaskModel::EVENT_OVERDUE, - array('tasks' => $user_tasks, 'project_name' => implode(", ", $project_names)) + array('tasks' => $user_tasks, 'project_name' => implode(', ', $project_names)) ); } } diff --git a/app/Controller/WebNotificationController.php b/app/Controller/WebNotificationController.php index 46a42063..30e317f8 100644 --- a/app/Controller/WebNotificationController.php +++ b/app/Controller/WebNotificationController.php @@ -54,14 +54,14 @@ class WebNotificationController extends BaseController $this->response->redirect($this->helper->url->to( 'TaskViewController', 'show', - array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id']), + array('task_id' => $this->notificationModel->getTaskIdFromEvent($notification['event_name'], $notification['event_data'])), 'comment-'.$notification['event_data']['comment']['id'] )); } else { $this->response->redirect($this->helper->url->to( 'TaskViewController', 'show', - array('task_id' => $notification['event_data']['task']['id'], 'project_id' => $notification['event_data']['task']['project_id']) + array('task_id' => $this->notificationModel->getTaskIdFromEvent($notification['event_name'], $notification['event_data'])) )); } } diff --git a/app/Model/NotificationModel.php b/app/Model/NotificationModel.php index 8937b77e..4d697b5e 100644 --- a/app/Model/NotificationModel.php +++ b/app/Model/NotificationModel.php @@ -133,4 +133,41 @@ class NotificationModel extends Base return e('Notification'); } } + + /** + * Get task id from event + * + * @access public + * @param string $event_name + * @param array $event_data + * @return integer + */ + public function getTaskIdFromEvent($event_name, array $event_data) + { + switch ($event_name) { + case TaskFileModel::EVENT_CREATE: + return $event_data['file']['task_id']; + case CommentModel::EVENT_CREATE: + case CommentModel::EVENT_UPDATE: + return $event_data['comment']['task_id']; + case SubtaskModel::EVENT_CREATE: + case SubtaskModel::EVENT_UPDATE: + return $event_data['subtask']['task_id']; + case TaskModel::EVENT_CREATE: + case TaskModel::EVENT_UPDATE: + case TaskModel::EVENT_CLOSE: + case TaskModel::EVENT_OPEN: + case TaskModel::EVENT_MOVE_COLUMN: + case TaskModel::EVENT_MOVE_POSITION: + case TaskModel::EVENT_MOVE_SWIMLANE: + case TaskModel::EVENT_ASSIGNEE_CHANGE: + case CommentModel::EVENT_USER_MENTION: + case TaskModel::EVENT_USER_MENTION: + return $event_data['task']['id']; + case TaskModel::EVENT_OVERDUE: + return $event_data['tasks'][0]['id']; + default: + return 0; + } + } } diff --git a/app/Template/dashboard/notifications.php b/app/Template/dashboard/notifications.php index e0e9b878..3b70b49f 100644 --- a/app/Template/dashboard/notifications.php +++ b/app/Template/dashboard/notifications.php @@ -36,10 +36,8 @@ - text->contains($notification['event_name'], 'task.overdue')): ?> - 1): ?> - - + text->contains($notification['event_name'], 'task.overdue') && count($notification['event_data']['tasks']) > 1): ?> + url->link($notification['title'], 'WebNotificationController', 'redirect', array('notification_id' => $notification['id'], 'user_id' => $user['id'])) ?> -- cgit v1.2.3