Completed
Push — master ( c3c208...858dca )
by Henry
08:18
created

CommentForm   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 254
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 11
dl 0
loc 254
c 0
b 0
f 0
ccs 111
cts 111
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 0 241 13
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);
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->author ? : $this->_language->get('comment_new'));
52 4
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
53 4
		$formElement->init(
54
		[
55 4
			'form' =>
56
			[
57
				'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'),
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('comment') 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...
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'),
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('url') 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...
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'),
0 ignored issues
show
Bug introduced by
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...
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'),
0 ignored issues
show
Bug introduced by
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...
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'),
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('article') 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...
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'),
0 ignored issues
show
Bug introduced by
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...
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
			->checkbox(!$comment->id || $comment->status ?
183
			[
184 4
				'id' => 'status',
185
				'class' => 'rs-admin-fn-status-switch',
186
				'name' => 'status',
187
				'checked' => 'checked'
188
			] :
189
			[
190 4
				'id' => 'status',
191
				'class' => 'rs-admin-fn-status-switch',
192
				'name' => 'status'
193
			])
194 4
			->label(null,
195
			[
196 4
				'class' => 'rs-admin-label-switch',
197 4
				'for' => 'status',
198 4
				'data-on' => $this->_language->get('publish'),
199 4
				'data-off' => $this->_language->get('unpublish')
200
			])
201 4
			->append('</li><li>')
202 4
			->label($this->_language->get('rank'),
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('rank') 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...
203
			[
204 4
				'for' => 'rank'
205
			])
206 4
			->number(
207
			[
208 4
				'id' => 'rank',
209 4
				'name' => 'rank',
210 4
				'value' => $comment->id ? $comment->rank : $commentModel->query()->max('rank') + 1
211
			])
212 4
			->append('</li>');
213 4
		if ($this->_registry->get('groupsEdit'))
214
		{
215
			$formElement
216 4
				->append('<li>')
217 4
				->label($this->_language->get('access'),
0 ignored issues
show
Bug introduced by
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...
218
				[
219 4
					'for' => 'access'
220
				])
221 4
				->select($helperOption->getGroupArray(),
222 4
				(array)json_decode($comment->access),
223
				[
224 4
					'id' => 'access',
225 4
					'name' => 'access[]',
226 4
					'multiple' => 'multiple',
227 4
					'size' => count($helperOption->getGroupArray())
228
				])
229 4
				->append('</li>');
230
		}
231
		$formElement
232 4
			->append('<li>')
233 4
			->label($this->_language->get('date'),
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('date') 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...
234
			[
235 4
				'for' => 'date'
236
			])
237 4
			->datetime(
238
			[
239 4
				'id' => 'date',
240 4
				'name' => 'date',
241 4
				'value' => $dater->formatField()
242
			])
243 4
			->append('</li></ul>')
244 4
			->hidden(
245
			[
246 4
				'name' => 'id',
247 4
				'value' => $comment->id
248
			])
249 4
			->token()
250 4
			->append('<div class="rs-admin-wrapper-button">')
251 4
			->cancel();
252 4
		if ($comment->id)
253
		{
254 2
			if ($this->_registry->get('commentsDelete'))
255
			{
256 1
				$formElement->delete();
257
			}
258 2
			if ($this->_registry->get('commentsEdit'))
259
			{
260 2
				$formElement->save();
261
			}
262
		}
263 2
		else if ($this->_registry->get('commentsNew'))
264
		{
265 1
			$formElement->create();
266
		}
267 4
		$formElement->append('</div>');
268
269
		/* collect output */
270
271 4
		$output .= $titleElement . $formElement;
272 4
		$output .= Module\Hook::trigger('adminCommentFormEnd');
273 4
		return $output;
274
	}
275
}
276