Completed
Push — master ( a52438...bf8826 )
by Henry
06:30
created

Option   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 435
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 58.56%

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 8
dl 0
loc 435
ccs 65
cts 111
cp 0.5856
rs 9.84
c 0
b 0
f 0
1
<?php
2
namespace Redaxscript\Admin\View\Helper;
3
4
use DateTimeZone;
5
use Redaxscript\Admin;
6
use Redaxscript\Filesystem;
7
use Redaxscript\Language;
8
use function function_exists;
9
use function mb_list_encodings;
10
use function resourcebundle_locales;
11
use function substr;
12
13
/**
14
 * helper class to create various options
15
 *
16
 * @since 3.0.0
17
 *
18
 * @package Redaxscript
19
 * @category View
20
 * @author Henry Ruhs
21
 */
22
23
class Option
24
{
25
	/**
26
	 * constructor of the class
27
	 *
28
	 * @since 3.2.0
29
	 *
30
	 * @param Language $_language instance of the language class
31
	 */
32
33
	public function __construct(protected Language $_language)
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PROTECTED, expecting T_VARIABLE
Loading history...
34
	{
35
	}
36
37
	/**
38
	 * get the robot array
39
	 *
40
	 * @since 3.0.0
41 12
	 *
42
	 * @return array
43 12
	 */
44 12
45
	public function getRobotArray() : array
46
	{
47
		return
48
		[
49
			$this->_language->get('select') => 'null',
50
			$this->_language->get('all') => 1,
51
			$this->_language->get('index') => 2,
52
			$this->_language->get('follow') => 3,
53
			$this->_language->get('index_no') => 4,
54 1
			$this->_language->get('follow_no') => 5,
55
			$this->_language->get('none') => 6
56
		];
57
	}
58 1
59 1
	/**
60 1
	 * get the charset array
61 1
	 *
62 1
	 * @since 4.4.0
63 1
	 *
64 1
	 * @return array
65
	 */
66
67
	public function getCharsetArray() : array
68
	{
69
		return mb_list_encodings();
70
	}
71
72
	/**
73
	 * get the locale array
74
	 *
75
	 * @since 4.4.0
76 1
	 *
77
	 * @return array
78 1
	 */
79
80
	public function getLocaleArray() : array
81
	{
82
		return function_exists('resourcebundle_locales') ? resourcebundle_locales(null) : [];
83
	}
84
85
	/**
86
	 * get the zone array
87
	 *
88
	 * @since 4.0.0
89 1
	 *
90
	 * @return array
91 1
	 */
92
93
	public function getZoneArray() : array
94
	{
95
		return DateTimeZone::listIdentifiers();
96
	}
97
98
	/**
99
	 * get the time array
100
	 *
101
	 * @since 3.0.0
102 1
	 *
103
	 * @return array
104 1
	 */
105
106
	public function getTimeArray() : array
107
	{
108
		return
109
		[
110
			'24h' => 'H:i',
111
			'12h' => 'h:i a'
112
		];
113
	}
114
115 1
	/**
116
	 * get the date array
117
	 *
118
	 * @since 3.0.0
119 1
	 *
120
	 * @return array
121
	 */
122
123
	public function getDateArray() : array
124
	{
125
		return
126
		[
127
			'DD.MM.YYYY' => 'd.m.Y',
128
			'MM.DD.YYYY' => 'm.d.Y',
129
			'YYYY.MM.DD' => 'Y.m.d'
130
		];
131
	}
132 1
133
	/**
134
	 * get the order array
135
	 *
136 1
	 * @since 3.0.0
137
	 *
138
	 * @return array
139
	 */
140
141
	public function getOrderArray() : array
142
	{
143
		return
144
		[
145
			$this->_language->get('ascending') => 'asc',
146
			$this->_language->get('descending') => 'desc'
147
		];
148
	}
149
150 1
	/**
151
	 * get the captcha array
152
	 *
153
	 * @since 3.0.0
154 1
	 *
155 1
	 * @return array
156
	 */
157
158
	public function getCaptchaArray() : array
159
	{
160
		return
161
		[
162
			$this->_language->get('random') => 1,
163
			$this->_language->get('addition') => 2,
164
			$this->_language->get('subtraction') => 3,
165
			$this->_language->get('disable') => 0
166
		];
167 1
	}
168
169
	/**
170
	 * get the permission array
171 1
	 *
172 1
	 * @since 3.0.0
173 1
	 *
174 1
	 * @param string|null $table name of the table
175
	 *
176
	 * @return array
177
	 */
178
179
	public function getPermissionArray(?string $table) : array
180
	{
181
		if ($table === 'modules')
182
		{
183
			return
184
			[
185
				$this->_language->get('install') => 1,
186
				$this->_language->get('edit') => 2,
187
				$this->_language->get('uninstall') => 3
188 1
			];
189
		}
190 1
		if ($table === 'settings')
191
		{
192
			return
193
			[
194 1
				$this->_language->get('none') => 1,
195 1
				$this->_language->get('edit') => 2,
196 1
			];
197
		}
198
		return
199 1
		[
200
			$this->_language->get('create') => 1,
201
			$this->_language->get('edit') => 2,
202
			$this->_language->get('delete') => 3
203 1
		];
204 1
	}
205
206
	/**
207
	 * get the language array
208
	 *
209 1
	 * @since 3.0.0
210 1
	 *
211 1
	 * @return array
212
	 */
213
214
	public function getLanguageArray() : array
215
	{
216
		$languageFilesystem = new Filesystem\Filesystem();
217
		$languageFilesystem->init('languages');
218
		$languageFilesystemArray = $languageFilesystem->getSortArray();
219
		$languageArray =
220
		[
221
			$this->_language->get('select') => 'null'
222
		];
223 1
224
		/* process filesystem */
225 1
226 1
		foreach ($languageFilesystemArray as $value)
227 1
		{
228
			$value = substr($value, 0, 2);
229
			$languageArray[$this->_language->get('_language')[$value]] = $value;
230 1
		}
231
		return $languageArray;
232
	}
233
234
	/**
235 1
	 * get the template array
236
	 *
237 1
	 * @since 3.0.0
238 1
	 *
239
	 * @return array
240 1
	 */
241
242
	public function getTemplateArray() : array
243
	{
244
		$templateFilesystem = new Filesystem\Filesystem();
245
		$templateFilesystem->init('templates', false,
246
		[
247
			'admin',
248
			'console',
249
			'install'
250
		]);
251 1
		$templateFilesystemArray = $templateFilesystem->getSortArray();
252
		$templateArray =
253 1
		[
254 1
			$this->_language->get('select') => 'null'
255
		];
256 1
257
		/* process filesystem */
258
259
		foreach ($templateFilesystemArray as $value)
260 1
		{
261
			$templateArray[$value] = $value;
262
		}
263 1
		return $templateArray;
264
	}
265
266
	/**
267
	 * get the category array
268 1
	 *
269
	 * @since 4.5.0
270 1
	 *
271
	 * @return array
272 1
	 */
273
274
	public function getCategoryArray() : array
275
	{
276
		$categoryModel = new Admin\Model\Category();
277
		$contents = $categoryModel->query()->orderByAsc('title')->findMany();
278
		return $this->_getContentArray($contents);
279
	}
280
281
	/**
282
	 * get the sibling for category array
283
	 *
284
	 * @since 4.5.0
285
	 *
286
	 * @param int|null $categoryId identifier of the category
287
	 *
288
	 * @return array
289
	 */
290
291
	public function getSiblingForCategoryArray(?int $categoryId) : array
292
	{
293
		$categoryModel = new Admin\Model\Category();
294
		$query = $categoryModel->query();
295
		if ($categoryId)
296
		{
297
			$query->whereNotEqual('id', $categoryId);
298
		}
299
		$contents = $query->orderByAsc('title')->findMany();
300
		return $this->_getContentArray($contents);
301
	}
302
303
	/**
304
	 * get the parent for category array
305
	 *
306
	 * @since 4.5.0
307
	 *
308
	 * @param int|null $categoryId identifier of the category
309
	 *
310
	 * @return array
311
	 */
312
313
	public function getParentForCategoryArray(?int $categoryId) : array
314
	{
315
		$categoryModel = new Admin\Model\Category();
316
		$query = $categoryModel->query()->whereNull('parent');
317
		if ($categoryId)
318
		{
319
			$query->whereNotEqual('id', $categoryId);
320
		}
321
		$contents = $query->orderByAsc('title')->findMany();
322
		return $this->_getContentArray($contents);
323
	}
324
325
	/**
326
	 * get the article array
327
	 *
328
	 * @since 4.5.0
329
	 *
330
	 * @return array
331
	 */
332
333
	public function getArticleArray() : array
334
	{
335
		$articleModel = new Admin\Model\Article();
336
		$contents = $articleModel->query()->orderByAsc('title')->findMany();
337
		return $this->_getContentArray($contents);
338
	}
339
340
	/**
341
	 * get the sibling for article array
342
	 *
343
	 * @since 4.5.0
344
	 *
345
	 * @param int|null $articleId identifier of the article
346
	 *
347
	 * @return array
348
	 */
349
350
	public function getSiblingForArticleArray(?int $articleId) : array
351
	{
352
		$articleModel = new Admin\Model\Article();
353
		$query = $articleModel->query();
354
		if ($articleId)
355
		{
356
			$query->whereNotEqual('id', $articleId);
357
		}
358
		$contents = $query->orderByAsc('title')->findMany();
359
		return $this->_getContentArray($contents);
360
	}
361
362
	/**
363
	 * get the sibling for extra array
364
	 *
365
	 * @since 4.5.0
366
	 *
367
	 * @param int|null $extraId identifier of the extra
368
	 *
369
	 * @return array
370
	 */
371
372
	public function getSiblingForExtraArray(?int $extraId) : array
373
	{
374
		$extraModel = new Admin\Model\Extra();
375
		$query = $extraModel->query();
376
		if ($extraId)
377
		{
378
			$query->whereNotEqual('id', $extraId);
379
		}
380
		$contents = $query->orderByAsc('title')->findMany();
381
		return $this->_getContentArray($contents);
382
	}
383
384
	/**
385
	 * get the article for comment array
386
	 *
387
	 * @since 4.5.0
388
	 *
389
	 * @return array
390
	 */
391
392
	public function getArticleForCommentArray() : array
393
	{
394
		$articleModel = new Admin\Model\Article();
395
		$contents = $articleModel->query()->where('comments', 1)->orderByAsc('title')->findMany();
396
		return $this->_getContentArray($contents);
397
	}
398
399
	/**
400
	 * get the content array
401
	 *
402
	 * @since 4.5.0
403
	 *
404
	 * @param object $contents
405
	 *
406
	 * @return array
407
	 */
408
409
	protected function _getContentArray(object $contents) : array
410
	{
411
		$contentArray =
412
		[
413
			$this->_language->get('select') => 'null'
414
		];
415
416
		/* process contents */
417
418
		foreach ($contents as $value)
419
		{
420
			$contentKey = $value->title . ' (' . $value->id . ')';
421
			$contentArray[$contentKey] = $value->id;
422
		}
423
		return $contentArray;
424
	}
425
426
	/**
427
	 * get the group array
428
	 *
429
	 * @since 4.0.0
430
	 *
431
	 * @return array
432
	 */
433
434
	public function getGroupArray() : array
435
	{
436
		$groupModel = new Admin\Model\Group();
437
		$groups = $groupModel->query()->orderByAsc('name')->findMany();
438
		$accessArray = [];
439
440
		/* process groups */
441
442
		foreach ($groups as $value)
443 1
		{
444
			$accessArray[$value->name] = $value->id;
445 1
		}
446 1
		return $accessArray;
447 1
	}
448
}
449