Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

Base::getAddressItems()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 2
nop 0
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
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 Customer
9
 */
10
11
12
namespace Aimeos\MShop\Customer\Item;
13
14
15
/**
16
 * Interface for customer DTO objects used by the shop.
17
 *
18
 * @package MShop
19
 * @subpackage Customer
20
 */
21
abstract class Base
22
	extends \Aimeos\MShop\Common\Item\ListRef\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
23
	implements \Aimeos\MShop\Customer\Item\Iface
24
{
25
	use \Aimeos\MShop\Common\Item\AddressRef\Traits;
26
	use \Aimeos\MShop\Common\Item\PropertyRef\Traits;
27
28
29
	private $billingaddress;
30
	private $data;
31
32
33
	/**
34
	 * Initializes the customer item object
35
	 *
36
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $address Payment address item object
37
	 * @param array $values List of attributes that belong to the customer item
38
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
39
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
40
	 * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addresses List of referenced address items
41
	 * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
42
	 */
43
	public function __construct( \Aimeos\MShop\Common\Item\Address\Iface $address, array $values = [],
44
		array $listItems = [], array $refItems = [], $addresses = [], array $propItems = [] )
45
	{
46
		parent::__construct( 'customer.', $values, $listItems, $refItems );
47
48
		foreach( $values as $name => $value )
49
		{
50
			switch( $name )
51
			{
52
				case 'customer.salutation': $address->setSalutation( $value ); break;
53
				case 'customer.company': $address->setCompany( $value ); break;
54
				case 'customer.vatid': $address->setVatId( $value ); break;
55
				case 'customer.title': $address->setTitle( $value ); break;
56
				case 'customer.firstname': $address->setFirstname( $value ); break;
57
				case 'customer.lastname': $address->setLastname( $value ); break;
58
				case 'customer.address1': $address->setAddress1( $value ); break;
59
				case 'customer.address2': $address->setAddress2( $value ); break;
60
				case 'customer.address3': $address->setAddress3( $value ); break;
61
				case 'customer.postal': $address->setPostal( $value ); break;
62
				case 'customer.city': $address->setCity( $value ); break;
63
				case 'customer.state': $address->setState( $value ); break;
64
				case 'customer.languageid': $address->setLanguageId( $value ); break;
65
				case 'customer.countryid': $address->setCountryId( $value ); break;
66
				case 'customer.telephone': $address->setTelephone( $value ); break;
67
				case 'customer.telefax': $address->setTelefax( $value ); break;
68
				case 'customer.website': $address->setWebsite( $value ); break;
69
				case 'customer.longitude': $address->setLongitude( $value ); break;
70
				case 'customer.latitude': $address->setLatitude( $value ); break;
71
				case 'customer.email': $address->setEmail( $value ); break;
72
			}
73
		}
74
75
		$this->initAddressItems( $addresses );
76
		$this->initPropertyItems( $propItems );
77
78
		// set modified flag to false
79
		$address->setId( $this->getId() );
80
81
		$this->billingaddress = $address;
82
		$this->data = $values;
83
	}
84
85
86
	/**
87
	 * Returns the billingaddress of the customer item.
88
	 *
89
	 * @return \Aimeos\MShop\Common\Item\Address\Iface
90
	 */
91
	public function getPaymentAddress()
92
	{
93
		return $this->billingaddress;
94
	}
95
96
97
	/**
98
	 * Sets the billingaddress of the customer item.
99
	 *
100
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $address Billingaddress of the customer item
101
	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item for chaining method calls
102
	 */
103
	public function setPaymentAddress( \Aimeos\MShop\Common\Item\Address\Iface $address )
104
	{
105
		if( $address === $this->billingaddress && $address->isModified() === false ) { return $this; }
106
107
		$this->billingaddress = $address;
108
		$this->setModified();
109
110
		return $this;
111
	}
112
113
114
	/**
115
	 * Returns the item type
116
	 *
117
	 * @return string Item type, subtypes are separated by slashes
118
	 */
119
	public function getResourceType()
120
	{
121
		return 'customer';
122
	}
123
124
125
	/**
126
	 * Tests if this item object was modified
127
	 *
128
	 * @return boolean True if modified, false if not
129
	 */
130
	public function isModified()
131
	{
132
		return parent::isModified() || $this->getPaymentAddress()->isModified();
133
	}
134
135
136
	/**
137
	 * Sets the item values from the given array.
138
	 *
139
	 * @param array $list Associative list of item keys and their values
140
	 * @return array Associative list of keys and their values that are unknown
141
	 */
142
	public function fromArray( array $list )
143
	{
144
		$unknown = [];
145
		$list = parent::fromArray( $list );
146
		$addr = $this->getPaymentAddress();
147
148
		foreach( $list as $key => $value )
149
		{
150
			switch( $key )
151
			{
152
				case 'customer.salutation': $addr->setSalutation( $value ); break;
153
				case 'customer.company': $addr->setCompany( $value ); break;
154
				case 'customer.vatid': $addr->setVatID( $value ); break;
155
				case 'customer.title': $addr->setTitle( $value ); break;
156
				case 'customer.firstname': $addr->setFirstname( $value ); break;
157
				case 'customer.lastname': $addr->setLastname( $value ); break;
158
				case 'customer.address1': $addr->setAddress1( $value ); break;
159
				case 'customer.address2': $addr->setAddress2( $value ); break;
160
				case 'customer.address3': $addr->setAddress3( $value ); break;
161
				case 'customer.postal': $addr->setPostal( $value ); break;
162
				case 'customer.city': $addr->setCity( $value ); break;
163
				case 'customer.state': $addr->setState( $value ); break;
164
				case 'customer.languageid': $addr->setLanguageId( $value ); break;
165
				case 'customer.countryid': $addr->setCountryId( $value ); break;
166
				case 'customer.telephone': $addr->setTelephone( $value ); break;
167
				case 'customer.email': $addr->setEmail( $value ); break;
168
				case 'customer.telefax': $addr->setTelefax( $value ); break;
169
				case 'customer.website': $addr->setWebsite( $value ); break;
170
				case 'customer.longitude': $addr->setLongitude( $value ); break;
171
				case 'customer.latitude': $addr->setLatitude( $value ); break;
172
				default: $unknown[$key] = $value;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
173
			}
174
		}
175
176
		return $unknown;
177
	}
178
179
180
	/**
181
	 * Returns the item values as array.
182
	 *
183
	 * @param boolean True to return private properties, false for public only
184
	 * @return array Associative list of item properties and their values
185
	 */
186
	public function toArray( $private = false )
187
	{
188
		$list = parent::toArray( $private );
189
190
		$list['customer.salutation'] = $this->getPaymentAddress()->getSalutation();
191
		$list['customer.company'] = $this->getPaymentAddress()->getCompany();
192
		$list['customer.vatid'] = $this->getPaymentAddress()->getVatID();
193
		$list['customer.title'] = $this->getPaymentAddress()->getTitle();
194
		$list['customer.firstname'] = $this->getPaymentAddress()->getFirstname();
195
		$list['customer.lastname'] = $this->getPaymentAddress()->getLastname();
196
		$list['customer.address1'] = $this->getPaymentAddress()->getAddress1();
197
		$list['customer.address2'] = $this->getPaymentAddress()->getAddress2();
198
		$list['customer.address3'] = $this->getPaymentAddress()->getAddress3();
199
		$list['customer.postal'] = $this->getPaymentAddress()->getPostal();
200
		$list['customer.city'] = $this->getPaymentAddress()->getCity();
201
		$list['customer.state'] = $this->getPaymentAddress()->getState();
202
		$list['customer.languageid'] = $this->getPaymentAddress()->getLanguageId();
203
		$list['customer.countryid'] = $this->getPaymentAddress()->getCountryId();
204
		$list['customer.telephone'] = $this->getPaymentAddress()->getTelephone();
205
		$list['customer.email'] = $this->getPaymentAddress()->getEmail();
206
		$list['customer.telefax'] = $this->getPaymentAddress()->getTelefax();
207
		$list['customer.website'] = $this->getPaymentAddress()->getWebsite();
208
		$list['customer.longitude'] = $this->getPaymentAddress()->getLongitude();
209
		$list['customer.latitude'] = $this->getPaymentAddress()->getLatitude();
210
211
		return $list;
212
	}
213
214
215
	/**
216
	 * Implements deep copies for clones.
217
	 */
218
	public function __clone()
219
	{
220
		$this->billingaddress = clone $this->billingaddress;
221
	}
222
}
223