Passed
Push — master ( 2e9af5...8d773b )
by Aimeos
05:58
created

Standard::__construct()   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 1
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 Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Locale
8
 */
9
10
11
namespace Aimeos\MShop\Locale\Item\Language;
12
13
14
/**
15
 * Default implementation of a Language 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\Language\Iface
23
{
24
	/**
25
	 * Sets the id of the language.
26
	 *
27
	 * @param string|null $key Id to set
28
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Locale language item for chaining method calls
29
	 */
30
	public function setId( ?string $key ) : \Aimeos\MShop\Common\Item\Iface
31
	{
32
		return parent::setId( $this->checkLanguageId( $key ) );
33
	}
34
35
36
	/**
37
	 * Returns the two letter ISO language code.
38
	 *
39
	 * @return string two letter ISO language code
40
	 */
41
	public function getCode() : string
42
	{
43
		return (string) $this->get( 'locale.language.code', $this->get( 'locale.language.id', '' ) );
44
	}
45
46
47
	/**
48
	 * Sets the two letter ISO language code.
49
	 *
50
	 * @param string $code two letter ISO language code
51
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Locale language item for chaining method calls
52
	 */
53
	public function setCode( string $code ) : \Aimeos\MShop\Common\Item\Iface
54
	{
55
		return $this->set( 'locale.language.code', $this->checkLanguageId( $code, false ) );
56
	}
57
58
59
	/**
60
	 * Returns the label property.
61
	 *
62
	 * @return string Returns the label of the language
63
	 */
64
	public function getLabel() : string
65
	{
66
		return (string) $this->get( 'locale.language.label', '' );
67
	}
68
69
70
	/**
71
	 * Sets the label property.
72
	 *
73
	 * @param string $label Label of the language
74
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Locale language item for chaining method calls
75
	 */
76
	public function setLabel( string $label ) : \Aimeos\MShop\Locale\Item\Language\Iface
77
	{
78
		return $this->set( 'locale.language.label', (string) $label );
79
	}
80
81
82
	/**
83
	 * Returns the status of the item.
84
	 *
85
	 * @return int Status of the item
86
	 */
87
	public function getStatus() : int
88
	{
89
		return $this->get( 'locale.language.status', 1 );
90
	}
91
92
93
	/**
94
	 * Sets the status of the item.
95
	 *
96
	 * @param int $status Status of the item
97
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Locale language item for chaining method calls
98
	 */
99
	public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface
100
	{
101
		return $this->set( 'locale.language.status', $status );
102
	}
103
104
105
	/**
106
	 * Tests if the item is available based on status, time, language and currency
107
	 *
108
	 * @return bool True if available, false if not
109
	 */
110
	public function isAvailable() : bool
111
	{
112
		return parent::isAvailable() && $this->getStatus() > 0;
113
	}
114
115
116
	/*
117
	 * Sets the item values from the given array and removes that entries from the list
118
	 *
119
	 * @param array &$list Associative list of item keys and their values
120
	 * @param bool True to set private properties too, false for public only
121
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Language item for chaining method calls
122
	 */
123
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
124
	{
125
		$item = parent::fromArray( $list, $private );
126
127
		foreach( $list as $key => $value )
128
		{
129
			switch( $key )
130
			{
131
				case 'locale.language.code': $item->setCode( $value ); break;
132
				case 'locale.language.label': $item->setLabel( $value ); break;
133
				case 'locale.language.status': $item->setStatus( (int) $value ); break;
134
				default: continue 2;
135
			}
136
137
			unset( $list[$key] );
138
		}
139
140
		return $item;
141
	}
142
143
144
	/**
145
	 * Returns the item values as array.
146
	 *
147
	 * @param bool True to return private properties, false for public only
148
	 * @return array Associative list of item properties and their values
149
	 */
150
	public function toArray( bool $private = false ) : array
151
	{
152
		$list = parent::toArray( $private );
153
154
		$list['locale.language.code'] = $this->getCode();
155
		$list['locale.language.label'] = $this->getLabel();
156
		$list['locale.language.status'] = $this->getStatus();
157
158
		return $list;
159
	}
160
}
161