Passed
Push — master ( e7ec1e...e85a3f )
by Aimeos
05:27
created

Standard::getRating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Locale
8
 */
9
10
11
namespace Aimeos\MShop\Locale\Item\Site;
12
13
14
/**
15
 * Default implementation of a Site item.
16
 *
17
 * @package MShop
18
 * @subpackage Locale
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Item\Base
22
	implements \Aimeos\MShop\Locale\Item\Site\Iface
23
{
24
	use \Aimeos\MShop\Common\Item\Config\Traits;
25
26
27
	/**
28
	 * Returns the ID of the site.
29
	 *
30
	 * @return string Unique ID of the site
31
	 */
32
	public function getSiteId() : string
33
	{
34
		return $this->get( 'locale.site.siteid', '' );
35
	}
36
37
38
	/**
39
	 * Sets the ID of the site.
40
	 *
41
	 * @param string $value Unique ID of the site
42
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
43
	 */
44
	public function setSiteId( string $value ) : \Aimeos\MShop\Locale\Item\Site\Iface
45
	{
46
		return $this->set( 'locale.site.siteid', $value );
47
	}
48
49
50
	/**
51
	 * Returns the code of the site.
52
	 *
53
	 * @return string Returns the code of the item
54
	 */
55
	public function getCode() : string
56
	{
57
		return $this->get( 'locale.site.code', '' );
58
	}
59
60
61
	/**
62
	 * Sets the code of the site.
63
	 *
64
	 * @param string $code The code to set
65
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
66
	 */
67
	public function setCode( string $code ) : \Aimeos\MShop\Common\Item\Tree\Iface
68
	{
69
		return $this->set( 'locale.site.code', $this->checkCode( $code, 255 ) );
70
	}
71
72
73
	/**
74
	 * Returns the config property of the site.
75
	 *
76
	 * @return array Returns the config of the Site
77
	 */
78
	public function getConfig() : array
79
	{
80
		return $this->get( 'locale.site.config', [] );
81
	}
82
83
84
	/**
85
	 * Sets the config property of the site.
86
	 *
87
	 * @param array $options Options to be set for the Site
88
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
89
	 */
90
	public function setConfig( array $options ) : \Aimeos\MShop\Common\Item\Iface
91
	{
92
		return $this->set( 'locale.site.config', $options );
93
	}
94
95
96
	/**
97
	 * Returns the label property of the site.
98
	 *
99
	 * @return string Returns the label of the Site
100
	 */
101
	public function getLabel() : string
102
	{
103
		return $this->get( 'locale.site.label', '' );
104
	}
105
106
107
	/**
108
	 * Sets the label property of the site.
109
	 *
110
	 * @param string $label The label of the Site
111
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
112
	 */
113
	public function setLabel( string $label ) : \Aimeos\MShop\Common\Item\Tree\Iface
114
	{
115
		return $this->set( 'locale.site.label', $label );
116
	}
117
118
119
	/**
120
	 * Returns the level of the item in the tree
121
	 *
122
	 * @return int Level of the item starting with "0" for the root node
123
	 */
124
	public function getLevel() : int
125
	{
126
		return 0;
127
	}
128
129
130
	/**
131
	 * Returns the logo path of the site.
132
	 *
133
	 * @param bool $large Return the largest image instead of the smallest
134
	 * @return string Returns the logo of the site
135
	 */
136
	public function getLogo( bool $large = false ) : string
137
	{
138
		if( ( $list = (array) $this->get( 'locale.site.logo', [] ) ) !== [] ) {
139
			return (string) ( $large ? end( $list ) : current( $list ) );
140
		}
141
142
		return '';
143
	}
144
145
146
	/**
147
	 * Returns the logo path of the site.
148
	 *
149
	 * @return string Returns the logo of the site
150
	 */
151
	public function getLogos() : array
152
	{
153
		return (array) $this->get( 'locale.site.logo', [] );
154
	}
155
156
157
	/**
158
	 * Returns the icon path of the site.
159
	 *
160
	 * @return string Returns the icon of the site
161
	 */
162
	public function getIcon() : string
163
	{
164
		return $this->get( 'locale.site.icon', '' );
165
	}
166
167
168
	/**
169
	 * Sets the icon path of the site.
170
	 *
171
	 * @param string $value The icon of the site
172
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
173
	 */
174
	public function setIcon( string $value ) : \Aimeos\MShop\Common\Item\Tree\Iface
175
	{
176
		return $this->set( 'locale.site.icon', $value );
177
	}
178
179
180
	/**
181
	 * Sets the logo path of the site.
182
	 *
183
	 * @param string $value The logo of the site
184
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
185
	 */
186
	public function setLogo( string $value ) : \Aimeos\MShop\Common\Item\Tree\Iface
187
	{
188
		return $this->set( 'locale.site.logo', [1 => $value] );
189
	}
190
191
192
	/**
193
	 * Sets the logo path of the site.
194
	 *
195
	 * @param array $value List of logo URLs with widths of the media file in pixels as keys
196
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
197
	 */
198
	public function setLogos( array $value ) : \Aimeos\MShop\Common\Item\Tree\Iface
199
	{
200
		return $this->set( 'locale.site.logo', $value );
201
	}
202
203
204
	/**
205
	 * Returns the ID of the parent site
206
	 *
207
	 * @return string Unique ID of the parent site
208
	 */
209
	public function getParentId() : string
210
	{
211
		return '0';
212
	}
213
214
215
	/**
216
	 * Returns the rating of the item
217
	 *
218
	 * @return string Decimal value of the item rating
219
	 */
220
	public function getRating() : string
221
	{
222
		return (string) $this->get( 'locale.site.rating', 0 );
223
	}
224
225
226
	/**
227
	 * Returns the total number of ratings for the item
228
	 *
229
	 * @return int Total number of ratings for the item
230
	 */
231
	public function getRatings() : int
232
	{
233
		return (int) $this->get( 'locale.site.ratings', 0 );
234
	}
235
236
237
	/**
238
	 * Returns the ID of the referenced customer/supplier related to the site.
239
	 *
240
	 * @return string Returns the referenced customer/supplier ID related to the site
241
	 */
242
	public function getRefId() : string
243
	{
244
		return $this->get( 'locale.site.refid', '' );
245
	}
246
247
248
	/**
249
	 * Sets the ID of the referenced customer/supplier related to the site.
250
	 *
251
	 * @param string $value The referenced customer/supplier ID related to the site
252
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
253
	 */
254
	public function setRefId( string $value ) : \Aimeos\MShop\Common\Item\Tree\Iface
255
	{
256
		return $this->set( 'locale.site.refid', $value );
257
	}
258
259
260
	/**
261
	 * Returns the status property of the Site.
262
	 *
263
	 * @return int Returns the status of the Site
264
	 */
265
	public function getStatus() : int
266
	{
267
		return $this->get( 'locale.site.status', 1 );
268
	}
269
270
271
	/**
272
	 * Sets status property.
273
	 *
274
	 * @param int $status The status of the Site
275
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
276
	 */
277
	public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface
278
	{
279
		return $this->set( 'locale.site.status', $status );
280
	}
281
282
283
	/**
284
	 * Returns the theme name for the site.
285
	 *
286
	 * @return string|null Returns the theme name for the site or emtpy for default theme
287
	 */
288
	public function getTheme() : ?string
289
	{
290
		return $this->get( 'locale.site.theme' );
291
	}
292
293
294
	/**
295
	 * Sets the theme name for the site.
296
	 *
297
	 * @param string $value The theme name for the site
298
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
299
	 */
300
	public function setTheme( string $value ) : \Aimeos\MShop\Common\Item\Tree\Iface
301
	{
302
		return $this->set( 'locale.site.theme', $value );
303
	}
304
305
306
	/**
307
	 * Tests if the item is available based on status, time, language and currency
308
	 *
309
	 * @return bool True if available, false if not
310
	 */
311
	public function isAvailable() : bool
312
	{
313
		return parent::isAvailable() && $this->getStatus() > 0;
314
	}
315
316
317
	/*
318
	 * Sets the item values from the given array and removes that entries from the list
319
	 *
320
	 * @param array &$list Associative list of item keys and their values
321
	 * @param bool True to set private properties too, false for public only
322
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Site item for chaining method calls
323
	 */
324
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
325
	{
326
		$item = parent::fromArray( $list, $private );
327
328
		foreach( $list as $key => $value )
329
		{
330
			switch( $key )
331
			{
332
				case 'locale.site.code': $item->setCode( $value ); break;
333
				case 'locale.site.label': $item->setLabel( $value ); break;
334
				case 'locale.site.status': $item->setStatus( (int) $value ); break;
335
				case 'locale.site.config': $item->setConfig( (array) $value ); break;
336
				case 'locale.site.refid': $item->setRefId( $value ); break;
337
				case 'locale.site.logo': $item->setLogos( (array) $value ); break;
338
				case 'locale.site.theme': $item->setTheme( $value ); break;
339
				case 'locale.site.icon': $item->setIcon( $value ); break;
340
				default: continue 2;
341
			}
342
343
			unset( $list[$key] );
344
		}
345
346
		return $item;
347
	}
348
349
350
	/**
351
	 * Returns the item values as array.
352
	 *
353
	 * @param bool True to return private properties, false for public only
354
	 * @return array Associative list of item properties and their values
355
	 */
356
	public function toArray( bool $private = false ) : array
357
	{
358
		$list = parent::toArray( $private );
359
360
		$list['locale.site.code'] = $this->getCode();
361
		$list['locale.site.icon'] = $this->getIcon();
362
		$list['locale.site.logo'] = $this->getLogos();
363
		$list['locale.site.theme'] = $this->getTheme();
364
		$list['locale.site.label'] = $this->getLabel();
365
		$list['locale.site.status'] = $this->getStatus();
366
		$list['locale.site.refid'] = $this->getRefId();
367
		$list['locale.site.hasChildren'] = $this->hasChildren();
368
		$list['locale.site.ratings'] = $this->getRatings();
369
		$list['locale.site.rating'] = $this->getRating();
370
371
		if( $private === true )
372
		{
373
			$list['locale.site.level'] = $this->getLevel();
374
			$list['locale.site.parentid'] = $this->getParentId();
375
			$list['locale.site.config'] = $this->getConfig();
376
		}
377
378
		return $list;
379
	}
380
381
382
	/**
383
	 * Adds a child node to this node.
384
	 *
385
	 * @param \Aimeos\MShop\Common\Item\Tree\Iface $item Child node to add
386
	 * @return \Aimeos\MShop\Common\Item\Tree\Iface Tree item for chaining method calls
387
	 */
388
	public function addChild( \Aimeos\MShop\Common\Item\Tree\Iface $item ) : \Aimeos\MShop\Common\Item\Tree\Iface
389
	{
390
		return $this;
391
	}
392
393
394
	/**
395
	 * Removes a child node from this node.
396
	 *
397
	 * @param \Aimeos\MShop\Common\Item\Tree\Iface $item Child node to remove
398
	 * @return \Aimeos\MShop\Common\Item\Tree\Iface Tree item for chaining method calls
399
	 */
400
	public function deleteChild( \Aimeos\MShop\Common\Item\Tree\Iface $item ) : \Aimeos\MShop\Common\Item\Tree\Iface
401
	{
402
		return $this;
403
	}
404
405
406
	/**
407
	 * Returns a child of this node identified by its index.
408
	 *
409
	 * @param int $index Index of child node
410
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Selected node
411
	 */
412
	public function getChild( int $index ) : \Aimeos\MShop\Common\Item\Tree\Iface
413
	{
414
		throw new \Aimeos\MShop\Locale\Exception( sprintf( 'Child node with index "%1$d" not available', $index ) );
415
	}
416
417
418
	/**
419
	 * Returns all children of this node.
420
	 *
421
	 * @return \Aimeos\Map Numerically indexed list of items implementing \Aimeos\MShop\Locale\Item\Site\Iface
422
	 */
423
	public function getChildren() : \Aimeos\Map
424
	{
425
		return map();
426
	}
427
428
429
	/**
430
	 * Returns the deleted children.
431
	 *
432
	 * @return \Aimeos\Map List of removed children implementing \Aimeos\MShop\Locale\Item\Site\Iface
433
	 */
434
	public function getChildrenDeleted() : \Aimeos\Map
435
	{
436
		return map();
437
	}
438
439
440
	/**
441
	 * Tests if a node has children.
442
	 *
443
	 * @return bool True if node has children, false if not
444
	 */
445
	public function hasChildren() : bool
446
	{
447
		return false;
448
	}
449
450
451
	/**
452
	 * Returns the node and its children as list
453
	 *
454
	 * @return \Aimeos\Map List of IDs as keys and items implementing \Aimeos\MShop\Locale\Item\Site\Iface
455
	 */
456
	public function toList() : \Aimeos\Map
457
	{
458
		return map( [$this->getId() => $this] );
459
	}
460
}
461