BackendUserViewHelper::initializeArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\ViewHelpers\Be;
13
14
use TYPO3\CMS\Core\Database\Connection;
15
use TYPO3\CMS\Core\Database\ConnectionPool;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
18
19
/**
20
 * ViewHelper to render details about the given backend user
21
 */
22
class BackendUserViewHelper extends AbstractViewHelper
23
{
24
    public function initializeArguments(): void
25
    {
26
        $this->registerArgument('userUid', 'int', 'UID of backend user', true);
27
    }
28
29
    public function render(): array
30
    {
31
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
32
        $queryBuilder->getRestrictions()->removeAll();
33
        $backendUser = $queryBuilder
34
            ->select('*')
35
            ->from('be_users')
36
            ->where(
37
                $queryBuilder->expr()->eq(
38
                    'uid',
39
                    $queryBuilder->createNamedParameter($this->arguments['userUid'], Connection::PARAM_INT)
40
                )
41
            )
42
            ->executeQuery()
43
            ->fetchAssociative();
44
45
        if ($backendUser === false) {
46
            $backendUser = [];
47
        }
48
49
        return $backendUser;
50
    }
51
}
52