Total Complexity | 15 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Coverage | 30.76% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | trait ToolbarTrait |
||
9 | { |
||
10 | private $toolbar = []; |
||
11 | |||
12 | /** |
||
13 | * @param $ident |
||
14 | * @throws \RuntimeException |
||
15 | * @return AbstractTool |
||
16 | */ |
||
17 | 2 | public function getTool($ident) |
|
18 | { |
||
19 | 2 | if (array_key_exists($ident, $this->toolbar)) { |
|
20 | 2 | return $this->toolbar[$ident]; |
|
21 | } |
||
22 | |||
23 | throw new \RuntimeException('Not allowed toolbar'); |
||
24 | } |
||
25 | |||
26 | 2 | public function addTool(ToolInterface $tool) |
|
27 | { |
||
28 | 2 | $this->toolbar[$tool->identifier()] = $tool; |
|
29 | 2 | } |
|
30 | |||
31 | 2 | public function getTools() |
|
32 | { |
||
33 | 2 | return $this->toolbar; |
|
34 | } |
||
35 | |||
36 | public function getActiveHeaderToolbarTools() |
||
37 | { |
||
38 | $list = []; |
||
39 | /** @var ToolInterface $tool */ |
||
40 | foreach ($this->toolbar as $tool) { |
||
41 | if ($tool->position() == ToolInterface::POSITION_HEADER && $tool->check()) { |
||
42 | $list[] = $tool; |
||
43 | } |
||
44 | } |
||
45 | |||
46 | return $list; |
||
47 | } |
||
48 | |||
49 | public function getActiveBodyToolbarToolsOnTop() |
||
50 | { |
||
51 | return $this->getActiveBodyToolbarTools(ToolInterface::POSITION_BODY_TOP); |
||
52 | } |
||
53 | |||
54 | public function getActiveBodyToolbarToolsOnBottom() |
||
55 | { |
||
56 | return $this->getActiveBodyToolbarTools(ToolInterface::POSITION_BODY_BOTTOM); |
||
57 | } |
||
58 | |||
59 | public function getActiveBodyToolbarTools($position) |
||
71 | } |
||
72 | } |
||
73 |