Passed
Push — devel-3.0 ( ca620b...2581df )
by Rubén
03:02
created

SecurityManagerController::getGridTabs()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 0
dl 0
loc 22
rs 9.9
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;
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\EventlogGrid;
31
use SP\Modules\Web\Controllers\Helpers\Grid\TrackGrid;
32
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
33
use SP\Services\EventLog\EventlogService;
34
use SP\Services\Track\TrackService;
35
36
/**
37
 * Class SecurityManagerController
38
 *
39
 * @package SP\Modules\Web\Controllers
40
 */
41
final class SecurityManagerController extends ControllerBase
42
{
43
    /**
44
     * @var ItemSearchData
45
     */
46
    protected $itemSearchData;
47
    /**
48
     * @var TabsGridHelper
49
     */
50
    protected $tabsGridHelper;
51
52
    /**
53
     * @throws \DI\DependencyException
54
     * @throws \DI\NotFoundException
55
     * @throws \SP\Core\Exceptions\ConstraintException
56
     * @throws \SP\Core\Exceptions\QueryException
57
     */
58
    public function indexAction()
59
    {
60
        $this->getGridTabs();
61
    }
62
63
    /**
64
     * Returns a tabbed grid with items
65
     *
66
     * @throws \DI\DependencyException
67
     * @throws \DI\NotFoundException
68
     * @throws \SP\Core\Exceptions\ConstraintException
69
     * @throws \SP\Core\Exceptions\QueryException
70
     */
71
    protected function getGridTabs()
72
    {
73
        $this->itemSearchData = new ItemSearchData();
74
        $this->itemSearchData->setLimitCount($this->configData->getAccountCount());
75
76
        $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class);
77
78
        if ($this->checkAccess(Acl::EVENTLOG)
79
            && $this->configData->isLogEnabled()
80
        ) {
81
            $this->tabsGridHelper->addTab($this->getEventlogList());
82
        }
83
84
        if ($this->checkAccess(Acl::TRACK)) {
85
            $this->tabsGridHelper->addTab($this->getTracksList());
86
        }
87
88
        $this->eventDispatcher->notifyEvent('show.itemlist.security', new Event($this));
89
90
        $this->tabsGridHelper->renderTabs(Acl::getActionRoute(Acl::SECURITY_MANAGE), $this->request->analyzeInt('tabIndex', 0));
91
92
        $this->view();
93
    }
94
95
    /**
96
     * Returns eventlog data tab
97
     *
98
     * @return \SP\Html\DataGrid\DataGridTab
99
     * @throws \DI\DependencyException
100
     * @throws \DI\NotFoundException
101
     * @throws \SP\Core\Exceptions\ConstraintException
102
     * @throws \SP\Core\Exceptions\QueryException
103
     */
104
    protected function getEventlogList()
105
    {
106
        return $this->dic->get(EventlogGrid::class)
107
            ->getGrid($this->dic->get(EventlogService::class)->search($this->itemSearchData))
108
            ->updatePager();
109
    }
110
111
    /**
112
     * Returns tracks data tab
113
     *
114
     * @return \SP\Html\DataGrid\DataGridTab
115
     * @throws \DI\DependencyException
116
     * @throws \DI\NotFoundException
117
     * @throws \SP\Core\Exceptions\ConstraintException
118
     * @throws \SP\Core\Exceptions\QueryException
119
     */
120
    protected function getTracksList()
121
    {
122
        return $this->dic->get(TrackGrid::class)
123
            ->getGrid($this->dic->get(TrackService::class)->search($this->itemSearchData))
124
            ->updatePager();
125
    }
126
127
    /**
128
     * @return TabsGridHelper
129
     */
130
    public function getTabsGridHelper()
131
    {
132
        return $this->tabsGridHelper;
133
    }
134
135
    /**
136
     * @throws \Psr\Container\ContainerExceptionInterface
137
     * @throws \Psr\Container\NotFoundExceptionInterface
138
     * @throws \SP\Services\Auth\AuthException
139
     */
140
    protected function initialize()
141
    {
142
        $this->checkLoggedIn();
143
    }
144
}