These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Metaways Infosystems GmbH, 2011 |
||
6 | * @copyright Aimeos (aimeos.org), 2015-2017 |
||
7 | * @package MShop |
||
8 | * @subpackage Common |
||
9 | */ |
||
10 | |||
11 | |||
12 | namespace Aimeos\MShop\Common\Item\Type; |
||
13 | |||
14 | |||
15 | /** |
||
16 | * Default implementation of the list item. |
||
17 | * |
||
18 | * @package MShop |
||
19 | * @subpackage Common |
||
20 | */ |
||
21 | class Standard |
||
22 | extends \Aimeos\MShop\Common\Item\Base |
||
23 | implements \Aimeos\MShop\Common\Item\Type\Iface |
||
24 | { |
||
25 | private $prefix; |
||
26 | private $values; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * Initializes the type item object. |
||
31 | * |
||
32 | * @param string $prefix Property prefix when converting to array |
||
33 | * @param array $values Initial values of the list type item |
||
34 | */ |
||
35 | public function __construct( $prefix, array $values = [] ) |
||
36 | { |
||
37 | parent::__construct( $prefix, $values ); |
||
38 | |||
39 | $this->prefix = $prefix; |
||
40 | $this->values = $values; |
||
41 | } |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Returns the code of the common list type item |
||
46 | * |
||
47 | * @return string Code of the common list type item |
||
48 | */ |
||
49 | public function getCode() |
||
50 | { |
||
51 | if( isset( $this->values[$this->prefix . 'code'] ) ) { |
||
52 | return (string) $this->values[$this->prefix . 'code']; |
||
53 | } |
||
54 | |||
55 | return ''; |
||
56 | } |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Sets the code of the common list type item |
||
61 | * |
||
62 | * @param string $code New code of the common list type item |
||
63 | * @return \Aimeos\MShop\Common\Item\Type\Iface Common type item for chaining method calls |
||
64 | */ |
||
65 | public function setCode( $code ) |
||
66 | { |
||
67 | if( (string) $code !== $this->getCode() ) |
||
68 | { |
||
69 | $this->values[$this->prefix . 'code'] = $this->checkCode( $code ); |
||
70 | $this->setModified(); |
||
71 | } |
||
72 | |||
73 | return $this; |
||
74 | } |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Returns the domain of the common list type item |
||
79 | * |
||
80 | * @return string Domain of the common list type item |
||
81 | */ |
||
82 | public function getDomain() |
||
83 | { |
||
84 | if( isset( $this->values[$this->prefix . 'domain'] ) ) { |
||
85 | return (string) $this->values[$this->prefix . 'domain']; |
||
86 | } |
||
87 | |||
88 | return ''; |
||
89 | } |
||
90 | |||
91 | |||
92 | /** |
||
93 | * Sets the domain of the common list type item |
||
94 | * |
||
95 | * @param string $domain New domain of the common list type item |
||
96 | * @return \Aimeos\MShop\Common\Item\Type\Iface Common type item for chaining method calls |
||
97 | */ |
||
98 | public function setDomain( $domain ) |
||
99 | { |
||
100 | if( (string) $domain !== $this->getDomain() ) |
||
101 | { |
||
102 | $this->values[$this->prefix . 'domain'] = (string) $domain; |
||
103 | $this->setModified(); |
||
104 | } |
||
105 | |||
106 | return $this; |
||
107 | } |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Returns the translated name for the type item |
||
112 | * |
||
113 | * @return string Translated name of the type item |
||
114 | */ |
||
115 | public function getName() |
||
116 | { |
||
117 | if( isset( $this->values[$this->prefix . 'name'] ) ) { |
||
118 | return (string) $this->values[$this->prefix . 'name']; |
||
119 | } |
||
120 | |||
121 | return $this->getLabel(); |
||
122 | } |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Returns the label of the common list type item |
||
127 | * |
||
128 | * @return string Label of the common list type item |
||
129 | */ |
||
130 | public function getLabel() |
||
131 | { |
||
132 | if( isset( $this->values[$this->prefix . 'label'] ) ) { |
||
133 | return (string) $this->values[$this->prefix . 'label']; |
||
134 | } |
||
135 | |||
136 | return ''; |
||
137 | } |
||
138 | |||
139 | |||
140 | /** |
||
141 | * Sets the label of the common list type item |
||
142 | * |
||
143 | * @param string $label New label of the common list type item |
||
144 | * @return \Aimeos\MShop\Common\Item\Type\Iface Common type item for chaining method calls |
||
145 | */ |
||
146 | public function setLabel( $label ) |
||
147 | { |
||
148 | if( (string) $label !== $this->getLabel() ) |
||
149 | { |
||
150 | $this->values[$this->prefix . 'label'] = (string) $label; |
||
151 | $this->setModified(); |
||
152 | } |
||
153 | |||
154 | return $this; |
||
155 | } |
||
156 | |||
157 | |||
158 | /** |
||
159 | * Returns the status of the common list type item |
||
160 | * |
||
161 | * @return integer Status of the common list type item |
||
162 | */ |
||
163 | public function getStatus() |
||
164 | { |
||
165 | if( isset( $this->values[$this->prefix . 'status'] ) ) { |
||
166 | return (int) $this->values[$this->prefix . 'status']; |
||
167 | } |
||
168 | |||
169 | return 0; |
||
170 | } |
||
171 | |||
172 | |||
173 | /** |
||
174 | * Sets the status of the common list type item |
||
175 | * |
||
176 | * @param integer $status New status of the common list type item |
||
177 | * @return \Aimeos\MShop\Common\Item\Type\Iface Common type item for chaining method calls |
||
178 | */ |
||
179 | public function setStatus( $status ) |
||
180 | { |
||
181 | if( (int) $status !== $this->getStatus() ) |
||
182 | { |
||
183 | $this->values[$this->prefix . 'status'] = (int) $status; |
||
184 | $this->setModified(); |
||
185 | } |
||
186 | |||
187 | return $this; |
||
188 | } |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Returns the item type |
||
193 | * |
||
194 | * @return string Item type, subtypes are separated by slashes |
||
195 | */ |
||
196 | public function getResourceType() |
||
197 | { |
||
198 | return str_replace( '.', '/', rtrim( $this->prefix, '.' ) ); |
||
199 | } |
||
200 | |||
201 | |||
202 | /** |
||
203 | * Tests if the item is available based on status, time, language and currency |
||
204 | * |
||
205 | * @return boolean True if available, false if not |
||
206 | */ |
||
207 | public function isAvailable() |
||
208 | { |
||
209 | return (bool) $this->getStatus(); |
||
210 | } |
||
211 | |||
212 | |||
213 | /** |
||
214 | * Sets the item values from the given array. |
||
215 | * |
||
216 | * @param array $list Associative list of item keys and their values |
||
217 | * @return array Associative list of keys and their values that are unknown |
||
218 | */ |
||
219 | public function fromArray( array $list ) |
||
220 | { |
||
221 | $unknown = []; |
||
222 | $list = parent::fromArray( $list ); |
||
223 | unset( $list[$this->prefix . 'name'] ); |
||
224 | |||
225 | foreach( $list as $key => $value ) |
||
226 | { |
||
227 | switch( $key ) |
||
228 | { |
||
229 | case $this->prefix . 'code': $this->setCode( $value ); break; |
||
230 | case $this->prefix . 'domain': $this->setDomain( $value ); break; |
||
231 | case $this->prefix . 'label': $this->setLabel( $value ); break; |
||
232 | case $this->prefix . 'status': $this->setStatus( $value ); break; |
||
233 | default: $unknown[$key] = $value; |
||
0 ignored issues
–
show
|
|||
234 | } |
||
235 | } |
||
236 | |||
237 | return $unknown; |
||
238 | } |
||
239 | |||
240 | |||
241 | /** |
||
242 | * Returns an associative list of item properties. |
||
243 | * |
||
244 | * @param boolean True to return private properties, false for public only |
||
245 | * @return array List of item properties. |
||
246 | */ |
||
247 | public function toArray( $private = false ) |
||
248 | { |
||
249 | $list = parent::toArray( $private ); |
||
250 | |||
251 | $list[$this->prefix . 'code'] = $this->getCode(); |
||
252 | $list[$this->prefix . 'domain'] = $this->getDomain(); |
||
253 | $list[$this->prefix . 'name'] = $this->getName(); |
||
254 | $list[$this->prefix . 'label'] = $this->getLabel(); |
||
255 | $list[$this->prefix . 'status'] = $this->getStatus(); |
||
256 | |||
257 | return $list; |
||
258 | } |
||
259 | } |
||
260 |
According to the PSR-2, the body of a default statement must start on the line immediately following the statement.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.