-
Notifications
You must be signed in to change notification settings - Fork 110
/
Standard.php
358 lines (291 loc) · 7.85 KB
/
Standard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2015-2017
* @package MShop
* @subpackage Attribute
*/
namespace Aimeos\MShop\Attribute\Item;
/**
* Default attribute item implementation.
*
* @package MShop
* @subpackage Attribute
*/
class Standard
extends \Aimeos\MShop\Common\Item\ListRef\Base
implements \Aimeos\MShop\Attribute\Item\Iface
{
use \Aimeos\MShop\Common\Item\PropertyRef\Traits;
private $values;
/**
* Initializes the attribute item.
*
* @param array $values Associative array with id, domain, code, and status to initialize the item properties; Optional
* @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
* @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
* @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
*/
public function __construct( array $values = [], array $listItems = [],
array $refItems = [], array $propItems = [] )
{
parent::__construct( 'attribute.', $values, $listItems, $refItems );
$this->setPropertyItems( $propItems );
$this->values = $values;
}
/**
* Returns the domain of the attribute item.
*
* @return string Returns the domain for this item e.g. text, media, price...
*/
public function getDomain()
{
if( isset( $this->values['attribute.domain'] ) ) {
return (string) $this->values['attribute.domain'];
}
return '';
}
/**
* Set the name of the domain for this attribute item.
*
* @param string $domain Name of the domain e.g. text, media, price...
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setDomain( $domain )
{
if( (string) $domain !== $this->getDomain() )
{
$this->values['attribute.domain'] = (string) $domain;
$this->setModified();
}
return $this;
}
/**
* Returns the type id of the attribute.
*
* @return string|null Type of the attribute
*/
public function getTypeId()
{
if( isset( $this->values['attribute.typeid'] ) ) {
return (string) $this->values['attribute.typeid'];
}
return null;
}
/**
* Sets the new type of the attribute.
*
* @param string $typeid Type of the attribute
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setTypeId( $typeid )
{
if( (string) $typeid !== $this->getTypeId() )
{
$this->values['attribute.typeid'] = (string) $typeid;
$this->setModified();
}
return $this;
}
/**
* Returns the type code of the attribute item.
*
* @return string|null Type code of the attribute item
*/
public function getType()
{
if( isset( $this->values['attribute.type'] ) ) {
return (string) $this->values['attribute.type'];
}
return null;
}
/**
* Returns the localized name of the type
*
* @return string|null Localized name of the type
*/
public function getTypeName()
{
if( isset( $this->values['attribute.typename'] ) ) {
return (string) $this->values['attribute.typename'];
}
return null;
}
/**
* Returns a unique code of the attribute item.
*
* @return string Returns the code of the attribute item
*/
public function getCode()
{
if( isset( $this->values['attribute.code'] ) ) {
return (string) $this->values['attribute.code'];
}
return '';
}
/**
* Sets a unique code for the attribute item.
*
* @param string $code Code of the attribute item
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setCode( $code )
{
if( strlen( $code ) > 255 ) {
throw new \Aimeos\MShop\Attribute\Exception( sprintf( 'Code must not be longer than 255 characters' ) );
}
if( (string) $code !== $this->getCode() )
{
$this->values['attribute.code'] = (string) $code;
$this->setModified();
}
return $this;
}
/**
* Returns the name of the attribute item.
*
* @return string Label of the attribute item
*/
public function getLabel()
{
if( isset( $this->values['attribute.label'] ) ) {
return (string) $this->values['attribute.label'];
}
return '';
}
/**
* Sets the new label of the attribute item.
*
* @param string $label Type label of the attribute item
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setLabel( $label )
{
if( (string) $label !== $this->getLabel() )
{
$this->values['attribute.label'] = (string) $label;
$this->setModified();
}
return $this;
}
/**
* Returns the status (enabled/disabled) of the attribute item.
*
* @return integer Returns the status of the item
*/
public function getStatus()
{
if( isset( $this->values['attribute.status'] ) ) {
return (int) $this->values['attribute.status'];
}
return 0;
}
/**
* Sets the new status of the attribute item.
*
* @param integer $status Status of the item
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setStatus( $status )
{
if( (int) $status !== $this->getStatus() )
{
$this->values['attribute.status'] = (int) $status;
$this->setModified();
}
return $this;
}
/**
* Gets the position of the attribute item.
*
* @return integer Position of the attribute item
*/
public function getPosition()
{
if( isset( $this->values['attribute.position'] ) ) {
return (int) $this->values['attribute.position'];
}
return 0;
}
/**
* Sets the position of the attribute item
*
* @param integer $pos Position of the attribute item
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item for chaining method calls
*/
public function setPosition( $pos )
{
if( (int) $pos !== $this->getPosition() )
{
$this->values['attribute.position'] = (int) $pos;
$this->setModified();
}
return $this;
}
/**
* Returns the item type
*
* @return string Item type, subtypes are separated by slashes
*/
public function getResourceType()
{
return 'attribute';
}
/**
* Tests if the item is available based on status, time, language and currency
*
* @return boolean True if available, false if not
*/
public function isAvailable()
{
return parent::isAvailable() && (bool) $this->getStatus();
}
/**
* Sets the item values from the given array.
*
* @param array $list Associative list of item keys and their values
* @return array Associative list of keys and their values that are unknown
*/
public function fromArray( array $list )
{
$unknown = [];
$list = parent::fromArray( $list );
unset( $list['attribute.type'], $list['attribute.typename'] );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'attribute.domain': $this->setDomain( $value ); break;
case 'attribute.code': $this->setCode( $value ); break;
case 'attribute.status': $this->setStatus( $value ); break;
case 'attribute.typeid': $this->setTypeId( $value ); break;
case 'attribute.position': $this->setPosition( $value ); break;
case 'attribute.label': $this->setLabel( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
/**
* Returns the item values as array.
*
* @param boolean True to return private properties, false for public only
* @return array Associative list of item properties and their values
*/
public function toArray( $private = false )
{
$list = parent::toArray( $private );
$list['attribute.domain'] = $this->getDomain();
$list['attribute.code'] = $this->getCode();
$list['attribute.status'] = $this->getStatus();
$list['attribute.type'] = $this->getType();
$list['attribute.typename'] = $this->getTypeName();
$list['attribute.position'] = $this->getPosition();
$list['attribute.label'] = $this->getLabel();
if( $private === true ) {
$list['attribute.typeid'] = $this->getTypeId();
}
return $list;
}
}