Passed
Push — devel-3.0 ( 2fc71e...3e43d6 )
by Rubén
03:39
created

ItemManagerController::getGridTabs()   C

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