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