ItemManagerController::getGridTabs()   C
last analyzed

Complexity

Conditions 10
Paths 256

Size

Total Lines 44
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 22
nc 256
nop 0
dl 0
loc 44
rs 6.1333
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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