This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
/
Default.php
307 lines (249 loc) · 7 KB
/
Default.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
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2015
* @package MShop
* @subpackage Product
*/
/**
* Default impelementation of a product item.
*
* @package MShop
* @subpackage Product
*/
class MShop_Product_Item_Default
extends MShop_Common_Item_ListRef_Abstract
implements MShop_Product_Item_Interface
{
private $_values;
/**
* Initializes the item object.
*
* @param array $values Parameter for initializing the basic properties
* @param MShop_Common_List_Item_Interface[] $listItems List of list items
* @param MShop_Common_Item_Interface[] $refItems List of referenced items
*/
public function __construct( array $values = array(), array $listItems = array(), array $refItems = array() )
{
parent::__construct( 'product.', $values, $listItems, $refItems );
$this->_values = $values;
}
/**
* Returns the type ID of the product item.
*
* @return integer|null Type ID of the product item
*/
public function getTypeId()
{
return ( isset( $this->_values['typeid'] ) ? (int) $this->_values['typeid'] : null );
}
/**
* Sets the new type ID of the product item.
*
* @param integer $typeid New type ID of the product item
*/
public function setTypeId( $typeid )
{
if( $typeid == $this->getTypeId() ) { return; }
$this->_values['typeid'] = (int) $typeid;
$this->setModified();
}
/**
* Returns the type of the product item.
*
* @return string|null Type of the product item
*/
public function getType()
{
return ( isset( $this->_values['type'] ) ? (string) $this->_values['type'] : null );
}
/**
* Returns the status of the product item.
*
* @return integer Status of the product item
*/
public function getStatus()
{
return ( isset( $this->_values['status'] ) ? (int) $this->_values['status'] : 0 );
}
/**
* Sets the new status of the product item.
*
* @param integer $status New status of the product item
*/
public function setStatus( $status )
{
if( $status == $this->getStatus() ) { return; }
$this->_values['status'] = (int) $status;
$this->setModified();
}
/**
* Returns the code of the product item.
*
* @return string Code of the product item
*/
public function getCode()
{
return ( isset( $this->_values['code'] ) ? (string) $this->_values['code'] : '' );
}
/**
* Sets the new code of the product item.
*
* @param string $code New code of product item
*/
public function setCode( $code )
{
$this->_checkCode( $code );
if( $code == $this->getCode() ) { return; }
$this->_values['code'] = (string) $code;
$this->setModified();
}
/**
* Returns the supplier code of the product item.
*
* @return string supplier code of the product item
*/
public function getSupplierCode()
{
return ( isset( $this->_values['suppliercode'] ) ? (string) $this->_values['suppliercode'] : '' );
}
/**
* Sets the new supplier code of the product item.
*
* @param string $suppliercode New supplier code of the product item
*/
public function setSupplierCode( $suppliercode )
{
if( $suppliercode == $this->getSupplierCode() ) { return; }
$this->_values['suppliercode'] = (string) $suppliercode;
$this->setModified();
}
/**
* Returns the label of the product item.
*
* @return string Label of the product item
*/
public function getLabel()
{
return ( isset( $this->_values['label'] ) ? (string) $this->_values['label'] : '' );
}
/**
* Sets a new label of the product item.
*
* @param string $label New label of the product item
*/
public function setLabel( $label )
{
if( $label == $this->getLabel() ) { return; }
$this->_values['label'] = (string) $label;
$this->setModified();
}
/**
* Returns the starting point of time, in which the product is available.
*
* @return string|null ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function getDateStart()
{
return ( isset( $this->_values['start'] ) ? (string) $this->_values['start'] : null );
}
/**
* Sets a new starting point of time, in which the product is available.
*
* @param string|null New ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function setDateStart( $date )
{
if( $date === $this->getDateStart() ) { return; }
$this->_checkDateFormat( $date );
$this->_values['start'] = ( $date !== null ? (string) $date : null );
$this->setModified();
}
/**
* Returns the ending point of time, in which the product is available.
*
* @return string|null ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function getDateEnd()
{
return ( isset( $this->_values['end'] ) ? (string) $this->_values['end'] : null );
}
/**
* Sets a new ending point of time, in which the product is available.
*
* @param string|null New ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function setDateEnd( $date )
{
if( $date === $this->getDateEnd() ) { return; }
$this->_checkDateFormat( $date );
$this->_values['end'] = ( $date !== null ? (string) $date : null );
$this->setModified();
}
/**
* Returns the configuration values of the item
*
* @return array Configuration values
*/
public function getConfig()
{
return ( isset( $this->_values['config'] ) ? $this->_values['config'] : array() );
}
/**
* Sets the configuration values of the item.
*
* @param array $config Configuration values
*/
public function setConfig( array $config )
{
$this->_values['config'] = $config;
$this->setModified();
}
/**
* 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 = array();
$list = parent::fromArray( $list );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'product.typeid': $this->setTypeId( $value ); break;
case 'product.code': $this->setCode( $value ); break;
case 'product.label': $this->setLabel( $value ); break;
case 'product.status': $this->setStatus( $value ); break;
case 'product.suppliercode': $this->setSupplierCode( $value ); break;
case 'product.datestart': $this->setDateStart( $value ); break;
case 'product.dateend': $this->setDateEnd( $value ); break;
case 'product.config': $this->setConfig( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
/**
* Returns the item values as array.
*
* @return Associative list of item properties and their values
*/
public function toArray()
{
$list = parent::toArray();
$list['product.typeid'] = $this->getTypeId();
$list['product.type'] = $this->getType();
$list['product.code'] = $this->getCode();
$list['product.label'] = $this->getLabel();
$list['product.status'] = $this->getStatus();
$list['product.suppliercode'] = $this->getSupplierCode();
$list['product.datestart'] = $this->getDateStart();
$list['product.dateend'] = $this->getDateEnd();
$list['product.config'] = $this->getConfig();
return $list;
}
}