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

ItemPresetHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A makeDefaultPresetView() 0 5 1
A makeAccountPermissionView() 0 17 2
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;
26
27
use SP\DataModel\AccountPermission;
28
use SP\DataModel\ItemPresetData;
29
use SP\Mvc\View\Components\SelectItemAdapter;
30
use SP\Services\User\UserService;
31
use SP\Services\UserGroup\UserGroupService;
32
33
/**
34
 * Class ItemPresetHelper
35
 *
36
 * @package SP\Modules\Web\Controllers\Helpers
37
 */
38
class ItemPresetHelper extends HelperBase
39
{
40
    /**
41
     * @var SelectItemAdapter
42
     */
43
    private $users;
44
    /**
45
     * @var SelectItemAdapter
46
     */
47
    private $userGroups;
48
    /**
49
     * @var SelectItemAdapter
50
     */
51
    private $userProfiles;
52
53
    /**
54
     * @param ItemPresetData $itemPresetData
55
     *
56
     * @throws \SP\Core\Exceptions\NoSuchPropertyException
57
     */
58
    public function makeAccountPermissionView(ItemPresetData $itemPresetData)
59
    {
60
        $accountPermission = $itemPresetData->hydrate(AccountPermission::class, 'data') ?: new AccountPermission();
61
62
        $this->view->assign('typeTemplate', 'item_preset-permission');
63
64
        $this->view->assign('permission', $accountPermission);
65
66
        $this->view->assign('users', $this->users->getItemsFromModelSelected([$itemPresetData->getUserId()]));
67
        $this->view->assign('usersView', $this->users->getItemsFromModelSelected($accountPermission->getUsersView()));
68
        $this->view->assign('usersEdit', $this->users->getItemsFromModelSelected($accountPermission->getUsersEdit()));
69
70
        $this->view->assign('userGroups', $this->userGroups->getItemsFromModelSelected([$itemPresetData->getUserGroupId()]));
71
        $this->view->assign('userGroupsView', $this->userGroups->getItemsFromModelSelected($accountPermission->getUserGroupsView()));
72
        $this->view->assign('userGroupsEdit', $this->userGroups->getItemsFromModelSelected($accountPermission->getUserGroupsEdit()));
73
74
        $this->view->assign('userProfiles', $this->userProfiles->getItemsFromModelSelected([$itemPresetData->getUserProfileId()]));
75
    }
76
77
    /**
78
     * makeDefaultPresetView
79
     */
80
    public function makeDefaultPresetView()
81
    {
82
        $this->view->assign('users', $this->users->getItemsFromModel());
83
        $this->view->assign('userGroups', $this->userGroups->getItemsFromModel());
84
        $this->view->assign('userProfiles', $this->userProfiles->getItemsFromModel());
85
    }
86
87
    protected function initialize()
88
    {
89
        $this->users = SelectItemAdapter::factory(UserService::getItemsBasic());
90
        $this->userGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
91
        $this->userProfiles = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
92
    }
93
}