Completed
Push — master ( 9027b3...432a29 )
by Henry
12:53 queued 02:53
created

includes/Admin/View/GroupForm.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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 Redaxscript\Validator;
8
use function count;
9
use function json_decode;
10
11
/**
12
 * children class to create the group form
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category View
18
 * @author Henry Ruhs
19
 */
20
21
class GroupForm extends ViewAbstract
22
{
23
	/**
24
	 * render the view
25
	 *
26
	 * @since 3.0.0
27
	 *
28
	 * @param int $groupId identifier of the group
29
	 *
30
	 * @return string
31
	 */
32
33 6
	public function render(int $groupId = null) : string
34
	{
35 6
		$output = Module\Hook::trigger('adminGroupFormStart');
36 6
		$groupModel = new Admin\Model\Group();
37 6
		$group = $groupModel->getById($groupId);
38 6
		$aliasValidator = new Validator\Alias();
39 6
		$nameValidator = new Validator\Name();
40 6
		$helperOption = new Helper\Option($this->_language);
41
42
		/* html element */
43
44 6
		$titleElement = new Html\Element();
45
		$titleElement
46 6
			->init('h2',
47
			[
48 6
				'class' => 'rs-admin-title-content',
49
			])
50 6
			->text($group?->id ? $group?->name : $this->_language->get('group_new'));
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
51 6
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
52 6
		$formElement->init(
53
		[
54
			'form' =>
55
			[
56 6
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default rs-admin-form-group'
57
			],
58
			'button' =>
59
			[
60
				'create' =>
61
				[
62
					'name' => self::class
63
				],
64
				'save' =>
65
				[
66
					'name' => self::class
67
				]
68
			],
69
			'link' =>
70
			[
71
				'cancel' =>
72
				[
73 6
					'href' => $this->_registry->get('groupsEdit') && $this->_registry->get('groupsDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/groups' : $this->_registry->get('parameterRoute') . 'admin'
74
				],
75
				'delete' =>
76
				[
77 6
					'href' => $group?->id ? $this->_registry->get('parameterRoute') . 'admin/delete/groups/' . $group?->id . '/' . $this->_registry->get('token') : null
78
				]
79
			]
80
		]);
81
82
		/* create the form */
83
84
		$formElement
85
86
			/* group */
87
88 6
			->radio(
89
			[
90 6
				'id' => self::class . '\Group',
91
				'class' => 'rs-admin-fn-status-tab',
92
				'name' => self::class . '\Tab',
93
				'checked' => 'checked'
94
			])
95 6
			->label($this->_language->get('group'),
96
			[
97 6
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
98
				'for' => self::class . '\Group'
99
			])
100 6
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
101 6
			->label($this->_language->get('name'),
102
			[
103 6
				'for' => 'name'
104
			])
105 6
			->text(
106
			[
107 6
				'autofocus' => 'autofocus',
108 6
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
109 6
				'id' => 'name',
110 6
				'name' => 'name',
111 6
				'pattern' => $nameValidator->getPattern(),
112 6
				'required' => 'required',
113 6
				'value' => $group?->name
114
			])
115 6
			->append('</li><li>')
116 6
			->label($this->_language->get('alias'),
117
			[
118 6
				'for' => 'alias'
119
			])
120 6
			->text(
121
			[
122 6
				'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
123 6
				'id' => 'alias',
124 6
				'name' => 'alias',
125 6
				'pattern' => $aliasValidator->getPattern(),
126 6
				'required' => 'required',
127 6
				'value' => $group?->alias
128
			])
129 6
			->append('</li><li>')
130 6
			->label($this->_language->get('description'),
131
			[
132 6
				'for' => 'description'
133
			])
134 6
			->textarea(
135
			[
136 6
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
137 6
				'id' => 'description',
138 6
				'name' => 'description',
139 6
				'rows' => 1,
140 6
				'value' => $group?->description
141
			])
142 6
			->append('</li></ul>');
143 6
		if (!$group?->id || $group?->id > 1)
144
		{
145
			$formElement
146
147
				/* access */
148
149 4
				->radio(
150
				[
151 4
					'id' => self::class . '\Access',
152
					'class' => 'rs-admin-fn-status-tab',
153
					'name' => self::class . '\Tab'
154
				])
155 4
				->label($this->_language->get('access'),
156
				[
157 4
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
158
					'for' => self::class . '\Access'
159
				])
160 4
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
161 4
				->label($this->_language->get('categories'),
162
				[
163 4
					'for' => 'categories'
164
				])
165 4
				->select($helperOption->getPermissionArray('groups'),
166 4
				(array)json_decode($group?->categories),
167
				[
168 4
					'id' => 'categories',
169 4
					'name' => 'categories[]',
170 4
					'multiple' => 'multiple',
171 4
					'size' => count($helperOption->getPermissionArray('groups'))
172
				])
173 4
				->append('</li><li>')
174 4
				->label($this->_language->get('articles'),
175
				[
176 4
					'for' => 'articles'
177
				])
178 4
				->select($helperOption->getPermissionArray('groups'),
179 4
				(array)json_decode($group?->articles),
180
				[
181 4
					'id' => 'articles',
182 4
					'name' => 'articles[]',
183 4
					'multiple' => 'multiple',
184 4
					'size' => count($helperOption->getPermissionArray('groups'))
185
				])
186 4
				->append('</li><li>')
187 4
				->label($this->_language->get('extras'),
188
				[
189 4
					'for' => 'extras'
190
				])
191 4
				->select($helperOption->getPermissionArray('groups'),
192 4
				(array)json_decode($group?->extras),
193
				[
194 4
					'id' => 'extras',
195 4
					'name' => 'extras[]',
196 4
					'multiple' => 'multiple',
197 4
					'size' => count($helperOption->getPermissionArray('groups'))
198
				])
199 4
				->append('</li><li>')
200 4
				->label($this->_language->get('comments'),
201
				[
202 4
					'for' => 'comments'
203
				])
204 4
				->select($helperOption->getPermissionArray('groups'),
205 4
				(array)json_decode($group?->comments),
206
				[
207 4
					'id' => 'comments',
208 4
					'name' => 'comments[]',
209 4
					'multiple' => 'multiple',
210 4
					'size' => count($helperOption->getPermissionArray('groups'))
211
				])
212 4
				->append('</li><li>')
213 4
				->label($this->_language->get('groups'),
214
				[
215 4
					'for' => 'groups'
216
				])
217 4
				->select($helperOption->getPermissionArray('groups'),
218 4
				(array)json_decode($group?->groups),
219
				[
220 4
					'id' => 'groups',
221 4
					'name' => 'groups[]',
222 4
					'multiple' => 'multiple',
223 4
					'size' => count($helperOption->getPermissionArray('groups'))
224
				])
225 4
				->append('</li><li>')
226 4
				->label($this->_language->get('users'),
227
				[
228 4
					'for' => 'users'
229
				])
230 4
				->select($helperOption->getPermissionArray('groups'),
231 4
				(array)json_decode($group?->users),
232
				[
233 4
					'id' => 'users',
234 4
					'name' => 'users[]',
235 4
					'multiple' => 'multiple',
236 4
					'size' => count($helperOption->getPermissionArray('groups'))
237
				])
238 4
				->append('</li><li>')
239 4
				->label($this->_language->get('modules'),
240
				[
241 4
					'for' => 'modules'
242
				])
243 4
				->select($helperOption->getPermissionArray('modules'),
244 4
				(array)json_decode($group?->modules),
245
				[
246 4
					'id' => 'modules',
247 4
					'name' => 'modules[]',
248 4
					'multiple' => 'multiple',
249 4
					'size' => count($helperOption->getPermissionArray('modules'))
250
				])
251 4
				->append('</li><li>')
252 4
				->label($this->_language->get('settings'),
253
				[
254 4
					'for' => 'settings'
255
				])
256 4
				->select($helperOption->getPermissionArray('settings'),
257
				[
258 4
					$group?->settings
259
				],
260
				[
261 4
					'id' => 'settings',
262
					'name' => 'settings'
263
				])
264 4
				->append('</li></ul>')
265
266
				/* customize */
267
268 4
				->radio(
269
				[
270 4
					'id' => self::class . '\Customize',
271
					'class' => 'rs-admin-fn-status-tab',
272
					'name' => self::class . '\Tab'
273
				])
274 4
				->label($this->_language->get('customize'),
275
				[
276 4
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
277
					'for' => self::class . '\Customize'
278
				])
279 4
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
280 4
				->label($this->_language->get('filter'),
281
				[
282 4
					'for' => 'filter'
283
				])
284 4
				->checkbox(!$group?->id || $group?->filter ?
285
				[
286 4
					'id' => 'filter',
287
					'class' => 'rs-admin-fn-status-switch',
288
					'name' => 'filter',
289
					'checked' => 'checked'
290
				] :
291
				[
292 4
					'id' => 'filter',
293
					'class' => 'rs-admin-fn-status-switch',
294
					'name' => 'filter'
295
				])
296 4
				->label(null,
297
				[
298 4
					'class' => 'rs-admin-label-switch',
299 4
					'for' => 'filter',
300 4
					'data-on' => $this->_language->get('enable'),
301 4
					'data-off' => $this->_language->get('disable')
302
				])
303 4
				->append('</li><li>')
304 4
				->label($this->_language->get('status'),
305
				[
306 4
					'for' => 'status'
307
				])
308 4
				->checkbox(!$group?->id || $group?->status ?
309
				[
310 4
					'id' => 'status',
311
					'class' => 'rs-admin-fn-status-switch',
312
					'name' => 'status',
313
					'checked' => 'checked'
314
				] :
315
				[
316 4
					'id' => 'status',
317
					'class' => 'rs-admin-fn-status-switch',
318
					'name' => 'status'
319
				])
320 4
				->label(null,
321
				[
322 4
					'class' => 'rs-admin-label-switch',
323 4
					'for' => 'status',
324 4
					'data-on' => $this->_language->get('enable'),
325 4
					'data-off' => $this->_language->get('disable')
326
				])
327 4
				->append('</li></ul>');
328
		}
329
		if ($group?->id)
330 6
		{
331
			$formElement
332 6
				->hidden(
333 6
				[
334
					'name' => 'id',
335 6
					'value' => $group?->id
336 6
				]);
337 6
		}
338 6
		$formElement
339
			->token()
340 4
			->append('<div class="rs-admin-wrapper-button">')
341
			->cancel();
342 1
		if ($group?->id)
343
		{
344 4
			if ($this->_registry->get('groupsDelete') && $group?->id > 1)
345
			{
346 4
				$formElement->delete();
347
			}
348
			if ($this->_registry->get('groupsEdit'))
349 2
			{
350
				$formElement->save();
351 1
			}
352
		}
353 6
		else if ($this->_registry->get('groupsNew'))
354
		{
355
			$formElement->create();
356
		}
357 6
		$formElement->append('</div>');
358 6
359 6
		/* collect output */
360
361
		$output .= $titleElement . $formElement;
362
		$output .= Module\Hook::trigger('adminGroupFormEnd');
363
		return $output;
364
	}
365
}
366