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\Action\DataGridAction; |
31
|
|
|
use SP\Html\DataGrid\Action\DataGridActionSearch; |
32
|
|
|
use SP\Html\DataGrid\Action\DataGridActionType; |
33
|
|
|
use SP\Html\DataGrid\DataGridData; |
34
|
|
|
use SP\Html\DataGrid\DataGridInterface; |
35
|
|
|
use SP\Html\DataGrid\DataGridTab; |
36
|
|
|
use SP\Html\DataGrid\Layout\DataGridHeader; |
37
|
|
|
use SP\Storage\Database\QueryResult; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Class PluginGrid |
41
|
|
|
* |
42
|
|
|
* @package SP\Modules\Web\Controllers\Helpers\Grid |
43
|
|
|
*/ |
44
|
|
|
final class PluginGrid extends GridBase |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var QueryResult |
48
|
|
|
*/ |
49
|
|
|
private $queryResult; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param QueryResult $queryResult |
53
|
|
|
* |
54
|
|
|
* @return DataGridInterface |
55
|
|
|
*/ |
56
|
|
|
public function getGrid(QueryResult $queryResult): DataGridInterface |
57
|
|
|
{ |
58
|
|
|
$this->queryResult = $queryResult; |
59
|
|
|
|
60
|
|
|
$grid = $this->getGridLayout(); |
61
|
|
|
|
62
|
|
|
$searchAction = $this->getSearchAction(); |
63
|
|
|
|
64
|
|
|
$grid->addDataAction($searchAction); |
65
|
|
|
$grid->setPager($this->getPager($searchAction)); |
66
|
|
|
|
67
|
|
|
$grid->addDataAction($this->getViewAction()); |
68
|
|
|
$grid->addDataAction($this->getEnableAction()); |
69
|
|
|
$grid->addDataAction($this->getDisableAction()); |
70
|
|
|
$grid->addDataAction($this->getResetAction()); |
71
|
|
|
$grid->addDataAction($this->getDeleteAction()); |
72
|
|
|
$grid->addDataAction( |
73
|
|
|
$this->getDeleteAction() |
74
|
|
|
->setName(__('Eliminar Seleccionados')) |
75
|
|
|
->setTitle(__('Eliminar Seleccionados')) |
76
|
|
|
->setIsSelection(true), |
77
|
|
|
true); |
78
|
|
|
|
79
|
|
|
$grid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return $grid; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return DataGridInterface |
86
|
|
|
*/ |
87
|
|
|
protected function getGridLayout(): DataGridInterface |
88
|
|
|
{ |
89
|
|
|
// Grid |
90
|
|
|
$gridTab = new DataGridTab($this->view->getTheme()); |
91
|
|
|
$gridTab->setId('tblPlugins'); |
92
|
|
|
$gridTab->setDataRowTemplate('datagrid-rows', 'grid'); |
93
|
|
|
$gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid'); |
94
|
|
|
$gridTab->setHeader($this->getHeader()); |
95
|
|
|
$gridTab->setData($this->getData()); |
96
|
|
|
$gridTab->setTitle(__('Plugins')); |
97
|
|
|
|
98
|
|
|
return $gridTab; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return DataGridHeader |
103
|
|
|
*/ |
104
|
|
|
protected function getHeader(): DataGridHeader |
105
|
|
|
{ |
106
|
|
|
// Grid Header |
107
|
|
|
$gridHeader = new DataGridHeader(); |
108
|
|
|
$gridHeader->addHeader(__('Plugin')); |
109
|
|
|
$gridHeader->addHeader(__('Estado')); |
110
|
|
|
|
111
|
|
|
return $gridHeader; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return DataGridData |
116
|
|
|
*/ |
117
|
|
|
protected function getData(): DataGridData |
118
|
|
|
{ |
119
|
|
|
// Grid Data |
120
|
|
|
$gridData = new DataGridData(); |
121
|
|
|
$gridData->setDataRowSourceId('id'); |
122
|
|
|
$gridData->addDataRowSource('name'); |
123
|
|
|
$gridData->addDataRowSourceWithIcon('enabled', $this->icons->getIconEnabled()); |
124
|
|
|
$gridData->addDataRowSourceWithIcon('enabled', $this->icons->getIconDisabled(), 0); |
125
|
|
|
$gridData->addDataRowSourceWithIcon('available', $this->icons->getIconDelete()->setTitle(__('No disponible')), 0); |
126
|
|
|
$gridData->setData($this->queryResult); |
127
|
|
|
|
128
|
|
|
return $gridData; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return \SP\Html\DataGrid\Action\DataGridActionSearch |
133
|
|
|
*/ |
134
|
|
|
private function getSearchAction() |
135
|
|
|
{ |
136
|
|
|
// Grid Actions |
137
|
|
|
$gridActionSearch = new DataGridActionSearch(); |
138
|
|
|
$gridActionSearch->setId(ActionsInterface::PLUGIN_SEARCH); |
139
|
|
|
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM); |
140
|
|
|
$gridActionSearch->setName('frmSearchPlugin'); |
141
|
|
|
$gridActionSearch->setTitle(__('Buscar Plugin')); |
142
|
|
|
$gridActionSearch->setOnSubmitFunction('plugin/search'); |
143
|
|
|
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_SEARCH)); |
144
|
|
|
|
145
|
|
|
return $gridActionSearch; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return DataGridAction |
150
|
|
|
*/ |
151
|
|
|
private function getViewAction() |
152
|
|
|
{ |
153
|
|
|
$gridAction = new DataGridAction(); |
154
|
|
|
$gridAction->setId(ActionsInterface::PLUGIN_VIEW); |
155
|
|
|
$gridAction->setType(DataGridActionType::VIEW_ITEM); |
156
|
|
|
$gridAction->setName(__('Ver Plugin')); |
157
|
|
|
$gridAction->setTitle(__('Ver Plugin')); |
158
|
|
|
$gridAction->setIcon($this->icons->getIconView()); |
159
|
|
|
$gridAction->setOnClickFunction('plugin/show'); |
160
|
|
|
$gridAction->setFilterRowSource('available', 0); |
161
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_VIEW)); |
162
|
|
|
|
163
|
|
|
return $gridAction; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return DataGridAction |
168
|
|
|
*/ |
169
|
|
|
private function getEnableAction() |
170
|
|
|
{ |
171
|
|
|
$gridAction = new DataGridAction(); |
172
|
|
|
$gridAction->setId(ActionsInterface::PLUGIN_ENABLE); |
173
|
|
|
$gridAction->setName(__('Habilitar')); |
174
|
|
|
$gridAction->setTitle(__('Habilitar')); |
175
|
|
|
$gridAction->setIcon($this->icons->getIconEnabled()); |
176
|
|
|
$gridAction->setOnClickFunction('plugin/toggle'); |
177
|
|
|
$gridAction->setFilterRowSource('enabled'); |
178
|
|
|
$gridAction->setFilterRowSource('available', 0); |
179
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_ENABLE)); |
180
|
|
|
$gridAction->addData('action-method', 'get'); |
181
|
|
|
|
182
|
|
|
return $gridAction; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return \SP\Html\DataGrid\Action\DataGridAction |
187
|
|
|
*/ |
188
|
|
|
private function getDisableAction() |
189
|
|
|
{ |
190
|
|
|
$gridAction = new DataGridAction(); |
191
|
|
|
$gridAction->setId(ActionsInterface::PLUGIN_DISABLE); |
192
|
|
|
$gridAction->setName(__('Deshabilitar')); |
193
|
|
|
$gridAction->setTitle(__('Deshabilitar')); |
194
|
|
|
$gridAction->setIcon($this->icons->getIconDisabled()); |
195
|
|
|
$gridAction->setOnClickFunction('plugin/toggle'); |
196
|
|
|
$gridAction->setFilterRowSource('enabled', 0); |
197
|
|
|
$gridAction->setFilterRowSource('available', 0); |
198
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_DISABLE)); |
199
|
|
|
$gridAction->addData('action-method', 'get'); |
200
|
|
|
|
201
|
|
|
return $gridAction; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return DataGridAction |
206
|
|
|
*/ |
207
|
|
|
private function getResetAction() |
208
|
|
|
{ |
209
|
|
|
$gridAction = new DataGridAction(); |
210
|
|
|
$gridAction->setId(ActionsInterface::PLUGIN_RESET); |
211
|
|
|
$gridAction->setName(__('Restablecer Datos')); |
212
|
|
|
$gridAction->setTitle(__('Restablecer Datos')); |
213
|
|
|
$gridAction->setIcon($this->icons->getIconRefresh()); |
214
|
|
|
$gridAction->setOnClickFunction('plugin/reset'); |
215
|
|
|
$gridAction->setFilterRowSource('available', 0); |
216
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_RESET)); |
217
|
|
|
$gridAction->addData('action-method', 'get'); |
218
|
|
|
$gridAction->addData('action-next', Acl::getActionRoute(ActionsInterface::PLUGIN)); |
219
|
|
|
|
220
|
|
|
return $gridAction; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return \SP\Html\DataGrid\Action\DataGridAction |
225
|
|
|
*/ |
226
|
|
|
private function getDeleteAction() |
227
|
|
|
{ |
228
|
|
|
$gridAction = new DataGridAction(); |
229
|
|
|
$gridAction->setId(ActionsInterface::PLUGIN_DELETE); |
230
|
|
|
$gridAction->setType(DataGridActionType::DELETE_ITEM); |
231
|
|
|
$gridAction->setName(__('Eliminar Plugin')); |
232
|
|
|
$gridAction->setTitle(__('Eliminar Plugin')); |
233
|
|
|
$gridAction->setIcon($this->icons->getIconDelete()); |
234
|
|
|
$gridAction->setFilterRowSource('available', 1); |
235
|
|
|
$gridAction->setOnClickFunction('plugin/delete'); |
236
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_DELETE)); |
237
|
|
|
$gridAction->addData('action-next', Acl::getActionRoute(ActionsInterface::PLUGIN)); |
238
|
|
|
|
239
|
|
|
return $gridAction; |
240
|
|
|
} |
241
|
|
|
} |