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 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
|
|
|
private $children; |
26
|
|
|
private $values; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the site object. |
30
|
|
|
* |
31
|
|
|
* @param array $values Associative list of item key/value pairs |
32
|
|
|
* @param array $children List of nodes implementing \Aimeos\MW\Tree\Node\Iface |
33
|
|
|
*/ |
34
|
|
|
public function __construct( array $values = [], array $children = [] ) |
35
|
|
|
{ |
36
|
|
|
\Aimeos\MW\Common\Base::checkClassList( '\\Aimeos\\MShop\\Locale\\Item\\Site\\Iface', $children ); |
37
|
|
|
parent::__construct( 'locale.site.', $values ); |
38
|
|
|
|
39
|
|
|
$this->values = $values; |
40
|
|
|
$this->children = $children; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the id of the site. |
46
|
|
|
* |
47
|
|
|
* @return integer|null Id of the site |
48
|
|
|
*/ |
49
|
|
|
public function getSiteId() |
50
|
|
|
{ |
51
|
|
|
return (int) $this->getId(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the code of the site. |
57
|
|
|
* |
58
|
|
|
* @return string Returns the code of the item |
59
|
|
|
*/ |
60
|
|
|
public function getCode() |
61
|
|
|
{ |
62
|
|
|
if( isset( $this->values['locale.site.code'] ) ) { |
63
|
|
|
return (string) $this->values['locale.site.code']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return ''; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Sets the code of the site. |
72
|
|
|
* |
73
|
|
|
* @param string $code The code to set |
74
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls |
75
|
|
|
*/ |
76
|
|
|
public function setCode( $code ) |
77
|
|
|
{ |
78
|
|
|
if( (string) $code !== $this->getCode() ) |
79
|
|
|
{ |
80
|
|
|
$this->values['locale.site.code'] = $this->checkCode( $code ); |
81
|
|
|
$this->setModified(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Returns the config property of the site. |
90
|
|
|
* |
91
|
|
|
* @return array Returns the config of the Site |
92
|
|
|
*/ |
93
|
|
|
public function getConfig() |
94
|
|
|
{ |
95
|
|
|
if( isset( $this->values['locale.site.config'] ) ) { |
96
|
|
|
return (array) $this->values['locale.site.config']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return []; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets the config property of the site. |
105
|
|
|
* |
106
|
|
|
* @param array $options Options to be set for the Site |
107
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls |
108
|
|
|
*/ |
109
|
|
|
public function setConfig( array $options ) |
110
|
|
|
{ |
111
|
|
|
$this->values['locale.site.config'] = $options; |
112
|
|
|
$this->setModified(); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the label property of the site. |
120
|
|
|
* |
121
|
|
|
* @return string Returns the label of the Site |
122
|
|
|
*/ |
123
|
|
|
public function getLabel() |
124
|
|
|
{ |
125
|
|
|
if( isset( $this->values['locale.site.label'] ) ) { |
126
|
|
|
return (string) $this->values['locale.site.label']; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return ''; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Sets the label property of the site. |
135
|
|
|
* |
136
|
|
|
* @param string $label The label of the Site |
137
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls |
138
|
|
|
*/ |
139
|
|
|
public function setLabel( $label ) |
140
|
|
|
{ |
141
|
|
|
if( (string) $label !== $this->getLabel() ) |
142
|
|
|
{ |
143
|
|
|
$this->values['locale.site.label'] = (string) $label; |
144
|
|
|
$this->setModified(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Returns the level of the item in the tree |
153
|
|
|
* |
154
|
|
|
* @return integer Level of the item starting with "0" for the root node |
155
|
|
|
*/ |
156
|
|
|
public function getLevel() |
157
|
|
|
{ |
158
|
|
|
return 0; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns the ID of the parent site |
164
|
|
|
* |
165
|
|
|
* @return string Unique ID of the parent site |
|
|
|
|
166
|
|
|
*/ |
167
|
|
|
public function getParentId() |
168
|
|
|
{ |
169
|
|
|
return 0; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Returns the status property of the Site. |
175
|
|
|
* |
176
|
|
|
* @return integer Returns the status of the Site |
177
|
|
|
*/ |
178
|
|
|
public function getStatus() |
179
|
|
|
{ |
180
|
|
|
if( isset( $this->values['locale.site.status'] ) ) { |
181
|
|
|
return (int) $this->values['locale.site.status']; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return 0; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Sets status property. |
190
|
|
|
* |
191
|
|
|
* @param integer $status The status of the Site |
192
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls |
193
|
|
|
*/ |
194
|
|
|
public function setStatus( $status ) |
195
|
|
|
{ |
196
|
|
|
if( (int) $status !== $this->getStatus() ) |
197
|
|
|
{ |
198
|
|
|
$this->values['locale.site.status'] = (int) $status; |
199
|
|
|
$this->setModified(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Returns the item type |
208
|
|
|
* |
209
|
|
|
* @return string Item type, subtypes are separated by slashes |
210
|
|
|
*/ |
211
|
|
|
public function getResourceType() |
212
|
|
|
{ |
213
|
|
|
return 'locale/site'; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Tests if the item is available based on status, time, language and currency |
219
|
|
|
* |
220
|
|
|
* @return boolean True if available, false if not |
221
|
|
|
*/ |
222
|
|
|
public function isAvailable() |
223
|
|
|
{ |
224
|
|
|
return parent::isAvailable() && (bool) $this->getStatus(); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Sets the item values from the given array. |
230
|
|
|
* |
231
|
|
|
* @param array $list Associative list of item keys and their values |
232
|
|
|
* @return array Associative list of keys and their values that are unknown |
233
|
|
|
*/ |
234
|
|
|
public function fromArray( array $list ) |
235
|
|
|
{ |
236
|
|
|
$unknown = []; |
237
|
|
|
$list = parent::fromArray( $list ); |
238
|
|
|
|
239
|
|
|
foreach( $list as $key => $value ) |
240
|
|
|
{ |
241
|
|
|
switch( $key ) |
242
|
|
|
{ |
243
|
|
|
case 'locale.site.code': $this->setCode( $value ); break; |
244
|
|
|
case 'locale.site.label': $this->setLabel( $value ); break; |
245
|
|
|
case 'locale.site.config': $this->setConfig( $value ); break; |
246
|
|
|
case 'locale.site.status': $this->setStatus( $value ); break; |
247
|
|
|
default: $unknown[$key] = $value; |
|
|
|
|
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
return $unknown; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Returns the item values as array. |
257
|
|
|
* |
258
|
|
|
* @param boolean True to return private properties, false for public only |
259
|
|
|
* @return array Associative list of item properties and their values |
260
|
|
|
*/ |
261
|
|
|
public function toArray( $private = false ) |
262
|
|
|
{ |
263
|
|
|
$list = parent::toArray( $private ); |
264
|
|
|
|
265
|
|
|
$list['locale.site.code'] = $this->getCode(); |
266
|
|
|
$list['locale.site.label'] = $this->getLabel(); |
267
|
|
|
$list['locale.site.config'] = $this->getConfig(); |
268
|
|
|
$list['locale.site.status'] = $this->getStatus(); |
269
|
|
|
$list['locale.site.hasChildren'] = $this->hasChildren(); |
270
|
|
|
|
271
|
|
|
if( $private === true ) |
272
|
|
|
{ |
273
|
|
|
$list['locale.site.level'] = $this->getLevel(); |
274
|
|
|
$list['locale.site.parentid'] = $this->getParentId(); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
return $list; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Returns a child of this node identified by its index. |
283
|
|
|
* |
284
|
|
|
* @param integer $index Index of child node |
285
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Selected node |
286
|
|
|
*/ |
287
|
|
|
public function getChild( $index ) |
288
|
|
|
{ |
289
|
|
|
throw new \Aimeos\MShop\Locale\Exception( sprintf( 'Child node with index "%1$d" not available', $index ) ); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Returns all children of this node. |
295
|
|
|
* |
296
|
|
|
* @return array Numerically indexed list of nodes |
297
|
|
|
*/ |
298
|
|
|
public function getChildren() |
299
|
|
|
{ |
300
|
|
|
return []; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Tests if a node has children. |
306
|
|
|
* |
307
|
|
|
* @return boolean True if node has children, false if not |
308
|
|
|
*/ |
309
|
|
|
public function hasChildren() |
310
|
|
|
{ |
311
|
|
|
return false; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Adds a child node to this node. |
317
|
|
|
* |
318
|
|
|
* @param \Aimeos\MShop\Common\Item\Tree\Iface $item Child node to add |
319
|
|
|
*/ |
320
|
|
|
public function addChild( \Aimeos\MShop\Common\Item\Tree\Iface $item ) |
321
|
|
|
{ |
322
|
|
|
} |
323
|
|
|
} |