/
Default.php
246 lines (199 loc) · 5.29 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
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2011
* @license LGPLv3, http://www.arcavias.com/en/license
* @package MShop
* @subpackage Locale
*/
/**
* Common locale class containing the site, language and currency information.
*
* @package MShop
* @subpackage Locale
*/
class MShop_Locale_Item_Default
extends MShop_Common_Item_Abstract
implements MShop_Locale_Item_Interface
{
private $_site;
private $_sitePath;
private $_siteSubTree;
private $_values;
/**
* Initializes the object with the locale values.
*
* @param array $values Values to be set on initialisation
* @param MShop_Locale_Item_Site_Interface|null $site Site object
* @param array $sitePath List of site IDs up to the root site item
* @param array $siteSubTree List of site IDs from all sites below the current site
*/
public function __construct( array $values = array( ), MShop_Locale_Item_Site_Interface $site = null,
array $sitePath = array(), array $siteSubTree = array() )
{
parent::__construct('locale.', $values);
$this->_values = $values;
$this->_site = $site;
$this->_sitePath = $sitePath;
$this->_siteSubTree = $siteSubTree;
}
/**
* Clones internal objects of the locale item.
*/
public function __clone()
{
$this->_site = ( isset( $this->_site ) ? clone $this->_site : null );
}
/**
* Returns the site item object.
*
* @return MShop_Locale_Item_Site_Interface Site item object
* @throws MShop_Locale_Exception if site object isn't available
*/
public function getSite()
{
if ( $this->_site === null ) {
throw new MShop_Locale_Exception('No site item available');
}
return $this->_site;
}
/**
* Returns the list site IDs up to the root site item.
*
* @return array List of site IDs
*/
public function getSitePath()
{
return $this->_sitePath;
}
/**
* Returns the list site IDs of the whole site subtree.
*
* @return array List of site IDs
*/
public function getSiteSubTree()
{
return $this->_siteSubTree;
}
/**
* Returns the Site ID of the item.
*
* @return integer|null Site ID (or null for global site)
*/
public function getSiteId()
{
return ( isset( $this->_values['siteid'] ) ? (int) $this->_values['siteid'] : null );
}
/**
* Sets the identifier of the shop instance.
*
* @param integer ID of the shop instance.
*/
public function setSiteId( $id )
{
if ( $id === $this->getSiteId() ) { return; }
$this->_values['siteid'] = (int) $id;
$this->_sitePath = array( (int) $id );
$this->_siteSubTree = array( (int) $id );
/** @todo: Wrong site item shouldn't be available any more but causes problems in controller */
// $this->_site = null;
$this->setModified();
}
/**
* Returns the ISO language code.
*
* @return string|null ISO language code (e.g. de or de_DE)
*/
public function getLanguageId()
{
return ( isset( $this->_values['langid'] ) ? (string) $this->_values['langid'] : null );
}
/**
* Sets the ISO language code.
*
* @param string|null $langid ISO language code (e.g. de or de_DE)
* @throws MShop_Exception If the language ID is invalid
*/
public function setLanguageId( $langid )
{
if ( $langid == $this->getLanguageId() ) { return; }
$this->_checkLanguageId( $langid );
$this->_values['langid'] = $langid;
$this->setModified();
}
/**
* Returns the currency ID.
*
* @return string|null Three letter ISO currency code (e.g. EUR)
*/
public function getCurrencyId()
{
return ( isset( $this->_values['currencyid'] ) ? (string) $this->_values['currencyid'] : null );
}
/**
* Sets the currency ID.
*
* @param string|null $currencyid Three letter ISO currency code (e.g. EUR)
* @throws MShop_Exception If the currency ID is invalid
*/
public function setCurrencyId( $currencyid )
{
if ( $currencyid == $this->getCurrencyId() ) { return; }
$this->_checkCurrencyId( $currencyid );
$this->_values['currencyid'] = $currencyid;
$this->setModified();
}
/**
* Returns the position of the item.
*
* @return integer Position of the item relative to the other items
*/
public function getPosition()
{
return ( isset( $this->_values['pos'] ) ? (int) $this->_values['pos'] : 0 );
}
/**
* Sets the position of the item.
*
* @param integer $pos Position of the item
*/
public function setPosition( $pos )
{
if ( $pos == $this->getPosition() ) { return; }
$this->_values['pos'] = (int) $pos;
$this->setModified();
}
/**
* Returns the status property of the locale item
*
* @return integer Returns the status of the locale item
*/
public function getStatus()
{
return ( isset( $this->_values['status'] ) ? (int) $this->_values['status'] : 0 );
}
/**
* Sets the status property
*
* @param integer $status The status of the locale item
*/
public function setStatus( $status )
{
if ( $status == $this->getStatus() ) { return; }
$this->_values['status'] = (int) $status;
$this->setModified();
}
/**
* Returns the item values as array.
*
* @return Associative list of item properties and their values
*/
public function toArray()
{
$list = parent::toArray();
$list['locale.languageid'] = $this->getLanguageId();
$list['locale.currencyid'] = $this->getCurrencyId();
$list['locale.position'] = $this->getPosition();
$list['locale.status'] = $this->getStatus();
return $list;
}
}