These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | 2 | public function render() : string |
|
30 | { |
||
31 | 2 | $output = Module\Hook::trigger('adminGroupTableStart'); |
|
32 | 2 | $parameterRoute = $this->_registry->get('parameterRoute'); |
|
33 | 2 | $groupsNew = $this->_registry->get('groupsNew'); |
|
34 | |||
35 | /* html element */ |
||
36 | |||
37 | 2 | $element = new Html\Element(); |
|
38 | $titleElement = $element |
||
39 | 2 | ->copy() |
|
40 | 2 | ->init('h2', |
|
41 | [ |
||
42 | 2 | 'class' => 'rs-admin-title-content', |
|
43 | ]) |
||
44 | 2 | ->text($this->_language->get('groups')); |
|
45 | $linkElement = $element |
||
46 | 2 | ->copy() |
|
47 | 2 | ->init('a', |
|
48 | [ |
||
49 | 2 | 'class' => 'rs-admin-button-default rs-admin-button-create', |
|
50 | 2 | 'href' => $parameterRoute . 'admin/new/groups' |
|
51 | ]) |
||
52 | 2 | ->text($this->_language->get('group_new')); |
|
53 | |||
54 | /* collect output */ |
||
55 | |||
56 | 2 | $output .= $titleElement; |
|
57 | 2 | if ($groupsNew) |
|
58 | { |
||
59 | 1 | $output .= $linkElement; |
|
60 | } |
||
61 | 2 | $output .= $this->_renderTable(); |
|
62 | 2 | $output .= Module\Hook::trigger('adminGroupTableEnd'); |
|
63 | 2 | return $output; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * render the table |
||
68 | * |
||
69 | * @since 4.0.0 |
||
70 | * |
||
71 | * @return string|null |
||
72 | */ |
||
73 | |||
74 | 2 | protected function _renderTable() : ?string |
|
75 | { |
||
76 | 2 | $output = null; |
|
77 | 2 | $outputHead = null; |
|
78 | 2 | $outputBody = null; |
|
79 | 2 | $outputFoot = null; |
|
80 | $tableArray = |
||
81 | [ |
||
82 | 2 | 'name' => $this->_language->get('name'), |
|
83 | 2 | 'alias' => $this->_language->get('alias'), |
|
84 | 2 | 'description' => $this->_language->get('description') |
|
85 | ]; |
||
86 | 2 | $adminControl = new Helper\Control($this->_registry, $this->_language); |
|
87 | 2 | $adminControl->init(); |
|
88 | 2 | $userModel = new Admin\Model\Group(); |
|
89 | 2 | $groups = $userModel->getAll(); |
|
90 | 2 | $groupsTotal = $groups->count(); |
|
91 | |||
92 | /* html element */ |
||
93 | |||
94 | 2 | $element = new Html\Element(); |
|
95 | $wrapperElement = $element |
||
96 | 2 | ->copy() |
|
97 | 2 | ->init('div', |
|
98 | [ |
||
99 | 2 | 'class' => 'rs-admin-wrapper-table' |
|
100 | ]); |
||
101 | $tableElement = $element |
||
102 | 2 | ->copy() |
|
103 | 2 | ->init('table', |
|
104 | [ |
||
105 | 2 | 'class' => 'rs-admin-table-default' |
|
106 | ]); |
||
107 | 2 | $theadElement = $element->copy()->init('thead'); |
|
108 | 2 | $tbodyElement = $element->copy()->init('tbody'); |
|
109 | 2 | $tfootElement = $element->copy()->init('tfoot'); |
|
110 | 2 | $trElement = $element->copy()->init('tr'); |
|
111 | 2 | $thElement = $element->copy()->init('th'); |
|
112 | 2 | $tdElement = $element->copy()->init('td'); |
|
113 | |||
114 | /* process table */ |
||
115 | |||
116 | 2 | foreach ($tableArray as $key => $value) |
|
117 | { |
||
118 | 2 | $outputHead .= $thElement->copy()->text($value); |
|
119 | 2 | $outputFoot .= $tdElement->copy()->text($value); |
|
120 | } |
||
121 | |||
122 | /* process categories */ |
||
123 | |||
124 | 2 | if ($groupsTotal) |
|
125 | { |
||
126 | 2 | foreach ($groups as $key => $value) |
|
0 ignored issues
–
show
|
|||
127 | { |
||
128 | $outputBody .= $trElement |
||
129 | 2 | ->copy() |
|
130 | 2 | ->attr('id', 'row-' . $value->id) |
|
131 | 2 | ->addClass(!$value->status ? 'rs-admin-is-disabled' : null) |
|
132 | 2 | ->html( |
|
133 | 2 | $tdElement->copy()->html($value->name . $adminControl->render('groups', $value->id, $value->alias, $value->status)) . |
|
134 | 2 | $tdElement->copy()->text($value->alias) . |
|
135 | 2 | $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 | 2 | $outputHead = $theadElement->html( |
|
154 | 2 | $trElement->html($outputHead) |
|
155 | ); |
||
156 | 2 | $outputBody = $tbodyElement->html($outputBody); |
|
157 | 2 | $outputFoot = $tfootElement->html( |
|
158 | 2 | $trElement->html($outputFoot) |
|
159 | ); |
||
160 | 2 | $output .= $wrapperElement->copy()->html( |
|
161 | 2 | $tableElement->html($outputHead . $outputBody . $outputFoot) |
|
162 | ); |
||
163 | 2 | return $output; |
|
164 | } |
||
165 | } |
||
166 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.