Passed
Pull Request — master (#166)
by
unknown
22:16
created

CreatorRoleViewHelper::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 17
rs 10
1
<?php
2
namespace EWW\Dpf\ViewHelpers;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use \EWW\Dpf\Security\Security;
18
19
class CreatorRoleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
20
{
21
    /**
22
     * frontendUserHelper
23
     *
24
     * @var \EWW\Dpf\Helper\FrontendUserHelper
25
     * @inject
26
     */
27
    protected $frontendUserHelper = null;
28
29
    /**
30
     * security
31
     *
32
     * @var \EWW\Dpf\Security\Security
33
     * @inject
34
     */
35
    protected $security = null;
36
37
    /**
38
     * Shows the frontend user name of the given frontenduser user id.
39
     *
40
     * @param int $feUserId
41
     * @return string
42
     */
43
    public function render($feUserId)
44
    {
45
        if ($this->security->getUser()->getUid() == $feUserId) {
46
            return "self";
47
        }
48
49
        $userRole = $this->frontendUserHelper->getUserRole($feUserId);
50
51
        if ($userRole === Security::ROLE_LIBRARIAN) {
52
            return "librarian";
53
        }
54
55
        if ($userRole == Security::ROLE_RESEARCHER) {
56
            return "user";
57
        }
58
59
        return null;
60
    }
61
}
62