NotificationsToolbarItem   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 115
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A checkAccess() 0 4 1
A getItem() 0 4 1
A getFluidTemplateObject() 0 12 1
A hasDropDown() 0 4 1
A getDropDown() 0 7 1
A getAdditionalAttributes() 0 4 1
A getIndex() 0 4 1
1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16
17
namespace Filoucrackeur\Hubic\Backend\ToolBarItems;
18
19
use Filoucrackeur\Hubic\Service\HubicService;
20
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
use TYPO3\CMS\Extbase\Object\ObjectManager;
23
use TYPO3\CMS\Fluid\View\StandaloneView;
24
25
26
class NotificationsToolbarItem implements ToolbarItemInterface
27
{
28
29
    /**
30
     * @var ObjectManager
31
     */
32
    protected $objectManager;
33
34
    /**
35
     * @var HubicService
36
     */
37
    protected $hubicService;
38
39
    public function __construct()
40
    {
41
        $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
42
        $this->hubicService = $this->objectManager->get(HubicService::class);
43
44
    }
45
46
    /**
47
     * Checks whether the user has access to this toolbar item
48
     *
49
     * @return bool TRUE if user has access, FALSE if not
50
     */
51
    public function checkAccess(): bool
52
    {
53
        return true;
54
    }
55
56
    /**
57
     * Render "item" part of this toolbar
58
     *
59
     * @return string Toolbar item HTML
60
     */
61
    public function getItem(): string
62
    {
63
        return $this->getFluidTemplateObject('Backend/ToolBar/NotificationToolBarItem.html')->render();
64
    }
65
66
    /**
67
     * Returns a new standalone view, shorthand function
68
     *
69
     * @param string $filename Which templateFile should be used.
70
     *
71
     * @return StandaloneView
72
     */
73
    protected function getFluidTemplateObject(string $filename): StandaloneView
74
    {
75
        $view = GeneralUtility::makeInstance(StandaloneView::class);
76
        $view->setLayoutRootPaths(['EXT:hubic/Resources/Private/Layouts']);
77
        $view->setPartialRootPaths(['EXT:hubic/Resources/Private/Partials']);
78
        $view->setTemplateRootPaths(['EXT:hubic/Resources/Private/Templates']);
79
80
        $view->setTemplate($filename);
81
82
        $view->getRequest()->setControllerExtensionName('Backend');
83
        return $view;
84
    }
85
86
    /**
87
     * TRUE if this toolbar item has a collapsible drop down
88
     *
89
     * @return bool
90
     */
91
    public function hasDropDown(): bool
92
    {
93
        return true;
94
    }
95
96
    /**
97
     * Render "drop down" part of this toolbar
98
     *
99
     * @return string Drop down HTML
100
     */
101
    public function getDropDown(): string
102
    {
103
        $accounts = $this->hubicService->getAccounts();
104
        return $this->getFluidTemplateObject('Backend/ToolBar/NotificationToolBarDropDown.html')
105
            ->assign('accounts', $accounts)
106
            ->render();
107
    }
108
109
    /**
110
     * Returns an array with additional attributes added to containing <li> tag of the item.
111
     *
112
     * Typical usages are additional css classes and data-* attributes, classes may be merged
113
     * with other classes needed by the framework. Do NOT set an id attribute here.
114
     *
115
     * array(
116
     *     'class' => 'my-class',
117
     *     'data-foo' => '42',
118
     * )
119
     *
120
     * @return array List item HTML attributes
121
     */
122
    public function getAdditionalAttributes(): array
123
    {
124
        return [];
125
    }
126
127
    /**
128
     * Returns an integer between 0 and 100 to determine
129
     * the position of this item relative to others
130
     *
131
     * By default, extensions should return 50 to be sorted between main core
132
     * items and other items that should be on the very right.
133
     *
134
     * @return int 0 .. 100
135
     */
136
    public function getIndex(): int
137
    {
138
        return 10;
139
    }
140
}
141