1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Layout action file. |
4
|
|
|
* |
5
|
|
|
* @package App |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Layout; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Layout action class. |
16
|
|
|
*/ |
17
|
|
|
class Action |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Get list view actions html. |
21
|
|
|
* |
22
|
|
|
* @param array $links |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public static function getListViewActions(array $links): string |
27
|
|
|
{ |
28
|
|
|
return '<div class="actions p-1">' . self::getDropdownButton([ |
29
|
|
|
'label' => 'actions', |
30
|
|
|
'icon' => 'fas fa-wrench', |
31
|
|
|
'class' => 'btn-sm btn-light', |
32
|
|
|
'items' => $links |
33
|
|
|
]) . '</div>'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get button html. |
38
|
|
|
* |
39
|
|
|
* @param array $link |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public static function getButton(array $link): string |
44
|
|
|
{ |
45
|
|
|
$showLabel = $link['showLabel'] ?? false; |
46
|
|
|
$btn = '<div class="c-btn-link btn-group">'; |
47
|
|
|
if (isset($link['href'])) { |
48
|
|
|
$btn .= "<a role=\"button\" href=\"{$link['href']}\" "; |
49
|
|
|
} else { |
50
|
|
|
$btn .= '<button type="button" '; |
51
|
|
|
} |
52
|
|
|
$class = 'btn '; |
53
|
|
|
if (isset($link['class'])) { |
54
|
|
|
$class .= $link['class']; |
55
|
|
|
} |
56
|
|
|
$btn .= "class=\"$class\" "; |
57
|
|
|
if (isset($link['data']) && \is_array($link['data'])) { |
58
|
|
|
foreach ($link['data'] as $key => $value) { |
59
|
|
|
$btn .= "data-{$key}=\"{$value}\" "; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
View Code Duplication |
if (!$showLabel && isset($link['label'])) { |
|
|
|
|
63
|
|
|
$btn .= 'data-placement="top" data-target="focus hover" data-content="' . \App\Language::translate($link['label'], $link['moduleName']) . '" '; |
64
|
|
|
} |
65
|
|
|
$btn .= '>'; |
66
|
|
|
if (isset($link['icon'])) { |
67
|
|
|
$btn .= "<span class=\"{$link['icon']}\"></span>"; |
68
|
|
|
} |
69
|
|
View Code Duplication |
if ($showLabel && isset($link['label'])) { |
|
|
|
|
70
|
|
|
$btn .= \App\Language::translate($link['label'], $link['moduleName']); |
71
|
|
|
} |
72
|
|
|
$btn .= isset($link['href']) ? '</a>' : '</button>'; |
73
|
|
|
return $btn . '</div>'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get dropdown button html. |
78
|
|
|
* |
79
|
|
|
* @param array $link |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public static function getDropdownButton(array $link): string |
84
|
|
|
{ |
85
|
|
|
$html = '<div class="dropdown"><button type="button"'; |
86
|
|
|
$class = 'dropdown-toggle btn '; |
87
|
|
|
if (isset($link['class'])) { |
88
|
|
|
$class .= $link['class']; |
89
|
|
|
} |
90
|
|
|
$html .= "class=\"$class\" data-toggle=\"dropdown\" aria-haspopup=\"true\">"; |
91
|
|
|
if (isset($link['icon'])) { |
92
|
|
|
$html .= "<span class=\"{$link['icon']}\"></span>"; |
93
|
|
|
} |
94
|
|
|
$html .= '</button><div class="dropdown-menu">'; |
95
|
|
|
foreach ($link['items'] as $item) { |
96
|
|
|
$html .= self::getButton($item); |
97
|
|
|
} |
98
|
|
|
$html .= '</div></div>'; |
99
|
|
|
return $html; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.