Passed
Push — devel-3.0 ( 4622e9...e92637 )
by Rubén
03:18
created

AccountHistoryGrid::getRestoreAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 12
rs 9.9666
c 0
b 0
f 0
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 AccountHistoryGrid
40
 *
41
 * @package SP\Modules\Web\Controllers\Helpers\Grid
42
 */
43
final class AccountHistoryGrid 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->getRestoreAction());
67
68
        $deleteAction = $this->getDeleteAction();
69
70
        $grid->setDataActions($deleteAction);
71
        $grid->setDataActions($deleteAction, true);
72
73
        $grid->setTime(round(getElapsedTime($this->queryTimeStart), 5));
0 ignored issues
show
Bug introduced by
round(getElapsedTime($this->queryTimeStart), 5) of type double is incompatible with the type integer expected by parameter $time of SP\Html\DataGrid\DataGridBase::setTime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        $grid->setTime(/** @scrutinizer ignore-type */ round(getElapsedTime($this->queryTimeStart), 5));
Loading history...
74
75
        return $grid;
76
    }
77
78
    /**
79
     * @return DataGridInterface
80
     */
81
    protected function getGridLayout(): DataGridInterface
82
    {
83
        // Grid
84
        $gridTab = new DataGridTab($this->view->getTheme());
85
        $gridTab->setId('tblAccountsHistory');
86
        $gridTab->setDataRowTemplate('datagrid-rows', 'grid');
87
        $gridTab->setDataPagerTemplate('datagrid-nav-full', 'grid');
88
        $gridTab->setHeader($this->getHeader());
89
        $gridTab->setData($this->getData());
90
        $gridTab->setTitle(__('Cuentas (H)'));
91
92
        return $gridTab;
93
    }
94
95
    /**
96
     * @return DataGridHeader
97
     */
98
    protected function getHeader(): DataGridHeader
99
    {
100
        // Grid Header
101
        $gridHeader = new DataGridHeader();
102
        $gridHeader->addHeader(__('Nombre'));
103
        $gridHeader->addHeader(__('Cliente'));
104
        $gridHeader->addHeader(__('Categoría'));
105
        $gridHeader->addHeader(__('Fecha'));
106
        $gridHeader->addHeader(__('Estado'));
107
108
        return $gridHeader;
109
    }
110
111
    /**
112
     * @return DataGridData
113
     */
114
    protected function getData(): DataGridData
115
    {
116
        // Grid Data
117
        $iconEdit = clone $this->icons->getIconEdit();
118
        $iconDelete = clone $this->icons->getIconDelete();
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('date');
127
        $gridData->addDataRowSourceWithIcon('isModify', $iconEdit->setTitle(__('Modificada'))->setClass('opacity50'));
128
        $gridData->addDataRowSourceWithIcon('isDeleted', $iconDelete->setTitle(__('Eliminada'))->setClass('opacity50'));
129
        $gridData->setData($this->queryResult);
130
131
        return $gridData;
132
    }
133
134
    /**
135
     * @return DataGridActionSearch
136
     */
137
    private function getSearchAction()
138
    {
139
        $gridActionSearch = new DataGridActionSearch();
140
        $gridActionSearch->setId(ActionsInterface::ACCOUNTMGR_HISTORY_SEARCH);
141
        $gridActionSearch->setType(DataGridActionType::SEARCH_ITEM);
142
        $gridActionSearch->setName('frmSearchAccountHistory');
143
        $gridActionSearch->setTitle(__('Buscar Cuenta'));
144
        $gridActionSearch->setOnSubmitFunction('appMgmt/search');
145
        $gridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNTMGR_HISTORY_SEARCH));
146
147
        return $gridActionSearch;
148
    }
149
150
    /**
151
     * @return DataGridAction
152
     */
153
    private function getRestoreAction()
154
    {
155
        $gridAction = new DataGridAction();
156
        $gridAction->setId(ActionsInterface::ACCOUNTMGR_HISTORY_RESTORE);
157
        $gridAction->setType(DataGridActionType::EDIT_ITEM);
158
        $gridAction->setName(__('Restaurar Cuenta'));
159
        $gridAction->setTitle(__('Restaurar Cuenta'));
160
        $gridAction->setIcon($this->icons->getIconRestore());
161
        $gridAction->setOnClickFunction('accountManager/restore');
162
        $gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNTMGR_HISTORY_RESTORE));
163
164
        return $gridAction;
165
    }
166
167
    /**
168
     * @return DataGridAction
169
     */
170
    private function getDeleteAction()
171
    {
172
        $gridAction = new DataGridAction();
173
        $gridAction->setId(ActionsInterface::ACCOUNTMGR_HISTORY_DELETE);
174
        $gridAction->setType(DataGridActionType::DELETE_ITEM);
175
        $gridAction->setName(__('Eliminar Cuenta'));
176
        $gridAction->setTitle(__('Eliminar Cuenta'));
177
        $gridAction->setIcon($this->icons->getIconDelete());
178
        $gridAction->setOnClickFunction('appMgmt/delete');
179
        $gridAction->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNTMGR_HISTORY_DELETE));
180
181
        return $gridAction;
182
    }
183
}