Completed
Push — master ( 83756e...027b1b )
by Aimeos
09:33
created

Standard::getLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
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 Locale
9
 */
10
11
12
namespace Aimeos\MShop\Locale\Item\Site;
13
14
15
/**
16
 * Default implementation of a Site item.
17
 *
18
 * @package MShop
19
 * @subpackage Locale
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Item\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
23
	implements \Aimeos\MShop\Locale\Item\Site\Iface
24
{
25
	private $children;
26
	private $values;
27
28
	/**
29
	 * Initializes the site object.
30
	 *
31
	 * @param array $values Associative list of item key/value pairs
32
	 * @param array $children List of nodes implementing \Aimeos\MW\Tree\Node\Iface
33
	 */
34
	public function __construct( array $values = [], array $children = [] )
35
	{
36
		\Aimeos\MW\Common\Base::checkClassList( '\\Aimeos\\MShop\\Locale\\Item\\Site\\Iface', $children );
37
		parent::__construct( 'locale.site.', $values );
38
39
		$this->values = $values;
40
		$this->children = $children;
41
	}
42
43
44
	/**
45
	 * Returns the id of the site.
46
	 *
47
	 * @return integer|null Id of the site
48
	 */
49
	public function getSiteId()
50
	{
51
		return (int) $this->getId();
52
	}
53
54
55
	/**
56
	 * Returns the code of the site.
57
	 *
58
	 * @return string Returns the code of the item
59
	 */
60
	public function getCode()
61
	{
62
		if( isset( $this->values['locale.site.code'] ) ) {
63
			return (string) $this->values['locale.site.code'];
64
		}
65
66
		return '';
67
	}
68
69
70
	/**
71
	 * Sets the code of the site.
72
	 *
73
	 * @param string $code The code to set
74
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
75
	 */
76
	public function setCode( $code )
77
	{
78
		if( $code == $this->getCode() ) { return $this; }
79
80
		$this->values['locale.site.code'] = (string) $this->checkCode( $code );;
81
		$this->setModified();
82
83
		return $this;
84
	}
85
86
87
	/**
88
	 * Returns the config property of the site.
89
	 *
90
	 * @return array Returns the config of the Site
91
	 */
92
	public function getConfig()
93
	{
94
		if( isset( $this->values['locale.site.config'] ) ) {
95
			return (array) $this->values['locale.site.config'];
96
		}
97
98
		return [];
99
	}
100
101
102
	/**
103
	 * Sets the config property of the site.
104
	 *
105
	 * @param array $options Options to be set for the Site
106
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
107
	 */
108
	public function setConfig( array $options )
109
	{
110
		$this->values['locale.site.config'] = $options;
111
		$this->setModified();
112
113
		return $this;
114
	}
115
116
117
	/**
118
	 * Returns the label property of the site.
119
	 *
120
	 * @return string Returns the label of the Site
121
	 */
122
	public function getLabel()
123
	{
124
		if( isset( $this->values['locale.site.label'] ) ) {
125
			return (string) $this->values['locale.site.label'];
126
		}
127
128
		return '';
129
	}
130
131
132
	/**
133
	 * Sets the label property of the site.
134
	 *
135
	 * @param string $label The label of the Site
136
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
137
	 */
138
	public function setLabel( $label )
139
	{
140
		if( $label == $this->getLabel() ) { return $this; }
141
142
		$this->values['locale.site.label'] = (string) $label;
143
		$this->setModified();
144
145
		return $this;
146
	}
147
148
149
	/**
150
	 * Returns the level of the item in the tree
151
	 *
152
	 * @return integer Level of the item starting with "0" for the root node
153
	 */
154
	public function getLevel()
155
	{
156
		return 0;
157
	}
158
159
160
	/**
161
	 * Returns the ID of the parent site
162
	 *
163
	 * @return string Unique ID of the parent site
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
164
	 */
165
	public function getParentId()
166
	{
167
		return 0;
168
	}
169
170
171
	/**
172
	 * Returns the status property of the Site.
173
	 *
174
	 * @return integer Returns the status of the Site
175
	 */
176
	public function getStatus()
177
	{
178
		if( isset( $this->values['locale.site.status'] ) ) {
179
			return (int) $this->values['locale.site.status'];
180
		}
181
182
		return 0;
183
	}
184
185
186
	/**
187
	 * Sets status property.
188
	 *
189
	 * @param integer $status The status of the Site
190
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Locale site item for chaining method calls
191
	 */
192
	public function setStatus( $status )
193
	{
194
		if( $status == $this->getStatus() ) { return $this; }
195
196
		$this->values['locale.site.status'] = (int) $status;
197
		$this->setModified();
198
199
		return $this;
200
	}
201
202
203
	/**
204
	 * Returns the item type
205
	 *
206
	 * @return string Item type, subtypes are separated by slashes
207
	 */
208
	public function getResourceType()
209
	{
210
		return 'locale/site';
211
	}
212
213
214
	/**
215
	 * Sets the item values from the given array.
216
	 *
217
	 * @param array $list Associative list of item keys and their values
218
	 * @return array Associative list of keys and their values that are unknown
219
	 */
220
	public function fromArray( array $list )
221
	{
222
		$unknown = [];
223
		$list = parent::fromArray( $list );
224
225
		foreach( $list as $key => $value )
226
		{
227
			switch( $key )
228
			{
229
				case 'locale.site.code': $this->setCode( $value ); break;
230
				case 'locale.site.label': $this->setLabel( $value ); break;
231
				case 'locale.site.config': $this->setConfig( $value ); break;
232
				case 'locale.site.status': $this->setStatus( $value ); break;
233
				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...
234
			}
235
		}
236
237
		return $unknown;
238
	}
239
240
241
	/**
242
	 * Returns the item values as array.
243
	 *
244
	 * @param boolean True to return private properties, false for public only
245
	 * @return array Associative list of item properties and their values
246
	 */
247
	public function toArray( $private = false )
248
	{
249
		$list = parent::toArray( $private );
250
251
		$list['locale.site.code'] = $this->getCode();
252
		$list['locale.site.label'] = $this->getLabel();
253
		$list['locale.site.config'] = $this->getConfig();
254
		$list['locale.site.status'] = $this->getStatus();
255
		$list['locale.site.hasChildren'] = $this->hasChildren();
256
257
		if( $private === true )
258
		{
259
			$list['locale.site.level'] = $this->getLevel();
260
			$list['locale.site.parentid'] = $this->getParentId();
261
		}
262
263
		return $list;
264
	}
265
266
267
	/**
268
	 * Returns a child of this node identified by its index.
269
	 *
270
	 * @param integer $index Index of child node
271
	 * @return \Aimeos\MShop\Locale\Item\Site\Iface Selected node
272
	 */
273
	public function getChild( $index )
274
	{
275
		throw new \Aimeos\MShop\Locale\Exception( sprintf( 'Child node with index "%1$d" not available', $index ) );
276
	}
277
278
279
	/**
280
	 * Returns all children of this node.
281
	 *
282
	 * @return array Numerically indexed list of nodes
283
	 */
284
	public function getChildren()
285
	{
286
		return [];
287
	}
288
289
290
	/**
291
	 * Tests if a node has children.
292
	 *
293
	 * @return boolean True if node has children, false if not
294
	 */
295
	public function hasChildren()
296
	{
297
		return false;
298
	}
299
300
301
	/**
302
	 * Adds a child node to this node.
303
	 *
304
	 * @param \Aimeos\MShop\Common\Item\Tree\Iface $item Child node to add
305
	 */
306
	public function addChild( \Aimeos\MShop\Common\Item\Tree\Iface $item )
307
	{
308
	}
309
}