Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

includes/Admin/View/GroupForm.php (16 issues)

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 function count;
8
use function json_decode;
9
10
/**
11
 * children class to create the group form
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category View
17
 * @author Henry Ruhs
18
 */
19
20
class GroupForm extends ViewAbstract
21
{
22
	/**
23
	 * render the view
24
	 *
25
	 * @since 3.0.0
26
	 *
27
	 * @param int $groupId identifier of the group
28
	 *
29
	 * @return string
30
	 */
31
32 6
	public function render(int $groupId = null) : string
33
	{
34 6
		$output = Module\Hook::trigger('adminGroupFormStart');
35 6
		$groupModel = new Admin\Model\Group();
36 6
		$group = $groupModel->getById($groupId);
37 6
		$helperOption = new Helper\Option($this->_language);
38
39
		/* html element */
40
41 6
		$titleElement = new Html\Element();
42
		$titleElement
43 6
			->init('h2',
44
			[
45 6
				'class' => 'rs-admin-title-content',
46
			])
47 6
			->text($group->name ? : $this->_language->get('group_new'));
48 6
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
49 6
		$formElement->init(
50
		[
51 6
			'form' =>
52
			[
53
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
54
			],
55
			'button' =>
56
			[
57
				'create' =>
58
				[
59
					'name' => self::class
60
				],
61
				'save' =>
62
				[
63
					'name' => self::class
64
				]
65
			],
66
			'link' =>
67
			[
68
				'cancel' =>
69
				[
70 6
					'href' => $this->_registry->get('groupsEdit') && $this->_registry->get('groupsDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/groups' : $this->_registry->get('parameterRoute') . 'admin'
71
				],
72
				'delete' =>
73
				[
74 6
					'href' => $group->id ? $this->_registry->get('parameterRoute') . 'admin/delete/groups/' . $group->id . '/' . $this->_registry->get('token') : null
75
				]
76
			]
77
		]);
78
79
		/* create the form */
80
81
		$formElement
82
83
			/* group */
84
85 6
			->radio(
86
			[
87 6
				'id' => self::class . '\Group',
88
				'class' => 'rs-admin-fn-status-tab',
89
				'name' => self::class . '\Tab',
90
				'checked' => 'checked'
91
			])
92 6
			->label($this->_language->get('group'),
0 ignored issues
show
It seems like $this->_language->get('group') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
93
			[
94 6
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
95
				'for' => self::class . '\Group'
96
			])
97 6
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
98 6
			->label($this->_language->get('name'),
0 ignored issues
show
It seems like $this->_language->get('name') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
99
			[
100 6
				'for' => 'name'
101
			])
102 6
			->text(
103
			[
104 6
				'autofocus' => 'autofocus',
105 6
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
106 6
				'id' => 'name',
107 6
				'name' => 'name',
108 6
				'required' => 'required',
109 6
				'value' => $group->name
110
			])
111 6
			->append('</li>');
112 6
		if (!$group->id)
113
		{
114
			$formElement
115 2
				->append('<li>')
116 2
				->label($this->_language->get('alias'),
0 ignored issues
show
It seems like $this->_language->get('alias') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
117
				[
118 2
					'for' => 'alias'
119
				])
120 2
				->text(
121
				[
122 2
					'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
123 2
					'id' => 'alias',
124 2
					'name' => 'alias',
125 2
					'pattern' => '[a-zA-Z0-9-]+',
126 2
					'required' => 'required',
127 2
					'value' => $group->alias
128
				])
129 2
				->append('</li>');
130
		}
131
		$formElement
132 6
			->append('<li>')
133 6
			->label($this->_language->get('description'),
0 ignored issues
show
It seems like $this->_language->get('description') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
134
			[
135 6
				'for' => 'description'
136
			])
137 6
			->textarea(
138
			[
139 6
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
140 6
				'id' => 'description',
141 6
				'name' => 'description',
142 6
				'rows' => 1,
143 6
				'value' => $group->description
144
			])
145 6
			->append('</li></ul>');
146 6
		if (!$group->id || $group->id > 1)
147
		{
148
			$formElement
149
150
				/* access */
151
152 4
				->radio(
153
				[
154 4
					'id' => self::class . '\Access',
155
					'class' => 'rs-admin-fn-status-tab',
156
					'name' => self::class . '\Tab'
157
				])
158 4
				->label($this->_language->get('access'),
0 ignored issues
show
It seems like $this->_language->get('access') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
159
				[
160 4
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
161
					'for' => self::class . '\Access'
162
				])
163 4
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
164 4
				->label($this->_language->get('categories'),
0 ignored issues
show
It seems like $this->_language->get('categories') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
165
				[
166 4
					'for' => 'categories'
167
				])
168 4
				->select($helperOption->getPermissionArray(),
169 4
				(array)json_decode($group->categories),
170
				[
171 4
					'id' => 'categories',
172 4
					'name' => 'categories[]',
173 4
					'multiple' => 'multiple',
174 4
					'size' => count($helperOption->getPermissionArray())
175
				])
176 4
				->append('</li><li>')
177 4
				->label($this->_language->get('articles'),
0 ignored issues
show
It seems like $this->_language->get('articles') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
178
				[
179 4
					'for' => 'articles'
180
				])
181 4
				->select($helperOption->getPermissionArray(),
182 4
				(array)json_decode($group->articles),
183
				[
184 4
					'id' => 'articles',
185 4
					'name' => 'articles[]',
186 4
					'multiple' => 'multiple',
187 4
					'size' => count($helperOption->getPermissionArray())
188
				])
189 4
				->append('</li><li>')
190 4
				->label($this->_language->get('extras'),
0 ignored issues
show
It seems like $this->_language->get('extras') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
191
				[
192 4
					'for' => 'extras'
193
				])
194 4
				->select($helperOption->getPermissionArray(),
195 4
				(array)json_decode($group->extras),
196
				[
197 4
					'id' => 'extras',
198 4
					'name' => 'extras[]',
199 4
					'multiple' => 'multiple',
200 4
					'size' => count($helperOption->getPermissionArray())
201
				])
202 4
				->append('</li><li>')
203 4
				->label($this->_language->get('comments'),
0 ignored issues
show
It seems like $this->_language->get('comments') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
204
				[
205 4
					'for' => 'comments'
206
				])
207 4
				->select($helperOption->getPermissionArray(),
208 4
				(array)json_decode($group->comments),
209
				[
210 4
					'id' => 'comments',
211 4
					'name' => 'comments[]',
212 4
					'multiple' => 'multiple',
213 4
					'size' => count($helperOption->getPermissionArray())
214
				])
215 4
				->append('</li><li>')
216 4
				->label($this->_language->get('groups'),
0 ignored issues
show
It seems like $this->_language->get('groups') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
217
				[
218 4
					'for' => 'groups'
219
				])
220 4
				->select($helperOption->getPermissionArray(),
221 4
				(array)json_decode($group->groups),
222
				[
223 4
					'id' => 'groups',
224 4
					'name' => 'groups[]',
225 4
					'multiple' => 'multiple',
226 4
					'size' => count($helperOption->getPermissionArray())
227
				])
228 4
				->append('</li><li>')
229 4
				->label($this->_language->get('users'),
0 ignored issues
show
It seems like $this->_language->get('users') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
230
				[
231 4
					'for' => 'users'
232
				])
233 4
				->select($helperOption->getPermissionArray(),
234 4
				(array)json_decode($group->users),
235
				[
236 4
					'id' => 'users',
237 4
					'name' => 'users[]',
238 4
					'multiple' => 'multiple',
239 4
					'size' => count($helperOption->getPermissionArray())
240
				])
241 4
				->append('</li><li>')
242 4
				->label($this->_language->get('modules'),
0 ignored issues
show
It seems like $this->_language->get('modules') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
243
				[
244 4
					'for' => 'modules'
245
				])
246 4
				->select($helperOption->getPermissionArray('modules'),
247 4
				(array)json_decode($group->modules),
248
				[
249 4
					'id' => 'modules',
250 4
					'name' => 'modules[]',
251 4
					'multiple' => 'multiple',
252 4
					'size' => count($helperOption->getPermissionArray('modules'))
253
				])
254 4
				->append('</li><li>')
255 4
				->label($this->_language->get('settings'),
0 ignored issues
show
It seems like $this->_language->get('settings') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
256
				[
257 4
					'for' => 'settings'
258
				])
259 4
				->select($helperOption->getPermissionArray('settings'),
260
				[
261 4
					$group->settings
262
				],
263
				[
264 4
					'id' => 'settings',
265
					'name' => 'settings'
266
				])
267 4
				->append('</li></ul>')
268
269
				/* customize */
270
271 4
				->radio(
272
				[
273 4
					'id' => self::class . '\Customize',
274
					'class' => 'rs-admin-fn-status-tab',
275
					'name' => self::class . '\Tab'
276
				])
277 4
				->label($this->_language->get('customize'),
0 ignored issues
show
It seems like $this->_language->get('customize') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
278
				[
279 4
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
280
					'for' => self::class . '\Customize'
281
				])
282 4
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
283 4
				->label($this->_language->get('filter'),
0 ignored issues
show
It seems like $this->_language->get('filter') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
284
				[
285 4
					'for' => 'filter'
286
				])
287 4
				->select($helperOption->getToggleArray(),
288
				[
289 4
					$group->id ? $group->filter : 1
290
				],
291
				[
292 4
					'id' => 'filter',
293
					'name' => 'filter'
294
				])
295 4
				->append('</li><li>')
296 4
				->label($this->_language->get('status'),
0 ignored issues
show
It seems like $this->_language->get('status') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
297
				[
298 4
					'for' => 'status'
299
				])
300 4
				->select($helperOption->getToggleArray(),
301
				[
302 4
					$group->id ? $group->status : 1
303
				],
304
				[
305 4
					'id' => 'status',
306
					'name' => 'status'
307
				])
308 4
				->append('</li></ul>');
309
		}
310
		$formElement
311 6
			->hidden(
312
			[
313 6
				'name' => 'id',
314 6
				'value' => $group->id
315
			])
316 6
			->token()
317 6
			->append('<div class="rs-admin-wrapper-button">')
318 6
			->cancel();
319 6
		if ($group->id)
320
		{
321 4
			if ($this->_registry->get('groupsDelete') && $group->id > 1)
322
			{
323 1
				$formElement->delete();
324
			}
325 4
			if ($this->_registry->get('groupsEdit'))
326
			{
327 4
				$formElement->save();
328
			}
329
		}
330 2
		else if ($this->_registry->get('groupsNew'))
331
		{
332 1
			$formElement->create();
333
		}
334 6
		$formElement->append('</div>');
335
336
		/* collect output */
337
338 6
		$output .= $titleElement . $formElement;
339 6
		$output .= Module\Hook::trigger('adminGroupFormEnd');
340 6
		return $output;
341
	}
342
}
343