Passed
Push — master ( ba8ea1...a9f80d )
by Aimeos
07:23
created

Standard::getIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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