Mark notification as read when clicking on it
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Web notification controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class WebNotification extends BaseController
|
||||
{
|
||||
/**
|
||||
* Mark all notifications as read
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$user_id = $this->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;
|
||||
}
|
||||
}
|
||||
79
app/Controller/WebNotificationController.php
Normal file
79
app/Controller/WebNotificationController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Web notification controller
|
||||
*
|
||||
* @package Kanboard\Controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class WebNotificationController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Mark all notifications as read
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$user_id = $this->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;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,23 @@ class UserUnreadNotification extends Base
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one notification
|
||||
*
|
||||
* @param integer $notification_id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getById($notification_id)
|
||||
{
|
||||
$notification = $this->db->table(self::TABLE)->eq('id', $notification_id)->findOne();
|
||||
|
||||
if (! empty($notification)) {
|
||||
$this->unserialize($notification);
|
||||
}
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notifications for a user
|
||||
*
|
||||
@@ -47,8 +64,7 @@ class UserUnreadNotification extends Base
|
||||
$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->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']);
|
||||
$this->unserialize($event);
|
||||
}
|
||||
|
||||
return $events;
|
||||
@@ -90,4 +106,10 @@ class UserUnreadNotification extends Base
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists();
|
||||
}
|
||||
|
||||
private function unserialize(&$event)
|
||||
{
|
||||
$event['event_data'] = json_decode($event['event_data'], true);
|
||||
$event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<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'])) ?>
|
||||
<?= $this->url->link(t('Mark all as read'), 'WebNotificationController', 'flush', array('user_id' => $user['id'])) ?>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -36,16 +36,12 @@
|
||||
<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 ($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'])) ?>
|
||||
<?= $this->url->link($notification['title'], 'WebNotificationController', 'redirect', array('notification_id' => $notification['id'], 'user_id' => $user['id'])) ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td>
|
||||
@@ -53,9 +49,9 @@
|
||||
</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'])) ?>
|
||||
<?= $this->url->link(t('Mark as read'), 'WebNotificationController', 'remove', array('user_id' => $user['id'], 'notification_id' => $notification['id'])) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</table>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
Reference in New Issue
Block a user