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\Dater; |
||
6 | use Redaxscript\Html; |
||
7 | use Redaxscript\Module; |
||
8 | use function count; |
||
9 | use function htmlspecialchars; |
||
10 | use function json_decode; |
||
11 | |||
12 | /** |
||
13 | * children class to create the article form |
||
14 | * |
||
15 | * @since 3.0.0 |
||
16 | * |
||
17 | * @package Redaxscript |
||
18 | * @category View |
||
19 | * @author Henry Ruhs |
||
20 | */ |
||
21 | |||
22 | class CommentForm extends ViewAbstract |
||
23 | { |
||
24 | /** |
||
25 | * render the view |
||
26 | * |
||
27 | * @since 3.0.0 |
||
28 | * |
||
29 | * @param int $commentId identifier of the comment |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | |||
34 | 4 | public function render(int $commentId = null) : string |
|
35 | { |
||
36 | 4 | $output = Module\Hook::trigger('adminCommentFormStart'); |
|
37 | 4 | $helperOption = new Helper\Option($this->_language); |
|
38 | 4 | $commentModel = new Admin\Model\Comment(); |
|
39 | 4 | $comment = $commentModel->getById($commentId); |
|
40 | 4 | $dater = new Dater(); |
|
41 | 4 | $dater->init($comment?->date); |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
42 | |||
43 | /* html element */ |
||
44 | |||
45 | 4 | $titleElement = new Html\Element(); |
|
46 | $titleElement |
||
47 | 4 | ->init('h2', |
|
48 | [ |
||
49 | 4 | 'class' => 'rs-admin-title-content', |
|
50 | ]) |
||
51 | 4 | ->text($comment?->id ? $comment?->text : $this->_language->get('comment_new')); |
|
52 | 4 | $formElement = new Admin\Html\Form($this->_registry, $this->_language); |
|
53 | 4 | $formElement->init( |
|
54 | [ |
||
55 | 'form' => |
||
56 | [ |
||
57 | 4 | 'class' => 'rs-admin-js-validate rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default rs-admin-form-comment' |
|
58 | ], |
||
59 | 'button' => |
||
60 | [ |
||
61 | 'create' => |
||
62 | [ |
||
63 | 'name' => self::class |
||
64 | ], |
||
65 | 'save' => |
||
66 | [ |
||
67 | 'name' => self::class |
||
68 | ] |
||
69 | ], |
||
70 | 'link' => |
||
71 | [ |
||
72 | 'cancel' => |
||
73 | [ |
||
74 | 4 | 'href' => $this->_registry->get('commentsEdit') && $this->_registry->get('commentsDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/comments' : $this->_registry->get('parameterRoute') . 'admin' |
|
75 | ], |
||
76 | 'delete' => |
||
77 | [ |
||
78 | 4 | 'href' => $comment?->id ? $this->_registry->get('parameterRoute') . 'admin/delete/comments/' . $comment?->id . '/' . $this->_registry->get('token') : null |
|
79 | ] |
||
80 | ] |
||
81 | ]); |
||
82 | |||
83 | /* create the form */ |
||
84 | |||
85 | $formElement |
||
86 | |||
87 | /* comment */ |
||
88 | |||
89 | 4 | ->radio( |
|
90 | [ |
||
91 | 4 | 'id' => self::class . '\Comment', |
|
92 | 'class' => 'rs-admin-fn-status-tab', |
||
93 | 'name' => self::class . '\Tab', |
||
94 | 'checked' => 'checked' |
||
95 | ]) |
||
96 | 4 | ->label($this->_language->get('comment'), |
|
97 | [ |
||
98 | 4 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
|
99 | 'for' => self::class . '\Comment' |
||
100 | ]) |
||
101 | 4 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
|
102 | 4 | ->label($this->_language->get('url'), |
|
103 | [ |
||
104 | 4 | 'for' => 'url' |
|
105 | ]) |
||
106 | 4 | ->url( |
|
107 | [ |
||
108 | 4 | 'id' => 'url', |
|
109 | 4 | 'name' => 'url', |
|
110 | 4 | 'value' => $comment?->url |
|
111 | ]) |
||
112 | 4 | ->append('</li><li>') |
|
113 | 4 | ->label('* ' . $this->_language->get('text'), |
|
114 | [ |
||
115 | 4 | 'for' => 'text' |
|
116 | ]) |
||
117 | 4 | ->textarea( |
|
118 | [ |
||
119 | 4 | 'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea', |
|
120 | 4 | 'id' => 'text', |
|
121 | 4 | 'name' => 'text', |
|
122 | 4 | 'required' => 'required', |
|
123 | 4 | 'value' => htmlspecialchars($comment?->text, ENT_QUOTES) |
|
124 | ]) |
||
125 | 4 | ->append('</li></ul>') |
|
126 | |||
127 | /* general */ |
||
128 | |||
129 | 4 | ->radio( |
|
130 | [ |
||
131 | 4 | 'id' => self::class . '\General', |
|
132 | 'class' => 'rs-admin-fn-status-tab', |
||
133 | 'name' => self::class . '\Tab' |
||
134 | ]) |
||
135 | 4 | ->label($this->_language->get('general'), |
|
136 | [ |
||
137 | 4 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
|
138 | 'for' => self::class . '\General' |
||
139 | ]) |
||
140 | 4 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
|
141 | 4 | ->label($this->_language->get('language'), |
|
142 | [ |
||
143 | 4 | 'for' => 'language' |
|
144 | ]) |
||
145 | 4 | ->select($helperOption->getLanguageArray(), |
|
146 | [ |
||
147 | 4 | 'value' => $comment?->language |
|
148 | ], |
||
149 | [ |
||
150 | 4 | 'id' => 'language', |
|
151 | 'name' => 'language' |
||
152 | ]) |
||
153 | 4 | ->append('</li><li>') |
|
154 | 4 | ->label($this->_language->get('article'), |
|
155 | [ |
||
156 | 4 | 'for' => 'article' |
|
157 | ]) |
||
158 | 4 | ->select($helperOption->getArticleForCommentArray(), |
|
159 | [ |
||
160 | 4 | $comment?->article |
|
161 | ], |
||
162 | [ |
||
163 | 4 | 'id' => 'article', |
|
164 | 'name' => 'article' |
||
165 | ]) |
||
166 | 4 | ->append('</li></ul>') |
|
167 | |||
168 | /* customize */ |
||
169 | |||
170 | 4 | ->radio( |
|
171 | [ |
||
172 | 4 | 'id' => self::class . '\Customize', |
|
173 | 'class' => 'rs-admin-fn-status-tab', |
||
174 | 'name' => self::class . '\Tab' |
||
175 | ]) |
||
176 | 4 | ->label($this->_language->get('customize'), |
|
177 | [ |
||
178 | 4 | 'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
|
179 | 'for' => self::class . '\Customize' |
||
180 | ]) |
||
181 | 4 | ->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
|
182 | 4 | ->label($this->_language->get('status'), |
|
183 | [ |
||
184 | 4 | 'for' => 'status' |
|
185 | ]) |
||
186 | 4 | ->checkbox(!$comment?->id || $comment?->status ? |
|
187 | [ |
||
188 | 4 | 'id' => 'status', |
|
189 | 'class' => 'rs-admin-fn-status-switch', |
||
190 | 'name' => 'status', |
||
191 | 'checked' => 'checked' |
||
192 | ] : |
||
193 | [ |
||
194 | 4 | 'id' => 'status', |
|
195 | 'class' => 'rs-admin-fn-status-switch', |
||
196 | 'name' => 'status' |
||
197 | ]) |
||
198 | 4 | ->label(null, |
|
199 | [ |
||
200 | 4 | 'class' => 'rs-admin-label-switch', |
|
201 | 4 | 'for' => 'status', |
|
202 | 4 | 'data-on' => $this->_language->get('publish'), |
|
203 | 4 | 'data-off' => $this->_language->get('unpublish') |
|
204 | ]) |
||
205 | 4 | ->append('</li><li>') |
|
206 | 4 | ->label($this->_language->get('rank'), |
|
207 | [ |
||
208 | 4 | 'for' => 'rank' |
|
209 | ]) |
||
210 | 4 | ->number( |
|
211 | [ |
||
212 | 4 | 'id' => 'rank', |
|
213 | 4 | 'name' => 'rank', |
|
214 | 4 | 'value' => $comment?->id ? $comment?->rank : $commentModel->query()->max('rank') + 1 |
|
215 | ]) |
||
216 | 4 | ->append('</li>'); |
|
217 | 4 | if ($this->_registry->get('groupsEdit')) |
|
218 | { |
||
219 | $formElement |
||
220 | 4 | ->append('<li>') |
|
221 | 4 | ->label($this->_language->get('access'), |
|
222 | [ |
||
223 | 4 | 'for' => 'access' |
|
224 | ]) |
||
225 | 4 | ->select($helperOption->getGroupArray(), |
|
226 | 4 | (array)json_decode($comment?->access), |
|
227 | [ |
||
228 | 4 | 'id' => 'access', |
|
229 | 4 | 'name' => 'access[]', |
|
230 | 4 | 'multiple' => 'multiple', |
|
231 | 4 | 'size' => count($helperOption->getGroupArray()) |
|
232 | ]) |
||
233 | 4 | ->append('</li>'); |
|
234 | } |
||
235 | $formElement |
||
236 | 4 | ->append('<li>') |
|
237 | 4 | ->label($this->_language->get('date'), |
|
238 | [ |
||
239 | 4 | 'for' => 'date' |
|
240 | ]) |
||
241 | 4 | ->datetime( |
|
242 | [ |
||
243 | 4 | 'id' => 'date', |
|
244 | 4 | 'name' => 'date', |
|
245 | 4 | 'value' => $dater->formatField() |
|
246 | ]) |
||
247 | 4 | ->append('</li></ul>'); |
|
248 | 4 | if ($comment?->id) |
|
249 | { |
||
250 | 4 | $formElement |
|
251 | 4 | ->hidden( |
|
252 | [ |
||
253 | 4 | 'name' => 'id', |
|
254 | 4 | 'value' => $comment?->id |
|
255 | 4 | ]); |
|
256 | 4 | } |
|
257 | $formElement |
||
258 | 2 | ->token() |
|
259 | ->append('<div class="rs-admin-wrapper-button">') |
||
260 | 1 | ->cancel(); |
|
261 | if ($comment?->id) |
||
262 | 2 | { |
|
263 | if ($this->_registry->get('commentsDelete')) |
||
264 | 2 | { |
|
265 | $formElement->delete(); |
||
266 | } |
||
267 | 2 | if ($this->_registry->get('commentsEdit')) |
|
268 | { |
||
269 | 1 | $formElement->save(); |
|
270 | } |
||
271 | 4 | } |
|
272 | else if ($this->_registry->get('commentsNew')) |
||
273 | { |
||
274 | $formElement->create(); |
||
275 | 4 | } |
|
276 | 4 | $formElement->append('</div>'); |
|
277 | 4 | ||
278 | /* collect output */ |
||
279 | |||
280 | $output .= $titleElement . $formElement; |
||
281 | $output .= Module\Hook::trigger('adminCommentFormEnd'); |
||
282 | return $output; |
||
283 | } |
||
284 | } |
||
285 |