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

ItemPresetHelper::makeDefaultPresetView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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