|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* sysPass |
|
4
|
|
|
* |
|
5
|
|
|
* @author nuxsmin |
|
6
|
|
|
* @link https://syspass.org |
|
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of sysPass. |
|
10
|
|
|
* |
|
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace SP\Modules\Web\Controllers\Helpers\Grid; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
use SP\Core\Acl\Acl; |
|
29
|
|
|
use SP\Core\Acl\ActionsInterface; |
|
30
|
|
|
use SP\Html\DataGrid\DataGrid; |
|
31
|
|
|
use SP\Html\DataGrid\DataGridAction; |
|
32
|
|
|
use SP\Html\DataGrid\DataGridActionInterface; |
|
33
|
|
|
use SP\Html\DataGrid\DataGridActionSearch; |
|
34
|
|
|
use SP\Html\DataGrid\DataGridActionType; |
|
35
|
|
|
use SP\Html\DataGrid\DataGridData; |
|
36
|
|
|
use SP\Html\DataGrid\DataGridHeader; |
|
37
|
|
|
use SP\Html\DataGrid\DataGridInterface; |
|
38
|
|
|
use SP\Storage\Database\QueryResult; |
|
39
|
|
|
use SP\Util\DateUtil; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Class NotificationGrid |
|
43
|
|
|
* |
|
44
|
|
|
* @package SP\Modules\Web\Controllers\Helpers\Grid |
|
45
|
|
|
*/ |
|
46
|
|
|
final class NotificationGrid extends GridBase |
|
47
|
|
|
{ |
|
48
|
|
|
/** |
|
49
|
|
|
* @var QueryResult |
|
50
|
|
|
*/ |
|
51
|
|
|
private $queryResult; |
|
52
|
|
|
/** |
|
53
|
|
|
* @var bool |
|
54
|
|
|
*/ |
|
55
|
|
|
private $isAdminApp; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param QueryResult $queryResult |
|
59
|
|
|
* |
|
60
|
|
|
* @return DataGridInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getGrid(QueryResult $queryResult): DataGridInterface |
|
63
|
|
|
{ |
|
64
|
|
|
$this->queryResult = $queryResult; |
|
65
|
|
|
|
|
66
|
|
|
$grid = $this->getGridLayout(); |
|
67
|
|
|
|
|
68
|
|
|
$searchAction = $this->getSearchAction(); |
|
69
|
|
|
|
|
70
|
|
|
$grid->setDataActions($this->getSearchAction()); |
|
71
|
|
|
$grid->setPager($this->getPager($searchAction)); |
|
72
|
|
|
|
|
73
|
|
|
$this->isAdminApp = $this->context->getUserData()->getIsAdminApp(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
if ($this->isAdminApp) { |
|
76
|
|
|
$grid->setDataActions($this->getCreateAction()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$grid->setDataActions($this->getViewAction()); |
|
80
|
|
|
$grid->setDataActions($this->setNonAdminFilter($this->getCheckAction())); |
|
81
|
|
|
$grid->setDataActions($this->setNonAdminFilter($this->getEditAction())); |
|
82
|
|
|
|
|
83
|
|
|
$deleteAction = $this->setNonAdminFilter($this->getDeleteAction()); |
|
84
|
|
|
|
|
85
|
|
|
$grid->setDataActions($deleteAction); |
|
86
|
|
|
$grid->setDataActions($deleteAction, true); |
|
87
|
|
|
|
|
88
|
|
|
$grid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
return $grid; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return DataGridInterface |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getGridLayout(): DataGridInterface |
|
97
|
|
|
{ |
|
98
|
|
|
// Grid |
|
99
|
|
|
$dataGrid = new DataGrid($this->view->getTheme()); |
|
100
|
|
|
$dataGrid->setId('tblNotifications'); |
|
101
|
|
|
$dataGrid->setDataRowTemplate('datagrid-rows', 'grid'); |
|
102
|
|
|
$dataGrid->setDataPagerTemplate('datagrid-nav-full', 'grid'); |
|
103
|
|
|
$dataGrid->setHeader($this->getHeader()); |
|
104
|
|
|
$dataGrid->setData($this->getData()); |
|
105
|
|
|
$dataGrid->setTitle(__('Notificaciones')); |
|
106
|
|
|
$dataGrid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
return $dataGrid; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return DataGridHeader |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function getHeader(): DataGridHeader |
|
115
|
|
|
{ |
|
116
|
|
|
// Grid Header |
|
117
|
|
|
$gridHeader = new DataGridHeader(); |
|
118
|
|
|
$gridHeader->addHeader(__('Fecha')); |
|
119
|
|
|
$gridHeader->addHeader(__('Tipo')); |
|
120
|
|
|
$gridHeader->addHeader(__('Componente')); |
|
121
|
|
|
$gridHeader->addHeader(__('Descripción')); |
|
122
|
|
|
$gridHeader->addHeader(__('Estado')); |
|
123
|
|
|
|
|
124
|
|
|
return $gridHeader; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return DataGridData |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function getData(): DataGridData |
|
131
|
|
|
{ |
|
132
|
|
|
// Grid Data |
|
133
|
|
|
$gridData = new DataGridData(); |
|
134
|
|
|
$gridData->setDataRowSourceId('id'); |
|
135
|
|
|
$gridData->addDataRowSource('date', false, |
|
136
|
|
|
function ($value) { |
|
137
|
|
|
return DateUtil::getDateFromUnix($value); |
|
138
|
|
|
}); |
|
139
|
|
|
$gridData->addDataRowSource('type'); |
|
140
|
|
|
$gridData->addDataRowSource('component'); |
|
141
|
|
|
$gridData->addDataRowSource('description'); |
|
142
|
|
|
$gridData->addDataRowSourceWithIcon('checked', $this->icons->getIconEnabled()->setTitle(__('Leída'))); |
|
143
|
|
|
$gridData->addDataRowSourceWithIcon('onlyAdmin', $this->icons->getIconAppAdmin()->setTitle(__('Sólo Admins'))); |
|
144
|
|
|
$gridData->addDataRowSourceWithIcon('sticky', $this->icons->getIconGroup()->setTitle(__('Global'))); |
|
145
|
|
|
$gridData->setData($this->queryResult); |
|
146
|
|
|
|
|
147
|
|
|
return $gridData; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return DataGridActionSearch |
|
152
|
|
|
*/ |
|
153
|
|
|
private function getSearchAction() |
|
154
|
|
|
{ |
|
155
|
|
|
// Grid Actions |
|
156
|
|
|
$gridActionSearch = new DataGridActionSearch(); |
|
157
|
|
|
$gridActionSearch->setId(ActionsInterface::NOTIFICATION_SEARCH); |
|
158
|
|
|
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM); |
|
159
|
|
|
$gridActionSearch->setName('frmSearchNotification'); |
|
160
|
|
|
$gridActionSearch->setTitle(__('Buscar Notificación')); |
|
161
|
|
|
$gridActionSearch->setOnSubmitFunction('notification/search'); |
|
162
|
|
|
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_SEARCH)); |
|
163
|
|
|
|
|
164
|
|
|
return $gridActionSearch; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return DataGridAction |
|
169
|
|
|
*/ |
|
170
|
|
|
private function getCreateAction() |
|
171
|
|
|
{ |
|
172
|
|
|
$gridAction = new DataGridAction(); |
|
173
|
|
|
$gridAction->setId(ActionsInterface::NOTIFICATION_CREATE); |
|
174
|
|
|
$gridAction->setType(DataGridActionType::MENUBAR_ITEM); |
|
175
|
|
|
$gridAction->setName(__('Nueva Notificación')); |
|
176
|
|
|
$gridAction->setTitle(__('Nueva Notificación')); |
|
177
|
|
|
$gridAction->setIcon($this->icons->getIconAdd()); |
|
178
|
|
|
$gridAction->setSkip(true); |
|
179
|
|
|
$gridAction->setOnClickFunction('notification/show'); |
|
180
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_CREATE)); |
|
181
|
|
|
|
|
182
|
|
|
return $gridAction; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @return DataGridAction |
|
187
|
|
|
*/ |
|
188
|
|
|
private function getViewAction() |
|
189
|
|
|
{ |
|
190
|
|
|
$gridAction = new DataGridAction(); |
|
191
|
|
|
$gridAction->setId(ActionsInterface::NOTIFICATION_VIEW); |
|
192
|
|
|
$gridAction->setType(DataGridActionType::VIEW_ITEM); |
|
193
|
|
|
$gridAction->setName(__('Ver Notificación')); |
|
194
|
|
|
$gridAction->setTitle(__('Ver Notificación')); |
|
195
|
|
|
$gridAction->setIcon($this->icons->getIconView()); |
|
196
|
|
|
$gridAction->setOnClickFunction('notification/show'); |
|
197
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_VIEW)); |
|
198
|
|
|
|
|
199
|
|
|
return $gridAction; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @param DataGridActionInterface $gridAction |
|
204
|
|
|
* |
|
205
|
|
|
* @return DataGridActionInterface |
|
206
|
|
|
*/ |
|
207
|
|
|
private function setNonAdminFilter(DataGridActionInterface $gridAction) |
|
208
|
|
|
{ |
|
209
|
|
|
if (!$this->isAdminApp) { |
|
210
|
|
|
$gridAction->setFilterRowSource('sticky'); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return $gridAction; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @return DataGridAction |
|
218
|
|
|
*/ |
|
219
|
|
|
private function getCheckAction() |
|
220
|
|
|
{ |
|
221
|
|
|
$gridAction = new DataGridAction(); |
|
222
|
|
|
$gridAction->setId(ActionsInterface::NOTIFICATION_CHECK); |
|
223
|
|
|
$gridAction->setName(__('Marcar Notificación')); |
|
224
|
|
|
$gridAction->setTitle(__('Marcar Notificación')); |
|
225
|
|
|
$gridAction->setIcon($this->icons->getIconEnabled()); |
|
226
|
|
|
$gridAction->setOnClickFunction('notification/check'); |
|
227
|
|
|
$gridAction->setFilterRowSource('checked'); |
|
228
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_CHECK)); |
|
229
|
|
|
$gridAction->addData('nextaction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); |
|
230
|
|
|
|
|
231
|
|
|
return $gridAction; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @return DataGridAction |
|
236
|
|
|
*/ |
|
237
|
|
|
private function getEditAction() |
|
238
|
|
|
{ |
|
239
|
|
|
$gridAction = new DataGridAction(); |
|
240
|
|
|
$gridAction->setId(ActionsInterface::NOTIFICATION_EDIT); |
|
241
|
|
|
$gridAction->setName(__('Editar Notificación')); |
|
242
|
|
|
$gridAction->setTitle(__('Editar Notificación')); |
|
243
|
|
|
$gridAction->setIcon($this->icons->getIconEdit()); |
|
244
|
|
|
$gridAction->setOnClickFunction('notification/show'); |
|
245
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_EDIT)); |
|
246
|
|
|
|
|
247
|
|
|
return $gridAction; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return DataGridAction |
|
252
|
|
|
*/ |
|
253
|
|
|
private function getDeleteAction() |
|
254
|
|
|
{ |
|
255
|
|
|
$gridAction = new DataGridAction(); |
|
256
|
|
|
$gridAction->setId(ActionsInterface::NOTIFICATION_DELETE); |
|
257
|
|
|
$gridAction->setType(DataGridActionType::DELETE_ITEM); |
|
258
|
|
|
$gridAction->setName(__('Eliminar Notificación')); |
|
259
|
|
|
$gridAction->setTitle(__('Eliminar Notificación')); |
|
260
|
|
|
$gridAction->setIcon($this->icons->getIconDelete()); |
|
261
|
|
|
$gridAction->setOnClickFunction('notification/delete'); |
|
262
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_DELETE)); |
|
263
|
|
|
$gridAction->addData('nextaction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); |
|
264
|
|
|
|
|
265
|
|
|
return $gridAction; |
|
266
|
|
|
} |
|
267
|
|
|
} |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.