|
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\Action\DataGridAction; |
|
30
|
|
|
use SP\Html\DataGrid\Action\DataGridActionHelp; |
|
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 AccountGrid |
|
41
|
|
|
* |
|
42
|
|
|
* @package SP\Modules\Web\Controllers\Helpers\Grid |
|
43
|
|
|
*/ |
|
44
|
|
|
final class AccountGrid 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(new DataGridActionHelp('help_account_search')); |
|
68
|
|
|
|
|
69
|
|
|
$grid->addDataAction($this->getViewAction()); |
|
70
|
|
|
$grid->addDataAction($this->getDeleteAction()); |
|
71
|
|
|
$grid->addDataAction( |
|
72
|
|
|
$this->getDeleteAction() |
|
73
|
|
|
->setName(__('Eliminar Seleccionados')) |
|
74
|
|
|
->setTitle(__('Eliminar Seleccionados')), |
|
75
|
|
|
true); |
|
76
|
|
|
|
|
77
|
|
|
$grid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
return $grid; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return DataGridInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function getGridLayout(): DataGridInterface |
|
86
|
|
|
{ |
|
87
|
|
|
// Grid |
|
88
|
|
|
$gridTab = new DataGridTab($this->view->getTheme()); |
|
89
|
|
|
$gridTab->setId('tblAccounts'); |
|
90
|
|
|
$gridTab->setDataRowTemplate('datagrid-rows', 'grid'); |
|
91
|
|
|
$gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid'); |
|
92
|
|
|
$gridTab->setHeader($this->getHeader()); |
|
93
|
|
|
$gridTab->setData($this->getData()); |
|
94
|
|
|
$gridTab->setTitle(__('Cuentas')); |
|
95
|
|
|
|
|
96
|
|
|
return $gridTab; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return \SP\Html\DataGrid\Layout\DataGridHeader |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function getHeader(): DataGridHeader |
|
103
|
|
|
{ |
|
104
|
|
|
// Grid Header |
|
105
|
|
|
$gridHeader = new DataGridHeader(); |
|
106
|
|
|
$gridHeader->addHeader(__('Nombre')); |
|
107
|
|
|
$gridHeader->addHeader(__('Cliente')); |
|
108
|
|
|
$gridHeader->addHeader(__('Categoría')); |
|
109
|
|
|
$gridHeader->addHeader(__('Creador')); |
|
110
|
|
|
$gridHeader->addHeader(__('Grupo')); |
|
111
|
|
|
|
|
112
|
|
|
return $gridHeader; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return DataGridData |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function getData(): DataGridData |
|
119
|
|
|
{ |
|
120
|
|
|
// Grid Data |
|
121
|
|
|
$gridData = new DataGridData(); |
|
122
|
|
|
$gridData->setDataRowSourceId('id'); |
|
123
|
|
|
$gridData->addDataRowSource('name'); |
|
124
|
|
|
$gridData->addDataRowSource('clientName'); |
|
125
|
|
|
$gridData->addDataRowSource('categoryName'); |
|
126
|
|
|
$gridData->addDataRowSource('userName'); |
|
127
|
|
|
$gridData->addDataRowSource('userGroupName'); |
|
128
|
|
|
$gridData->setData($this->queryResult); |
|
129
|
|
|
|
|
130
|
|
|
return $gridData; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return DataGridActionSearch |
|
135
|
|
|
*/ |
|
136
|
|
|
private function getSearchAction() |
|
137
|
|
|
{ |
|
138
|
|
|
$gridActionSearch = new DataGridActionSearch(); |
|
139
|
|
|
$gridActionSearch->setId(ActionsInterface::ACCOUNTMGR_SEARCH); |
|
140
|
|
|
$gridActionSearch->setType(DataGridActionType::SEARCH_ITEM); |
|
141
|
|
|
$gridActionSearch->setName('frmSearchAccount'); |
|
142
|
|
|
$gridActionSearch->setTitle(__('Buscar Cuenta')); |
|
143
|
|
|
$gridActionSearch->setOnSubmitFunction('appMgmt/search'); |
|
144
|
|
|
$gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNTMGR_SEARCH)); |
|
145
|
|
|
|
|
146
|
|
|
return $gridActionSearch; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return \SP\Html\DataGrid\Action\DataGridAction |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getViewAction() |
|
153
|
|
|
{ |
|
154
|
|
|
$gridAction = new DataGridAction(); |
|
155
|
|
|
$gridAction->setId(ActionsInterface::ACCOUNT_VIEW); |
|
156
|
|
|
$gridAction->setType(DataGridActionType::VIEW_ITEM); |
|
157
|
|
|
$gridAction->setName(__('Detalles de Cuenta')); |
|
158
|
|
|
$gridAction->setTitle(__('Detalles de Cuenta')); |
|
159
|
|
|
$gridAction->setIcon($this->icons->getIconView()); |
|
160
|
|
|
$gridAction->setOnClickFunction(Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); |
|
161
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); |
|
162
|
|
|
|
|
163
|
|
|
return $gridAction; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return DataGridAction |
|
168
|
|
|
*/ |
|
169
|
|
|
private function getDeleteAction() |
|
170
|
|
|
{ |
|
171
|
|
|
$gridAction = new DataGridAction(); |
|
172
|
|
|
$gridAction->setId(ActionsInterface::ACCOUNTMGR_DELETE); |
|
173
|
|
|
$gridAction->setType(DataGridActionType::DELETE_ITEM); |
|
174
|
|
|
$gridAction->setName(__('Eliminar Cuenta')); |
|
175
|
|
|
$gridAction->setTitle(__('Eliminar Cuenta')); |
|
176
|
|
|
$gridAction->setIcon($this->icons->getIconDelete()); |
|
177
|
|
|
$gridAction->setOnClickFunction('appMgmt/delete'); |
|
178
|
|
|
$gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNTMGR_DELETE)); |
|
179
|
|
|
|
|
180
|
|
|
return $gridAction; |
|
181
|
|
|
} |
|
182
|
|
|
} |