Completed
Push — master ( de9e2d...f59dfb )
by Henry
08:37
created

includes/Admin/View/Helper/Option.php (1 issue)

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\Helper;
3
4
use DateTimeZone;
5
use Redaxscript\Db;
6
use Redaxscript\Filesystem;
7
use Redaxscript\Language;
8
use function substr;
9
10
/**
11
 * helper class to create various options
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category View
17
 * @author Henry Ruhs
18
 */
19
20
class Option
21
{
22
	/**
23
	 * instance of the language class
24
	 *
25
	 * @var Language
26
	 */
27
28
	protected $_language;
29
30
	/**
31
	 * constructor of the class
32
	 *
33
	 * @since 3.2.0
34
	 *
35
	 * @param Language $language instance of the language class
36
	 */
37 13
38
	public function __construct(Language $language)
39 13
	{
40 13
		$this->_language = $language;
41
	}
42
43
	/**
44
	 * get the toggle array
45
	 *
46
	 * @since 3.0.0
47
	 *
48
	 * @return array
49
	 */
50 1
51
	public function getToggleArray() : array
52
	{
53
		return
54 1
		[
55 1
			$this->_language->get('enable') => 1,
56
			$this->_language->get('disable') => 0
57
		];
58
	}
59
60
	/**
61
	 * get the visible array
62
	 *
63
	 * @since 3.0.0
64
	 *
65
	 * @return array
66
	 */
67 1
68
	public function getVisibleArray() : array
69
	{
70
		return
71 1
		[
72 1
			$this->_language->get('publish') => 1,
73
			$this->_language->get('unpublish') => 0
74
		];
75
	}
76
77
	/**
78
	 * get the robot array
79
	 *
80
	 * @since 3.0.0
81
	 *
82
	 * @return array
83
	 */
84 1
85
	public function getRobotArray() : array
86
	{
87
		return
88 1
		[
89 1
			$this->_language->get('select') => 'null',
90 1
			$this->_language->get('all') => 1,
91 1
			$this->_language->get('index') => 2,
92 1
			$this->_language->get('follow') => 3,
93 1
			$this->_language->get('index_no') => 4,
94 1
			$this->_language->get('follow_no') => 5,
95
			$this->_language->get('none') => 6
96
		];
97
	}
98
99
	/**
100
	 * get the zone array
101
	 *
102
	 * @since 4.0.0
103
	 *
104
	 * @return array
105
	 */
106 1
107
	public function getZoneArray() : array
108 1
	{
109
		return DateTimeZone::listIdentifiers();
110
	}
111
112
	/**
113
	 * get the time array
114
	 *
115
	 * @since 3.0.0
116
	 *
117
	 * @return array
118
	 */
119 1
120
	public function getTimeArray() : array
121
	{
122
		return
123 1
		[
124
			'24h' => 'H:i',
125
			'12h' => 'h:i a'
126
		];
127
	}
128
129
	/**
130
	 * get the date array
131
	 *
132
	 * @since 3.0.0
133
	 *
134
	 * @return array
135
	 */
136 1
137
	public function getDateArray() : array
138
	{
139
		return
140 1
		[
141
			'DD.MM.YYYY' => 'd.m.Y',
142
			'MM.DD.YYYY' => 'm.d.Y',
143
			'YYYY.MM.DD' => 'Y.m.d'
144
		];
145
	}
146
147
	/**
148
	 * get the order array
149
	 *
150
	 * @since 3.0.0
151
	 *
152
	 * @return array
153
	 */
154 1
155
	public function getOrderArray() : array
156
	{
157
		return
158 1
		[
159 1
			$this->_language->get('ascending') => 'asc',
160
			$this->_language->get('descending') => 'desc'
161
		];
162
	}
163
164
	/**
165
	 * get the captcha array
166
	 *
167
	 * @since 3.0.0
168
	 *
169
	 * @return array
170
	 */
171 1
172
	public function getCaptchaArray() : array
173
	{
174
		return
175 1
		[
176 1
			$this->_language->get('random') => 1,
177 1
			$this->_language->get('addition') => 2,
178 1
			$this->_language->get('subtraction') => 3,
179
			$this->_language->get('disable') => 0
180
		];
181
	}
182
183
	/**
184
	 * get the permission array
185
	 *
186
	 * @since 3.0.0
187
	 *
188
	 * @param string $table name of the table
189
	 *
190
	 * @return array
191
	 */
192 1
193
	public function getPermissionArray(string $table = null) : array
194 1
	{
195
		if ($table === 'modules')
196
		{
197
			return
198 1
			[
199 1
				$this->_language->get('install') => 1,
200 1
				$this->_language->get('edit') => 2,
201
				$this->_language->get('uninstall') => 3
202
			];
203 1
		}
204
		if ($table === 'settings')
205
		{
206
			return
207 1
			[
208 1
				$this->_language->get('none') => 1,
209
				$this->_language->get('edit') => 2,
210
			];
211
		}
212
		return
213 1
		[
214 1
			$this->_language->get('create') => 1,
215 1
			$this->_language->get('edit') => 2,
216
			$this->_language->get('delete') => 3
217
		];
218
	}
219
220
	/**
221
	 * get the language array
222
	 *
223
	 * @since 3.0.0
224
	 *
225
	 * @return array
226
	 */
227 1
228
	public function getLanguageArray() : array
229 1
	{
230 1
		$languageFilesystem = new Filesystem\Filesystem();
231 1
		$languageFilesystem->init('languages');
232
		$languageFilesystemArray = $languageFilesystem->getSortArray();
233
		$languageArray =
234 1
		[
235
			$this->_language->get('select') => 'null'
236
		];
237
238
		/* process filesystem */
239 1
240
		foreach ($languageFilesystemArray as $value)
241 1
		{
242 1
			$value = substr($value, 0, 2);
243
			$languageArray[$this->_language->get($value, '_index')] = $value;
244 1
		}
245
		return $languageArray;
246
	}
247
248
	/**
249
	 * get the template array
250
	 *
251
	 * @since 3.0.0
252
	 *
253
	 * @return array
254
	 */
255 1
256
	public function getTemplateArray() : array
257 1
	{
258 1
		$templateFilesystem = new Filesystem\Filesystem();
259
		$templateFilesystem->init('templates', false,
260 1
		[
261
			'admin',
262
			'console',
263
			'install'
264 1
		]);
265
		$templateFilesystemArray = $templateFilesystem->getSortArray();
266
		$templateArray =
267 1
		[
268
			$this->_language->get('select') => 'null'
269
		];
270
271
		/* process filesystem */
272 1
273
		foreach ($templateFilesystemArray as $value)
274 1
		{
275
			$templateArray[$value] = $value;
276 1
		}
277
		return $templateArray;
278
	}
279
280
	/**
281
	 * get the content array
282
	 *
283
	 * @since 3.0.0
284
	 *
285
	 * @param string $table name of the table
286
	 * @param array $excludeArray array of the exclude
287
	 *
288
	 * @return array
289
	 */
290 1
291
	public function getContentArray(string $table = null, array $excludeArray = []) : array
292 1
	{
293 1
		$query = Db::forTablePrefix($table);
294
		if ($excludeArray)
0 ignored issues
show
Bug Best Practice introduced by
The expression $excludeArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
295 1
		{
296
			$query->whereNotIn('id', $excludeArray);
297 1
		}
298
		$contents = $query->orderByAsc('title')->findMany();
299
		$contentArray =
300 1
		[
301
			$this->_language->get('select') => 'null'
302
		];
303
304
		/* process contents */
305 1
306
		foreach ($contents as $value)
307 1
		{
308 1
			$contentKey = $value->title . ' (' . $value->id . ')';
309
			$contentArray[$contentKey] = $value->id;
310 1
		}
311
		return $contentArray;
312
	}
313
314
	/**
315
	 * get the access array
316
	 *
317
	 * @since 3.0.0
318
	 *
319
	 * @param string $table name of the table
320
	 *
321
	 * @return array
322
	 */
323 1
324
	public function getAccessArray(string $table = null) : array
325 1
	{
326 1
		$access = Db::forTablePrefix($table)->orderByAsc('name')->findMany();
327
		$accessArray = [];
328
329
		/* process access */
330 1
331
		foreach ($access as $value)
332 1
		{
333
			$accessArray[$value->name] = $value->id;
334 1
		}
335
		return $accessArray;
336
	}
337
}
338