This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
/
Default.php
executable file
·406 lines (341 loc) · 11.4 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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2011
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @package MShop
* @subpackage Customer
*/
/**
* Interface for customer DTO objects used by the shop.
*
* @package MShop
* @subpackage Customer
*/
class MShop_Customer_Item_Default
extends MShop_Common_Item_ListRef_Abstract
implements MShop_Customer_Item_Interface
{
private $_billingaddress;
private $_values;
private $_helper;
private $_salt;
/**
* Initializes the customer item object
*
* @param array $values List of attributes that belong to the customer item
* @param MShop_Common_Item_Address_Interface $address Payment address item object
* @param MShop_Common_List_Item_Interface[] $listItems List of list items
* @param MShop_Common_Item_Interface[] $refItems List of referenced items
* @param string $salt Password salt (optional)
* @param MShop_Common_Item_Helper_Password_Interface $helper Password encryption helper object
*/
public function __construct( MShop_Common_Item_Address_Interface $address, array $values = array(),
array $listItems = array(), array $refItems = array(), $salt = '',
MShop_Common_Item_Helper_Password_Interface $helper = null )
{
parent::__construct( 'customer.', $values, $listItems, $refItems );
foreach( $values as $name => $value )
{
switch( $name )
{
case 'salutation': $address->setSalutation( $value ); break;
case 'company': $address->setCompany( $value ); break;
case 'vatid': $address->setVatID( $value ); break;
case 'title': $address->setTitle( $value ); break;
case 'firstname': $address->setFirstname( $value ); break;
case 'lastname': $address->setLastname( $value ); break;
case 'address1': $address->setAddress1( $value ); break;
case 'address2': $address->setAddress2( $value ); break;
case 'address3': $address->setAddress3( $value ); break;
case 'postal': $address->setPostal( $value ); break;
case 'city': $address->setCity( $value ); break;
case 'state': $address->setState( $value ); break;
case 'langid': $address->setLanguageId( $value ); break;
case 'countryid': $address->setCountryId( $value ); break;
case 'telephone': $address->setTelephone( $value ); break;
case 'telefax': $address->setTelefax( $value ); break;
case 'website': $address->setWebsite( $value ); break;
case 'email': $address->setEmail( $value ); break;
}
}
// set modified flag to false
$address->setId( $this->getId() );
$this->_billingaddress = $address;
$this->_values = $values;
$this->_helper = $helper;
$this->_salt = $salt;
}
/**
* Sets the new ID of the item.
*
* @param string|null $id ID of the item
*/
public function setId( $id )
{
parent::setId( $id );
// set modified flag
$this->_billingaddress->setId( $this->getId() );
}
/**
* Returns the label of the customer item.
*
* @return string Label of the customer item
*/
public function getLabel()
{
return ( isset( $this->_values['label'] ) ? (string) $this->_values['label'] : '' );
}
/**
* Sets the new label of the customer item.
*
* @param string $value Label of the customer item
*/
public function setLabel( $value )
{
if( $value == $this->getLabel() ) { return; }
$this->_values['label'] = (string) $value;
$this->setModified();
}
/**
* Returns the status of the item.
*
* @return integer Status of the item
*/
public function getStatus()
{
return ( isset( $this->_values['status'] ) ? (int) $this->_values['status'] : 0 );
}
/**
* Sets the status of the item.
*
* @param integer $value Status of the item
*/
public function setStatus( $value )
{
if( $value == $this->getStatus() ) { return; }
$this->_values['status'] = (int) $value;
$this->setModified();
}
/**
* Returns the code of the customer item.
*
* @return string Code of the customer item
*/
public function getCode()
{
return ( isset( $this->_values['code'] ) ? (string) $this->_values['code'] : '' );
}
/**
* Sets the new code of the customer item.
*
* @param string $value Code of the customer item
*/
public function setCode( $value )
{
$this->_checkCode( $value );
if( $value == $this->getCode() ) { return; }
$this->_values['code'] = (string) $value;
$this->setModified();
}
/**
* Returns the billingaddress of the customer item.
*
* @return MShop_Common_Item_Address_Interface
*/
public function getPaymentAddress()
{
return $this->_billingaddress;
}
/**
* Sets the billingaddress of the customer item.
*
* @param MShop_Common_Item_Address_Interface $address Billingaddress of the customer item
*/
public function setPaymentAddress( MShop_Common_Item_Address_Interface $address )
{
if( $address === $this->_billingaddress && $address->isModified() === false ) { return; }
$this->_billingaddress = $address;
$this->setModified();
}
/**
* Returns the birthday of the customer item.
*
* @return string
*/
public function getBirthday()
{
return ( isset( $this->_values['birthday'] ) ? (string) $this->_values['birthday'] : null );
}
/**
* Sets the birthday of the customer item.
*
* @param string $value Birthday of the customer item
*/
public function setBirthday( $value )
{
if( $value === $this->getBirthday() ) { return; }
if( $value !== null )
{
$this->_checkDateOnlyFormat( $value );
$value = (string) $value;
}
$this->_values['birthday'] = $value;
$this->setModified();
}
/**
* Returns the password of the customer item.
*
* @return string
*/
public function getPassword()
{
return ( isset( $this->_values['password'] ) ? (string) $this->_values['password'] : '' );
}
/**
* Sets the password of the customer item.
*
* @param string $value password of the customer item
*/
public function setPassword( $value )
{
if( $value == $this->getPassword() ) { return; }
if( $this->_helper !== null ) {
$value = $this->_helper->encode( $value, $this->_salt );
}
$this->_values['password'] = $value;
$this->setModified();
}
/**
* Returns the last verification date of the customer.
*
* @return string|null Last verification date of the customer (YYYY-MM-DD format) or null if unknown
*/
public function getDateVerified()
{
return ( isset( $this->_values['vdate'] ) ? (string) $this->_values['vdate'] : null );
}
/**
* Sets the latest verification date of the customer.
*
* @param string|null $value Latest verification date of the customer (YYYY-MM-DD) or null if unknown
*/
public function setDateVerified( $value )
{
if( $value === $this->getDateVerified() ) { return; }
$this->_checkDateOnlyFormat( $value );
$this->_values['vdate'] = ( $value ? (string) $value : null );
$this->setModified();
}
/**
* Returns the group IDs the customer belongs to
*
* @return array List of group IDs
*/
public function getGroups()
{
if( !isset( $this->_values['groups'] ) )
{
$this->_values['groups'] = array();
foreach( $this->getListItems( 'customer/group' ) as $listItem ) {
$this->_values['groups'][] = $listItem->getRefId();
}
}
return (array) $this->_values['groups'];
}
/**
* 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 );
$addr = $this->getPaymentAddress();
foreach( $list as $key => $value )
{
switch( $key )
{
case 'customer.label': $this->setLabel( $value ); break;
case 'customer.code': $this->setCode( $value ); break;
case 'customer.birthday': $this->setBirthday( $value ); break;
case 'customer.status': $this->setStatus( $value ); break;
case 'customer.password': $this->setPassword( $value ); break;
case 'customer.dateverified': $this->setDateVerified( $value ); break;
case 'customer.salutation': $addr->setSalutation( $value ); break;
case 'customer.company': $addr->setCompany( $value ); break;
case 'customer.vatid': $addr->setVatID( $value ); break;
case 'customer.title': $addr->setTitle( $value ); break;
case 'customer.firstname': $addr->setFirstname( $value ); break;
case 'customer.lastname': $addr->setLastname( $value ); break;
case 'customer.address1': $addr->setAddress1( $value ); break;
case 'customer.address2': $addr->setAddress2( $value ); break;
case 'customer.address3': $addr->setAddress3( $value ); break;
case 'customer.postal': $addr->setPostal( $value ); break;
case 'customer.city': $addr->setCity( $value ); break;
case 'customer.state': $addr->setState( $value ); break;
case 'customer.languageid': $addr->setLanguageId( $value ); break;
case 'customer.countryid': $addr->setCountryId( $value ); break;
case 'customer.telephone': $addr->setTelephone( $value ); break;
case 'customer.email': $addr->setEmail( $value ); break;
case 'customer.telefax': $addr->setTelefax( $value ); break;
case 'customer.website': $addr->setWebsite( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
/**
* Returns the item values as array.
*
* @return array Associative list of item properties and their values
*/
public function toArray()
{
$list = parent::toArray();
$list['customer.label'] = $this->getLabel();
$list['customer.code'] = $this->getCode();
$list['customer.birthday'] = $this->getBirthday();
$list['customer.status'] = $this->getStatus();
$list['customer.password'] = $this->getPassword();
$list['customer.dateverified'] = $this->getDateVerified();
$list['customer.salutation'] = $this->getPaymentAddress()->getSalutation();
$list['customer.company'] = $this->getPaymentAddress()->getCompany();
$list['customer.vatid'] = $this->getPaymentAddress()->getVatID();
$list['customer.title'] = $this->getPaymentAddress()->getTitle();
$list['customer.firstname'] = $this->getPaymentAddress()->getFirstname();
$list['customer.lastname'] = $this->getPaymentAddress()->getLastname();
$list['customer.address1'] = $this->getPaymentAddress()->getAddress1();
$list['customer.address2'] = $this->getPaymentAddress()->getAddress2();
$list['customer.address3'] = $this->getPaymentAddress()->getAddress3();
$list['customer.postal'] = $this->getPaymentAddress()->getPostal();
$list['customer.city'] = $this->getPaymentAddress()->getCity();
$list['customer.state'] = $this->getPaymentAddress()->getState();
$list['customer.languageid'] = $this->getPaymentAddress()->getLanguageId();
$list['customer.countryid'] = $this->getPaymentAddress()->getCountryId();
$list['customer.telephone'] = $this->getPaymentAddress()->getTelephone();
$list['customer.email'] = $this->getPaymentAddress()->getEmail();
$list['customer.telefax'] = $this->getPaymentAddress()->getTelefax();
$list['customer.website'] = $this->getPaymentAddress()->getWebsite();
return $list;
}
/**
* Implements deep copies for clones.
*/
public function __clone()
{
$this->_billingaddress = clone $this->_billingaddress;
}
/**
* Tests if the date param represents an ISO format.
*
* @param string|null $date ISO date in YYYY-MM-DD format or null for no date
*/
protected function _checkDateOnlyFormat( $date )
{
if( $date !== null && preg_match( '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/', $date ) !== 1 ) {
throw new MShop_Exception( sprintf( 'Invalid characters in date "%1$s". ISO format "YYYY-MM-DD" expected.', $date ) );
}
}
}