Passed
Pull Request — master (#201)
by
unknown
09:49 queued 02:44
created

IsDocumentBookmarkableViewHelper::render()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 30
rs 9.1111
c 1
b 0
f 0
cc 6
nc 6
nop 0
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 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Extbase\Object\ObjectManager;
20
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
21
use \EWW\Dpf\Security\Security;
22
use \EWW\Dpf\Domain\Repository\BookmarkRepository;
23
24
class IsDocumentBookmarkableViewHelper extends AbstractViewHelper
25
{
26
    public function initializeArguments()
27
    {
28
        parent::initializeArguments();
29
30
        $this->registerArgument('identifier', 'string', '', true);
31
        $this->registerArgument('creator', 'int', '', true);
32
        $this->registerArgument('state', 'string', '', true);
33
    }
34
35
    /**
36
     * @return bool
37
     */
38
    public function render()
39
    {
40
        $identifier = $this->arguments['identifier'];
41
        $creator = $this->arguments['creator'];
42
        $state = $this->arguments['state'];
43
44
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
45
        /** @var Security $security */
46
        $security = $objectManager->get(Security::class);
47
48
        /** @var BookmarkRepository $bookmarkRepository */
49
        $bookmarkRepository = $objectManager->get(BookmarkRepository::class);
50
51
        if ($bookmarkRepository->findBookmark($security->getUser()->getUid(), $identifier)) {
52
            return false;
53
        }
54
55
        if ($security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
56
            return $state !== DocumentWorkflow::STATE_NEW_NONE;
57
        }
58
59
        if ($security->getUser()->getUserRole() === Security::ROLE_RESEARCHER) {
60
            return (
61
                $security->getUser()->getUid() !== $creator &&
62
                $state !== DocumentWorkflow::STATE_DISCARDED_NONE &&
63
                $state !== DocumentWorkflow::STATE_NONE_DELETED
64
            );
65
        }
66
67
        return false;
68
    }
69
}
70