|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Http\Controllers\Dashboard; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Http\Controllers\Controller; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Notification controller. |
|
18
|
|
|
*/ |
|
19
|
|
|
class NotificationController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* My notifications. |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
public function index() |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$user = $this->getUser(); |
|
27
|
|
|
|
|
28
|
|
|
$this->response->html($this->helper->layout->app('dashboard/notifications', [ |
|
|
|
|
|
|
29
|
|
|
'title' => t('My notifications'), |
|
30
|
|
|
'notifications' => $this->userUnreadNotificationModel->getAll($user['id']), |
|
|
|
|
|
|
31
|
|
|
])); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Mark all notifications as read. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function flush() |
|
38
|
|
|
{ |
|
39
|
|
|
$user = $this->getUser(); |
|
40
|
|
|
|
|
41
|
|
|
$this->userUnreadNotificationModel->markAllAsRead($user['id']); |
|
|
|
|
|
|
42
|
|
|
$this->response->redirect($this->helper->url->to('Dashboard/NotificationController', 'index')); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Mark a notification as read. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function remove() |
|
49
|
|
|
{ |
|
50
|
|
|
$user = $this->getUser(); |
|
51
|
|
|
$notification_id = $this->request->getIntegerParam('notification_id'); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$this->userUnreadNotificationModel->markAsRead($user['id'], $notification_id); |
|
|
|
|
|
|
54
|
|
|
$this->response->redirect($this->helper->url->to('Dashboard/NotificationController', 'index')); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Redirect to the task and mark notification as read. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function redirect() |
|
61
|
|
|
{ |
|
62
|
|
|
$user = $this->getUser(); |
|
63
|
|
|
$notification_id = $this->request->getIntegerParam('notification_id'); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$notification = $this->userUnreadNotificationModel->getById($notification_id); |
|
|
|
|
|
|
66
|
|
|
$this->userUnreadNotificationModel->markAsRead($user['id'], $notification_id); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
if (empty($notification)) { |
|
69
|
|
|
$this->response->redirect($this->helper->url->to('Dashboard/NotificationController', 'index')); |
|
|
|
|
|
|
70
|
|
|
} elseif ($this->helper->text->contains($notification['event_name'], 'comment')) { |
|
|
|
|
|
|
71
|
|
|
$this->response->redirect($this->helper->url->to( |
|
|
|
|
|
|
72
|
|
|
'Task/TaskController', |
|
73
|
|
|
'show', |
|
74
|
|
|
['task_id' => $this->notificationModel->getTaskIdFromEvent($notification['event_name'], $notification['event_data'])], |
|
|
|
|
|
|
75
|
|
|
'comment-'.$notification['event_data']['comment']['id'] |
|
76
|
|
|
)); |
|
77
|
|
|
} else { |
|
78
|
|
|
$this->response->redirect($this->helper->url->to( |
|
|
|
|
|
|
79
|
|
|
'Task/TaskController', |
|
80
|
|
|
'show', |
|
81
|
|
|
['task_id' => $this->notificationModel->getTaskIdFromEvent($notification['event_name'], $notification['event_data'])] |
|
|
|
|
|
|
82
|
|
|
)); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.