1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Admin\View; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Html; |
6
|
|
|
use Redaxscript\Module; |
7
|
|
|
use function count; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* children class to create the admin group table |
11
|
|
|
* |
12
|
|
|
* @since 4.0.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category View |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class GroupTable extends ViewAbstract |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* render the view |
23
|
|
|
* |
24
|
|
|
* @since 4.0.0 |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
public function render() : string |
30
|
|
|
{ |
31
|
|
|
$output = Module\Hook::trigger('adminGroupTableStart'); |
32
|
|
|
$parameterRoute = $this->_registry->get('parameterRoute'); |
33
|
|
|
$groupsNew = $this->_registry->get('groupsNew'); |
34
|
|
|
|
35
|
|
|
/* html element */ |
36
|
|
|
|
37
|
|
|
$element = new Html\Element(); |
38
|
|
|
$titleElement = $element |
39
|
|
|
->copy() |
40
|
|
|
->init('h2', |
41
|
|
|
[ |
42
|
|
|
'class' => 'rs-admin-title-content', |
43
|
|
|
]) |
44
|
|
|
->text($this->_language->get('groups')); |
|
|
|
|
45
|
|
|
$linkElement = $element |
46
|
|
|
->copy() |
47
|
|
|
->init('a', |
48
|
|
|
[ |
49
|
|
|
'class' => 'rs-admin-button-default rs-admin-button-create', |
50
|
|
|
'href' => $parameterRoute . 'admin/new/groups' |
51
|
|
|
]) |
52
|
|
|
->text($this->_language->get('group_new')); |
|
|
|
|
53
|
|
|
|
54
|
|
|
/* collect output */ |
55
|
|
|
|
56
|
|
|
$output .= $titleElement; |
57
|
|
|
if ($groupsNew) |
58
|
|
|
{ |
59
|
|
|
$output .= $linkElement; |
60
|
|
|
} |
61
|
|
|
$output .= $this->_renderTable(); |
62
|
|
|
$output .= Module\Hook::trigger('adminGroupTableEnd'); |
63
|
|
|
return $output; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* render the table |
68
|
|
|
* |
69
|
|
|
* @since 4.0.0 |
70
|
|
|
* |
71
|
|
|
* @return string|null |
72
|
|
|
*/ |
73
|
|
|
|
74
|
|
|
protected function _renderTable() : ?string |
75
|
|
|
{ |
76
|
|
|
$output = null; |
77
|
|
|
$outputHead = null; |
78
|
|
|
$outputBody = null; |
79
|
|
|
$outputFoot = null; |
80
|
|
|
$tableArray = |
81
|
|
|
[ |
82
|
|
|
'name' => $this->_language->get('name'), |
83
|
|
|
'alias' => $this->_language->get('alias'), |
84
|
|
|
'description' => $this->_language->get('description') |
85
|
|
|
]; |
86
|
|
|
$adminControl = new Helper\Control($this->_registry, $this->_language); |
87
|
|
|
$adminControl->init(); |
88
|
|
|
$userModel = new Admin\Model\Group(); |
89
|
|
|
$groups = $userModel->getAll(); |
90
|
|
|
$groupsTotal = $groups->count(); |
91
|
|
|
|
92
|
|
|
/* html element */ |
93
|
|
|
|
94
|
|
|
$element = new Html\Element(); |
95
|
|
|
$wrapperElement = $element |
96
|
|
|
->copy() |
97
|
|
|
->init('div', |
98
|
|
|
[ |
99
|
|
|
'class' => 'rs-admin-wrapper-table' |
100
|
|
|
]); |
101
|
|
|
$tableElement = $element |
102
|
|
|
->copy() |
103
|
|
|
->init('table', |
104
|
|
|
[ |
105
|
|
|
'class' => 'rs-admin-table-default' |
106
|
|
|
]); |
107
|
|
|
$theadElement = $element->copy()->init('thead'); |
108
|
|
|
$tbodyElement = $element->copy()->init('tbody'); |
109
|
|
|
$tfootElement = $element->copy()->init('tfoot'); |
110
|
|
|
$trElement = $element->copy()->init('tr'); |
111
|
|
|
$thElement = $element->copy()->init('th'); |
112
|
|
|
$tdElement = $element->copy()->init('td'); |
113
|
|
|
|
114
|
|
|
/* process table */ |
115
|
|
|
|
116
|
|
|
foreach ($tableArray as $key => $value) |
117
|
|
|
{ |
118
|
|
|
$outputHead .= $thElement->copy()->text($value); |
|
|
|
|
119
|
|
|
$outputFoot .= $tdElement->copy()->text($value); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/* process categories */ |
123
|
|
|
|
124
|
|
|
if ($groupsTotal) |
125
|
|
|
{ |
126
|
|
|
foreach ($groups as $key => $value) |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
$outputBody .= $trElement |
129
|
|
|
->copy() |
130
|
|
|
->attr('id', 'row-' . $value->id) |
131
|
|
|
->addClass(!$value->status ? 'rs-admin-is-disabled' : null) |
132
|
|
|
->html( |
133
|
|
|
$tdElement->copy()->html($value->name . $adminControl->render('groups', $value->id, $value->alias, $value->status)) . |
134
|
|
|
$tdElement->copy()->text($value->alias) . |
135
|
|
|
$tdElement->copy()->text($value->description) |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
else |
140
|
|
|
{ |
141
|
|
|
$outputBody .= $trElement |
142
|
|
|
->copy() |
143
|
|
|
->html( |
144
|
|
|
$tdElement |
145
|
|
|
->copy() |
146
|
|
|
->attr('colspan', count($tableArray)) |
147
|
|
|
->text($this->_language->get('group_no')) |
|
|
|
|
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/* collect output */ |
152
|
|
|
|
153
|
|
|
$outputHead = $theadElement->html( |
154
|
|
|
$trElement->html($outputHead) |
155
|
|
|
); |
156
|
|
|
$outputBody = $tbodyElement->html($outputBody); |
157
|
|
|
$outputFoot = $tfootElement->html( |
158
|
|
|
$trElement->html($outputFoot) |
159
|
|
|
); |
160
|
|
|
$output .= $wrapperElement->copy()->html( |
161
|
|
|
$tableElement->html($outputHead . $outputBody . $outputFoot) |
162
|
|
|
); |
163
|
|
|
return $output; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.