Passed
Push — devel-3.0 ( 7ceb3a...2fc71e )
by Rubén
03:58
created

ItemManagerController   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 57
dl 0
loc 218
rs 10
c 0
b 0
f 0
wmc 23

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientsList() 0 5 1
A getTabsGridHelper() 0 3 1
A getCustomFieldsList() 0 5 1
A getAccountsList() 0 5 1
A getAccountsHistoryList() 0 5 1
A getAccountFilesList() 0 5 1
F getGridTabs() 0 48 11
A indexAction() 0 3 1
A initialize() 0 3 1
A getCategoriesList() 0 5 1
A getItemPresetList() 0 5 1
A getPluginsList() 0 5 1
A getTagsList() 0 5 1
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;
26
27
use SP\Core\Acl\Acl;
28
use SP\Core\Events\Event;
29
use SP\DataModel\ItemSearchData;
30
use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid;
31
use SP\Modules\Web\Controllers\Helpers\Grid\AccountHistoryGrid;
32
use SP\Modules\Web\Controllers\Helpers\Grid\CategoryGrid;
33
use SP\Modules\Web\Controllers\Helpers\Grid\ClientGrid;
34
use SP\Modules\Web\Controllers\Helpers\Grid\CustomFieldGrid;
35
use SP\Modules\Web\Controllers\Helpers\Grid\FileGrid;
36
use SP\Modules\Web\Controllers\Helpers\Grid\ItemPresetGrid;
37
use SP\Modules\Web\Controllers\Helpers\Grid\PluginGrid;
38
use SP\Modules\Web\Controllers\Helpers\Grid\TagGrid;
39
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
40
use SP\Services\Account\AccountFileService;
41
use SP\Services\Account\AccountHistoryService;
42
use SP\Services\Account\AccountService;
43
use SP\Services\Category\CategoryService;
44
use SP\Services\Client\ClientService;
45
use SP\Services\CustomField\CustomFieldDefService;
46
use SP\Services\ItemPreset\ItemPresetService;
47
use SP\Services\Plugin\PluginService;
48
use SP\Services\Tag\TagService;
49
50
/**
51
 * Class ItemManagerController
52
 *
53
 * @package SP\Modules\Web\Controllers
54
 */
55
final class ItemManagerController extends ControllerBase
56
{
57
    /**
58
     * @var ItemSearchData
59
     */
60
    protected $itemSearchData;
61
    /**
62
     * @var TabsGridHelper
63
     */
64
    protected $tabsGridHelper;
65
66
    /**
67
     * @throws \SP\Core\Exceptions\ConstraintException
68
     * @throws \SP\Core\Exceptions\QueryException
69
     */
70
    public function indexAction()
71
    {
72
        $this->getGridTabs();
73
    }
74
75
    /**
76
     * Returns a tabbed grid with items
77
     *
78
     * @throws \SP\Core\Exceptions\ConstraintException
79
     * @throws \SP\Core\Exceptions\QueryException
80
     */
81
    protected function getGridTabs()
82
    {
83
        $this->itemSearchData = new ItemSearchData();
84
        $this->itemSearchData->setLimitCount($this->configData->getAccountCount());
85
86
        $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class);
87
88
        if ($this->checkAccess(Acl::CATEGORY)) {
89
            $this->tabsGridHelper->addTab($this->getCategoriesList());
90
        }
91
92
        if ($this->checkAccess(Acl::TAG)) {
93
            $this->tabsGridHelper->addTab($this->getTagsList());
94
        }
95
96
        if ($this->checkAccess(Acl::CLIENT)) {
97
            $this->tabsGridHelper->addTab($this->getClientsList());
98
        }
99
100
        if ($this->checkAccess(Acl::CUSTOMFIELD)) {
101
            $this->tabsGridHelper->addTab($this->getCustomFieldsList());
102
        }
103
104
        if ($this->configData->isFilesEnabled() && $this->checkAccess(Acl::FILE)) {
105
            $this->tabsGridHelper->addTab($this->getAccountFilesList());
106
        }
107
108
        if ($this->checkAccess(Acl::ACCOUNTMGR)) {
109
            $this->tabsGridHelper->addTab($this->getAccountsList());
110
        }
111
112
        if ($this->checkAccess(Acl::ACCOUNTMGR_HISTORY)) {
113
            $this->tabsGridHelper->addTab($this->getAccountsHistoryList());
114
        }
115
116
        if ($this->checkAccess(Acl::ITEMPRESET)) {
117
            $this->tabsGridHelper->addTab($this->getItemPresetList());
118
        }
119
120
        if ($this->checkAccess(Acl::PLUGIN)) {
121
            $this->tabsGridHelper->addTab($this->getPluginsList());
122
        }
123
124
        $this->eventDispatcher->notifyEvent('show.itemlist.items', new Event($this));
125
126
        $this->tabsGridHelper->renderTabs(Acl::getActionRoute(Acl::ITEMS_MANAGE), $this->request->analyzeInt('tabIndex', 0));
127
128
        $this->view();
129
    }
130
131
    /**
132
     * Returns categories' data tab
133
     *
134
     * @return \SP\Html\DataGrid\DataGridTab
135
     * @throws \SP\Core\Exceptions\ConstraintException
136
     * @throws \SP\Core\Exceptions\QueryException
137
     */
138
    protected function getCategoriesList()
139
    {
140
        return $this->dic->get(CategoryGrid::class)
141
            ->getGrid($this->dic->get(CategoryService::class)->search($this->itemSearchData))
142
            ->updatePager();
143
    }
144
145
    /**
146
     * Returns tags' data tab
147
     *
148
     * @return \SP\Html\DataGrid\DataGridTab
149
     * @throws \SP\Core\Exceptions\ConstraintException
150
     * @throws \SP\Core\Exceptions\QueryException
151
     */
152
    protected function getTagsList()
153
    {
154
        return $this->dic->get(TagGrid::class)
155
            ->getGrid($this->dic->get(TagService::class)->search($this->itemSearchData))
156
            ->updatePager();
157
    }
158
159
    /**
160
     * Returns clients' data tab
161
     *
162
     * @return \SP\Html\DataGrid\DataGridTab
163
     * @throws \SP\Core\Exceptions\ConstraintException
164
     * @throws \SP\Core\Exceptions\QueryException
165
     */
166
    protected function getClientsList()
167
    {
168
        return $this->dic->get(ClientGrid::class)
169
            ->getGrid($this->dic->get(ClientService::class)->search($this->itemSearchData))
170
            ->updatePager();
171
    }
172
173
    /**
174
     * Returns custom fields' data tab
175
     *
176
     * @return \SP\Html\DataGrid\DataGridTab
177
     * @throws \SP\Core\Exceptions\ConstraintException
178
     * @throws \SP\Core\Exceptions\QueryException
179
     */
180
    protected function getCustomFieldsList()
181
    {
182
        return $this->dic->get(CustomFieldGrid::class)
183
            ->getGrid($this->dic->get(CustomFieldDefService::class)->search($this->itemSearchData))
184
            ->updatePager();
185
    }
186
187
    /**
188
     * Returns account files' data tab
189
     *
190
     * @return \SP\Html\DataGrid\DataGridTab
191
     * @throws \SP\Core\Exceptions\ConstraintException
192
     * @throws \SP\Core\Exceptions\QueryException
193
     */
194
    protected function getAccountFilesList()
195
    {
196
        return $this->dic->get(FileGrid::class)
197
            ->getGrid($this->dic->get(AccountFileService::class)->search($this->itemSearchData))
198
            ->updatePager();
199
    }
200
201
    /**
202
     * Returns accounts' data tab
203
     *
204
     * @return \SP\Html\DataGrid\DataGridTab
205
     * @throws \SP\Core\Exceptions\ConstraintException
206
     * @throws \SP\Core\Exceptions\QueryException
207
     */
208
    protected function getAccountsList()
209
    {
210
        return $this->dic->get(AccountGrid::class)
211
            ->getGrid($this->dic->get(AccountService::class)->search($this->itemSearchData))
212
            ->updatePager();
213
    }
214
215
    /**
216
     * Returns accounts' history data tab
217
     *
218
     * @return \SP\Html\DataGrid\DataGridTab
219
     * @throws \SP\Core\Exceptions\ConstraintException
220
     * @throws \SP\Core\Exceptions\QueryException
221
     */
222
    protected function getAccountsHistoryList()
223
    {
224
        return $this->dic->get(AccountHistoryGrid::class)
225
            ->getGrid($this->dic->get(AccountHistoryService::class)->search($this->itemSearchData))
226
            ->updatePager();
227
    }
228
229
    /**
230
     * Returns API tokens data tab
231
     *
232
     * @return \SP\Html\DataGrid\DataGridTab
233
     * @throws \SP\Core\Exceptions\ConstraintException
234
     * @throws \SP\Core\Exceptions\QueryException
235
     */
236
    protected function getItemPresetList()
237
    {
238
        return $this->dic->get(ItemPresetGrid::class)
239
            ->getGrid($this->dic->get(ItemPresetService::class)->search($this->itemSearchData))
240
            ->updatePager();
241
    }
242
243
    /**
244
     * Returns plugins' data tab
245
     *
246
     * @return \SP\Html\DataGrid\DataGridTab
247
     * @throws \SP\Core\Exceptions\ConstraintException
248
     * @throws \SP\Core\Exceptions\QueryException
249
     */
250
    protected function getPluginsList()
251
    {
252
        return $this->dic->get(PluginGrid::class)
253
            ->getGrid($this->dic->get(PluginService::class)->search($this->itemSearchData))
254
            ->updatePager();
255
    }
256
257
    /**
258
     * @return TabsGridHelper
259
     */
260
    public function getTabsGridHelper()
261
    {
262
        return $this->tabsGridHelper;
263
    }
264
265
    /**
266
     * @throws \Psr\Container\ContainerExceptionInterface
267
     * @throws \Psr\Container\NotFoundExceptionInterface
268
     * @throws \SP\Services\Auth\AuthException
269
     */
270
    protected function initialize()
271
    {
272
        $this->checkLoggedIn();
273
    }
274
}