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
|
|
|
use SP\Core\Acl\Acl; |
28
|
|
|
use SP\Core\Acl\ActionsInterface; |
29
|
|
|
use SP\Html\DataGrid\DataGridAction; |
30
|
|
|
use SP\Html\DataGrid\DataGridActionSearch; |
31
|
|
|
use SP\Html\DataGrid\DataGridActionType; |
32
|
|
|
use SP\Html\DataGrid\DataGridData; |
33
|
|
|
use SP\Html\DataGrid\DataGridHeader; |
34
|
|
|
use SP\Html\DataGrid\DataGridInterface; |
35
|
|
|
use SP\Html\DataGrid\DataGridTab; |
36
|
|
|
use SP\Storage\Database\QueryResult; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Class AccountDefaultPermissionGrid |
40
|
|
|
* |
41
|
|
|
* @package SP\Modules\Web\Controllers\Helpers\Grid |
42
|
|
|
*/ |
43
|
|
|
final class ItemPresetGrid extends GridBase |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var QueryResult |
47
|
|
|
*/ |
48
|
|
|
private $queryResult; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param QueryResult $queryResult |
52
|
|
|
* |
53
|
|
|
* @return DataGridInterface |
54
|
|
|
*/ |
55
|
|
|
public function getGrid(QueryResult $queryResult): DataGridInterface |
56
|
|
|
{ |
57
|
|
|
$this->queryResult = $queryResult; |
58
|
|
|
|
59
|
|
|
$grid = $this->getGridLayout(); |
60
|
|
|
|
61
|
|
|
$searchAction = $this->getSearchAction(); |
62
|
|
|
|
63
|
|
|
$grid->setDataActions($this->getSearchAction()); |
64
|
|
|
$grid->setPager($this->getPager($searchAction)); |
65
|
|
|
|
66
|
|
|
$grid->setDataActions($this->getCreatePermissionAction(), true); |
67
|
|
|
$grid->setDataActions($this->getEditAction()); |
68
|
|
|
$grid->setDataActions($this->getDeleteAction()); |
69
|
|
|
$grid->setDataActions($this->getDeleteAction()->setTitle(__('Eliminar Seleccionados')), true); |
70
|
|
|
|
71
|
|
|
$grid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $grid; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return DataGridInterface |
78
|
|
|
*/ |
79
|
|
|
protected function getGridLayout(): DataGridInterface |
80
|
|
|
{ |
81
|
|
|
// Grid |
82
|
|
|
$gridTab = new DataGridTab($this->view->getTheme()); |
83
|
|
|
$gridTab->setId('tblItemPreset'); |
84
|
|
|
$gridTab->setDataRowTemplate('datagrid-rows', 'grid'); |
85
|
|
|
$gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid'); |
86
|
|
|
$gridTab->setHeader($this->getHeader()); |
87
|
|
|
$gridTab->setData($this->getData()); |
88
|
|
|
$gridTab->setTitle(__('Valores por Defecto')); |
89
|
|
|
|
90
|
|
|
return $gridTab; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return DataGridHeader |
95
|
|
|
*/ |
96
|
|
|
protected function getHeader(): DataGridHeader |
97
|
|
|
{ |
98
|
|
|
// Grid Header |
99
|
|
|
$gridHeader = new DataGridHeader(); |
100
|
|
|
$gridHeader->addHeader(__('Tipo')); |
101
|
|
|
$gridHeader->addHeader(__('Usuario')); |
102
|
|
|
$gridHeader->addHeader(__('Grupo')); |
103
|
|
|
$gridHeader->addHeader(__('Perfil')); |
104
|
|
|
$gridHeader->addHeader(__('Prioridad')); |
105
|
|
|
$gridHeader->addHeader(__('Forzado')); |
106
|
|
|
|
107
|
|
|
return $gridHeader; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return DataGridData |
112
|
|
|
*/ |
113
|
|
|
protected function getData(): DataGridData |
114
|
|
|
{ |
115
|
|
|
// Grid Data |
116
|
|
|
$gridData = new DataGridData(); |
117
|
|
|
$gridData->setDataRowSourceId('id'); |
118
|
|
|
$gridData->addDataRowSource('type'); |
119
|
|
|
$gridData->addDataRowSource('userName'); |
120
|
|
|
$gridData->addDataRowSource('userGroupName'); |
121
|
|
|
$gridData->addDataRowSource('userProfileName'); |
122
|
|
|
$gridData->addDataRowSource('priority'); |
123
|
|
|
$gridData->addDataRowSource('fixed', false, function ($value) { |
124
|
|
|
return $value === 1 ? __('SI') : __('NO'); |
125
|
|
|
}); |
126
|
|
|
$gridData->setData($this->queryResult); |
127
|
|
|
|
128
|
|
|
return $gridData; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return DataGridActionSearch |
133
|
|
|
*/ |
134
|
|
|
private function getSearchAction() |
135
|
|
|
{ |
136
|
|
|
// Grid Actions |
137
|
|
|
$gridActionSearch = new DataGridActionSearch(); |
138
|
|
|
$gridActionSearch->setId(ActionsInterface::ITEMPRESET_SEARCH); |
139
|
|
|
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM); |
140
|
|
|
$gridActionSearch->setName('frmSearchPermission'); |
141
|
|
|
$gridActionSearch->setTitle(__('Buscar Valor')); |
142
|
|
|
$gridActionSearch->setOnSubmitFunction('appMgmt/search'); |
143
|
|
|
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::ITEMPRESET_SEARCH)); |
144
|
|
|
|
145
|
|
|
return $gridActionSearch; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return DataGridAction |
150
|
|
|
*/ |
151
|
|
|
private function getCreatePermissionAction() |
152
|
|
|
{ |
153
|
|
|
$gridAction = new DataGridAction(); |
154
|
|
|
$gridAction->setId(ActionsInterface::ITEMPRESET_CREATE); |
155
|
|
|
$gridAction->setType(DataGridActionType::MENUBAR_ITEM); |
156
|
|
|
$gridAction->setName(__('Nuevo Permiso')); |
157
|
|
|
$gridAction->setTitle(__('Nuevo Permiso')); |
158
|
|
|
|
159
|
|
|
$icon = clone $this->icons->getIconAdd(); |
160
|
|
|
|
161
|
|
|
$gridAction->setIcon($icon->setIcon('add_circle')); |
162
|
|
|
$gridAction->setSkip(true); |
163
|
|
|
$gridAction->setOnClickFunction('appMgmt/show'); |
164
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ITEMPRESET_CREATE) . '/permission'); |
165
|
|
|
|
166
|
|
|
return $gridAction; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return DataGridAction |
171
|
|
|
*/ |
172
|
|
|
private function getEditAction() |
173
|
|
|
{ |
174
|
|
|
$gridAction = new DataGridAction(); |
175
|
|
|
$gridAction->setId(ActionsInterface::ITEMPRESET_EDIT); |
176
|
|
|
$gridAction->setType(DataGridActionType::EDIT_ITEM); |
177
|
|
|
$gridAction->setName(__('Editar Valor')); |
178
|
|
|
$gridAction->setTitle(__('Editar Valor')); |
179
|
|
|
$gridAction->setIcon($this->icons->getIconEdit()); |
180
|
|
|
$gridAction->setOnClickFunction('appMgmt/show'); |
181
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ITEMPRESET_EDIT)); |
182
|
|
|
|
183
|
|
|
return $gridAction; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return DataGridAction |
188
|
|
|
*/ |
189
|
|
|
private function getDeleteAction() |
190
|
|
|
{ |
191
|
|
|
$gridAction = new DataGridAction(); |
192
|
|
|
$gridAction->setId(ActionsInterface::ITEMPRESET_DELETE); |
193
|
|
|
$gridAction->setType(DataGridActionType::DELETE_ITEM); |
194
|
|
|
$gridAction->setName(__('Eliminar Valor')); |
195
|
|
|
$gridAction->setTitle(__('Eliminar Valor')); |
196
|
|
|
$gridAction->setIcon($this->icons->getIconDelete()); |
197
|
|
|
$gridAction->setOnClickFunction('appMgmt/delete'); |
198
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ITEMPRESET_DELETE)); |
199
|
|
|
|
200
|
|
|
return $gridAction; |
201
|
|
|
} |
202
|
|
|
} |