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

includes/Admin/View/UserForm.php (12 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 user form
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category View
17
 * @author Henry Ruhs
18
 */
19
20
class UserForm extends ViewAbstract
21
{
22
	/**
23
	 * render the view
24
	 *
25
	 * @since 3.0.0
26
	 *
27
	 * @param int $userId identifier of the user
28
	 *
29
	 * @return string
30
	 */
31
32 4
	public function render(int $userId = null) : string
33
	{
34 4
		$output = Module\Hook::trigger('adminUserFormStart');
35 4
		$userModel = new Admin\Model\User();
36 4
		$user = $userModel->getById($userId);
37 4
		$helperOption = new Helper\Option($this->_language);
38
39
		/* html element */
40
41 4
		$titleElement = new Html\Element();
42
		$titleElement
43 4
			->init('h2',
44
			[
45 4
				'class' => 'rs-admin-title-content',
46
			])
47 4
			->text($user->name ? : $this->_language->get('user_new'));
48 4
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
49 4
		$formElement->init(
50
		[
51 4
			'form' =>
52
			[
53
				'class' => 'rs-admin-js-validate 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 4
					'href' => $this->_registry->get('usersEdit') && $this->_registry->get('usersDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/users' : $this->_registry->get('parameterRoute') . 'admin'
71
				],
72
				'delete' =>
73
				[
74 4
					'href' => $user->id ? $this->_registry->get('parameterRoute') . 'admin/delete/users/' . $user->id . '/' . $this->_registry->get('token') : null
75
				]
76
			]
77
		]);
78
79
		/* create the form */
80
81
		$formElement
82
83
			/* user */
84
85 4
			->radio(
86
			[
87 4
				'id' => self::class . '\User',
88
				'class' => 'rs-admin-fn-status-tab',
89
				'name' => self::class . '\Tab',
90
				'checked' => 'checked'
91
			])
92 4
			->label($this->_language->get('user'),
0 ignored issues
show
It seems like $this->_language->get('user') 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 4
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
95
				'for' => self::class . '\User'
96
			])
97 4
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
98 4
			->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 4
				'for' => 'name'
101
			])
102 4
			->text(
103
			[
104 4
				'autofocus' => 'autofocus',
105 4
				'id' => 'name',
106 4
				'name' => 'name',
107 4
				'required' => 'required',
108 4
				'value' => $user->name
109
			])
110 4
			->append('</li>');
111 4
		if (!$user->id)
112
		{
113
			$formElement
114 2
				->append('<li>')
115 2
				->label($this->_language->get('user'),
0 ignored issues
show
It seems like $this->_language->get('user') 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...
116
				[
117 2
					'for' => 'user'
118
				])
119 2
				->text(
120
				[
121 2
					'id' => 'user',
122 2
					'name' => 'user',
123 2
					'pattern' => '[a-zA-Z0-9]{1,30}',
124 2
					'required' => 'required',
125 2
					'value' => $user->user
126
				])
127 2
				->append('</li>');
128
		}
129
		$formElement
130 4
			->append('<li>')
131 4
			->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...
132
			[
133 4
				'for' => 'description'
134
			])
135 4
			->textarea(
136
			[
137 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
138 4
				'id' => 'description',
139 4
				'name' => 'description',
140 4
				'rows' => 1,
141 4
				'value' => $user->description
142
			])
143 4
			->append('</li><li>')
144 4
			->label($this->_language->get('password'),
0 ignored issues
show
It seems like $this->_language->get('password') 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...
145
			[
146 4
				'for' => 'password'
147
			])
148 4
			->password(
149
			[
150 4
				'id' => 'password',
151
				'pattern' => '[a-zA-Z0-9]{1,30}',
152
				'name' => 'password',
153
				'autocomplete' => 'new-password'
154
			])
155 4
			->append('</li><li>')
156 4
			->label($this->_language->get('password_confirm'),
0 ignored issues
show
It seems like $this->_language->get('password_confirm') 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...
157
			[
158 4
				'for' => 'password_confirm'
159
			])
160 4
			->password(
161
			[
162 4
				'id' => 'password_confirm',
163
				'pattern' => '[a-zA-Z0-9]{1,30}',
164
				'name' => 'password_confirm',
165
				'autocomplete' => 'new-password'
166
			])
167 4
			->append('</li><li>')
168 4
			->label($this->_language->get('email'),
0 ignored issues
show
It seems like $this->_language->get('email') 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...
169
			[
170 4
				'for' => 'email'
171
			])
172 4
			->email(
173
			[
174 4
				'id' => 'email',
175 4
				'name' => 'email',
176 4
				'required' => 'required',
177 4
				'value' => $user->email
178
			])
179 4
			->append('</li></ul>')
180
181
			/* general */
182
183 4
			->radio(
184
			[
185 4
				'id' => self::class . '\General',
186
				'class' => 'rs-admin-fn-status-tab',
187
				'name' => self::class . '\Tab'
188
			])
189 4
			->label($this->_language->get('general'),
0 ignored issues
show
It seems like $this->_language->get('general') 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...
190
			[
191 4
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
192
				'for' => self::class . '\General'
193
			])
194 4
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
195 4
			->label($this->_language->get('language'),
0 ignored issues
show
It seems like $this->_language->get('language') 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...
196
			[
197 4
				'for' => 'language'
198
			])
199 4
			->select($helperOption->getLanguageArray(),
200
			[
201 4
				$user->language
202
			],
203
			[
204 4
				'id' => 'language',
205
				'name' => 'language'
206
			])
207 4
			->append('</li></ul>');
208 4
		if (!$user->id || $user->id > 1)
209
		{
210
			$formElement
211
212
				/* customize */
213
214 3
				->radio(
215
				[
216 3
					'id' => self::class . '\Customize',
217
					'class' => 'rs-admin-fn-status-tab',
218
					'name' => self::class . '\Tab'
219
				])
220 3
				->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...
221
				[
222 3
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
223
					'for' => self::class . '\Customize'
224
				])
225 3
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
226 3
				->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...
227
				[
228 3
					'for' => 'status'
229
				])
230 3
				->select($helperOption->getToggleArray(),
231
				[
232 3
					$user->id ? $user->status : 1
233
				],
234
				[
235 3
					'id' => 'status',
236
					'name' => 'status'
237
				])
238 3
				->append('</li>');
239 3
			if ($this->_registry->get('groupsEdit'))
240
			{
241
				$formElement
242 1
					->append('<li>')
243 1
					->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...
244
					[
245 1
						'for' => 'groups'
246
					])
247 1
					->select($helperOption->getGroupArray(),
248 1
					(array)json_decode($user->groups),
249
					[
250 1
						'id' => 'groups',
251 1
						'name' => 'groups[]',
252 1
						'multiple' => 'multiple',
253 1
						'size' => count($helperOption->getGroupArray())
254
					])
255 1
					->append('</li>');
256
			}
257 3
			$formElement->append('</ul>');
258
		}
259
		$formElement
260 4
			->hidden(
261
			[
262 4
				'name' => 'id',
263 4
				'value' => $user->id
264
			])
265 4
			->token()
266 4
			->append('<div class="rs-admin-wrapper-button">')
267 4
			->cancel();
268 4
		if ($user->id)
269
		{
270 2
			if (($this->_registry->get('usersDelete') || $this->_registry->get('myId') === $user->id) && $user->id > 1)
271
			{
272 1
				$formElement->delete();
273
			}
274 2
			if ($this->_registry->get('usersEdit') || $this->_registry->get('myId') === $user->id)
275
			{
276 2
				$formElement->save();
277
			}
278
		}
279 2
		else if ($this->_registry->get('usersNew'))
280
		{
281 1
			$formElement->create();
282
		}
283 4
		$formElement->append('</div>');
284
285
		/* collect output */
286
287 4
		$output .= $titleElement . $formElement;
288 4
		$output .= Module\Hook::trigger('adminUserFormEnd');
289 4
		return $output;
290
	}
291
}
292