Completed
Push — master ( 19fed6...e690ae )
by
unknown
14:30
created

BackendUserGroupController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
c 0
b 0
f 0
dl 0
loc 112
rs 10
wmc 13

8 Methods

Rating   Name   Duplication   Size   Complexity  
A injectBackendUserGroupRepository() 0 3 1
A __construct() 0 4 1
A removeAllFromCompareListAction() 0 5 1
A addToCompareListAction() 0 8 1
A getBackendUser() 0 3 1
A indexAction() 0 11 2
A compareAction() 0 17 4
A removeFromCompareListAction() 0 11 2
1
<?php
2
3
namespace TYPO3\CMS\Beuser\Controller;
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
use TYPO3\CMS\Beuser\Service\UserInformationService;
19
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
21
22
/**
23
 * Backend module user group administration controller
24
 * @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
25
 */
26
class BackendUserGroupController extends ActionController
27
{
28
    /**
29
     * @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
30
     */
31
    protected $backendUserGroupRepository;
32
33
    /**
34
     * @param \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository
35
     */
36
    public function injectBackendUserGroupRepository(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository)
37
    {
38
        $this->backendUserGroupRepository = $backendUserGroupRepository;
39
    }
40
41
    /**
42
     * @var UserInformationService
43
     */
44
    protected $userInformationService;
45
46
    public function __construct(
47
        UserInformationService $userInformationService
48
    ) {
49
        $this->userInformationService = $userInformationService;
50
    }
51
52
    /**
53
     * Displays all BackendUserGroups
54
     */
55
    public function indexAction(): void
56
    {
57
        $compareGroupUidList = array_keys($this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? []);
58
        $this->view->assignMultiple(
59
            [
60
                'shortcutLabel' => 'backendUserGroupsMenu',
61
                'backendUserGroups' => $this->backendUserGroupRepository->findAll(),
62
                'compareGroupUidList' => array_map(static function ($value) { // uid as key and force value to 1
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
                'compareGroupUidList' => array_map(static function (/** @scrutinizer ignore-unused */ $value) { // uid as key and force value to 1

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
63
                    return 1;
64
                }, array_flip($compareGroupUidList)),
65
                'compareGroupList' => !empty($compareGroupUidList) ? $this->backendUserGroupRepository->findByUidList($compareGroupUidList) : [],
66
            ]
67
        );
68
    }
69
70
    public function compareAction(): void
71
    {
72
        $compareGroupUidList = array_keys($this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? []);
73
74
        $compareData = [];
75
        foreach ($compareGroupUidList as $uid) {
76
            if ($compareInformation = $this->userInformationService->getGroupInformation($uid)) {
77
                $compareData[] = $compareInformation;
78
            }
79
        }
80
        if (empty($compareData)) {
81
            $this->redirect('index');
82
        }
83
84
        $this->view->assignMultiple([
85
            'shortcutLabel' => 'compareBackendUsersGroups',
86
            'compareGroupList' => $compareData,
87
        ]);
88
    }
89
90
    /**
91
     * Attaches one backend user group to the compare list
92
     *
93
     * @param int $uid
94
     */
95
    public function addToCompareListAction(int $uid): void
96
    {
97
        $list = $this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? [];
98
        $list[$uid] = true;
99
        $this->getBackendUser()->uc['beuser']['compareGroupUidList'] = $list;
100
        $this->getBackendUser()->writeUC();
101
102
        $this->redirect('index');
103
    }
104
105
    /**
106
     * Removes given backend user group to the compare list
107
     *
108
     * @param int $uid
109
     * @param int $redirectToCompare
110
     */
111
    public function removeFromCompareListAction(int $uid, int $redirectToCompare = 0): void
112
    {
113
        $list = $this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? [];
114
        unset($list[$uid]);
115
        $this->getBackendUser()->uc['beuser']['compareGroupUidList'] = $list;
116
        $this->getBackendUser()->writeUC();
117
118
        if ($redirectToCompare) {
119
            $this->redirect('compare');
120
        } else {
121
            $this->redirect('index');
122
        }
123
    }
124
125
    /**
126
     * Removes all backend user groups from the compare list
127
     */
128
    public function removeAllFromCompareListAction(): void
129
    {
130
        $this->getBackendUser()->uc['beuser']['compareGroupUidList'] = [];
131
        $this->getBackendUser()->writeUC();
132
        $this->redirect('index');
133
    }
134
135
    protected function getBackendUser(): BackendUserAuthentication
136
    {
137
        return $GLOBALS['BE_USER'];
138
    }
139
}
140