1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Notifications controller handling notification creation and rendering. |
5
|
|
|
* |
6
|
|
|
* phpMyAdmin Error reporting server |
7
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
8
|
|
|
* |
9
|
|
|
* Licensed under The MIT License |
10
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
11
|
|
|
* Redistributions of files must retain the above copyright notice. |
12
|
|
|
* |
13
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
15
|
|
|
* |
16
|
|
|
* @see https://www.phpmyadmin.net/ |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Controller; |
20
|
|
|
|
21
|
|
|
use Cake\Event\Event; |
22
|
|
|
use Cake\Http\Response; |
23
|
|
|
use Cake\ORM\TableRegistry; |
24
|
|
|
use Cake\Routing\Router; |
25
|
|
|
use function array_push; |
26
|
|
|
use function intval; |
27
|
|
|
use function json_encode; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Notifications Controller. |
31
|
|
|
*/ |
32
|
|
|
class NotificationsController extends AppController |
33
|
|
|
{ |
34
|
|
|
/** @var string */ |
35
|
|
|
public $components = [ |
36
|
|
|
'RequestHandler', |
37
|
|
|
'OrderSearch', |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
public $helpers = [ |
42
|
|
|
'Html', |
43
|
|
|
'Form', |
44
|
|
|
'Reports', |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** @var string */ |
48
|
|
|
public $uses = [ |
49
|
|
|
'Notification', |
50
|
|
|
'Developer', |
51
|
|
|
'Report', |
52
|
|
|
]; |
53
|
|
|
|
54
|
12 |
|
public function beforeFilter(Event $event): void |
55
|
|
|
{ |
56
|
12 |
|
if ($this->request->getParam('action') === 'clean_old_notifs') { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
12 |
|
parent::beforeFilter($event); |
61
|
12 |
|
} |
62
|
|
|
|
63
|
4 |
|
public function index(): void |
64
|
|
|
{ |
65
|
|
|
// no need to do anything here. Just render the view. |
66
|
4 |
|
} |
67
|
|
|
|
68
|
4 |
|
public function data_tables(): Response |
69
|
|
|
{ |
70
|
4 |
|
$current_developer = TableRegistry::getTableLocator()->get('Developers')-> |
71
|
4 |
|
findById($this->request->getSession()->read('Developer.id'))->all()->first(); |
72
|
|
|
|
73
|
|
|
$aColumns = [ |
74
|
4 |
|
'report_id' => 'Reports.id', |
75
|
|
|
'error_message' => 'Reports.error_message', |
76
|
|
|
'error_name' => 'Reports.error_name', |
77
|
|
|
'pma_version' => 'Reports.pma_version', |
78
|
|
|
'exception_type' => 'Reports.exception_type', |
79
|
|
|
'created_time' => 'Notifications.created', |
80
|
|
|
]; |
81
|
|
|
|
82
|
4 |
|
$orderConditions = $this->OrderSearch->getOrder($aColumns); |
|
|
|
|
83
|
4 |
|
$searchConditions = $this->OrderSearch->getSearchConditions($aColumns); |
84
|
|
|
|
85
|
4 |
|
$aColumns['id'] = 'Notifications.id'; |
86
|
|
|
$params = [ |
87
|
4 |
|
'contain' => 'Reports', |
88
|
4 |
|
'fields' => $aColumns, |
89
|
|
|
'conditions' => [ |
90
|
|
|
'AND' => [ |
91
|
4 |
|
['Notifications.developer_id ' => $current_developer['id']], |
92
|
4 |
|
$searchConditions, |
93
|
|
|
], |
94
|
|
|
], |
95
|
4 |
|
'order' => $orderConditions, |
96
|
|
|
]; |
97
|
|
|
|
98
|
4 |
|
$pagedParams = $params; |
99
|
4 |
|
$pagedParams['limit'] = intval($this->request->query('iDisplayLength')); |
|
|
|
|
100
|
4 |
|
$pagedParams['offset'] = intval($this->request->query('iDisplayStart')); |
|
|
|
|
101
|
|
|
|
102
|
4 |
|
$rows = $this->Notifications->find('all', $pagedParams); |
|
|
|
|
103
|
4 |
|
$totalFiltered = $this->Notifications->find( |
104
|
4 |
|
'all', |
105
|
|
|
[ |
106
|
|
|
'conditions' => [ |
107
|
4 |
|
'developer_id' => $current_developer['id'], |
108
|
|
|
], |
109
|
|
|
] |
110
|
4 |
|
)->count(); |
111
|
|
|
|
112
|
|
|
// Make the display rows array |
113
|
4 |
|
$dispRows = []; |
114
|
4 |
|
$tmp_row = []; |
115
|
4 |
|
foreach ($rows as $row) { |
116
|
4 |
|
$tmp_row[0] = '<input type="checkbox" name="notifs[]" value="' |
117
|
4 |
|
. $row['id'] |
118
|
4 |
|
. '"/>'; |
119
|
4 |
|
$tmp_row[1] = '<a href="' |
120
|
4 |
|
. Router::url( |
121
|
|
|
[ |
122
|
4 |
|
'controller' => 'reports', |
123
|
4 |
|
'action' => 'view', |
124
|
4 |
|
$row['report_id'], |
125
|
|
|
] |
126
|
|
|
) |
127
|
4 |
|
. '">' |
128
|
4 |
|
. $row['report_id'] |
129
|
4 |
|
. '</a>'; |
130
|
4 |
|
$tmp_row[2] = $row['error_name']; |
131
|
4 |
|
$tmp_row[3] = $row['error_message']; |
132
|
4 |
|
$tmp_row[4] = $row['pma_version']; |
133
|
4 |
|
$tmp_row[5] = $row['exception_type'] ? 'php' : 'js'; |
134
|
4 |
|
$tmp_row[6] = $row['created_time']; |
135
|
4 |
|
array_push($dispRows, $tmp_row); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$response = [ |
139
|
4 |
|
'iTotalDisplayRecords' => $totalFiltered, |
140
|
4 |
|
'iTotalRecords' => $this->Notifications->find('all', $params)->count(), |
141
|
4 |
|
'sEcho' => intval($this->request->query('sEcho')), |
|
|
|
|
142
|
4 |
|
'aaData' => $dispRows, |
143
|
|
|
]; |
144
|
4 |
|
$this->autoRender = false; |
145
|
4 |
|
$this->response->body(json_encode($response)); |
|
|
|
|
146
|
|
|
|
147
|
4 |
|
return $this->response; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* To carry out mass actions on Notifications. |
152
|
|
|
* Currently it deletes them (marks them "read"). |
153
|
|
|
* Can be Extended for other mass operations as well. |
154
|
|
|
* Expects an array of Notification Ids as a POST parameter. |
155
|
|
|
* |
156
|
|
|
* @return void Nothing |
157
|
|
|
*/ |
158
|
4 |
|
public function mass_action(): void |
159
|
|
|
{ |
160
|
4 |
|
$msg = 'Selected Notifications have been marked \'Read\'!'; |
161
|
4 |
|
$flash_class = 'alert alert-success'; |
162
|
|
|
|
163
|
4 |
|
if ($this->request->getData('mark_all')) { |
164
|
|
|
// Delete all notifications for this Developer |
165
|
4 |
|
$this->Notifications->deleteAll( |
|
|
|
|
166
|
4 |
|
['developer_id' => $this->request->getSession()->read('Developer.id')] |
167
|
|
|
); |
168
|
|
|
|
169
|
4 |
|
$msg = 'All your notifications have been marked \'Read\''; |
170
|
|
|
} else { |
171
|
4 |
|
foreach ($this->request->data['notifs'] as $notif_id) { |
|
|
|
|
172
|
4 |
|
if (! $this->Notifications->delete($this->Notifications->get(intval($notif_id)))) { |
173
|
|
|
$msg = '<b>ERROR</b>: There was some problem in deleting Notification(ID:' |
174
|
|
|
. $notif_id |
175
|
|
|
. ')!'; |
176
|
|
|
$flash_class = 'alert alert-error'; |
177
|
1 |
|
break; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
} |
181
|
4 |
|
$this->Flash->default( |
182
|
4 |
|
$msg, |
183
|
4 |
|
['params' => ['class' => $flash_class]] |
184
|
|
|
); |
185
|
4 |
|
$this->redirect('/notifications/'); |
186
|
4 |
|
} |
187
|
|
|
} |
188
|
|
|
|