Completed
Push — master ( 027b78...4ee65e )
by Aimeos
07:42
created

Standard::setDateStart()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
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-2016
7
 * @package MShop
8
 * @subpackage Service
9
 */
10
11
12
namespace Aimeos\MShop\Service\Item;
13
14
15
/**
16
 * Service item with common methods.
17
 *
18
 * @package MShop
19
 * @subpackage Service
20
 */
21
class Standard
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\Service\Item\Iface
24
{
25
	private $values;
26
27
	/**
28
	 * Initializes the item object.
29
	 *
30
	 * @param array $values Parameter for initializing the basic properties
31
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
32
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
33
	 */
34
	public function __construct( array $values = [], array $listItems = [], array $refItems = [] )
35
	{
36
		parent::__construct( 'service.', $values, $listItems, $refItems );
37
38
		$this->values = $values;
39
	}
40
41
42
	/**
43
	 * Returns the code of the service item payment if available.
44
	 *
45
	 * @return string Service item code
46
	 */
47
	public function getCode()
48
	{
49
		if( isset( $this->values['service.code'] ) ) {
50
			return (string) $this->values['service.code'];
51
		}
52
53
		return '';
54
	}
55
56
57
	/**
58
	 * Sets the code of the service item payment.
59
	 *
60
	 * @param string code of the service item payment
61
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
62
	 */
63
	public function setCode( $code )
64
	{
65
		if( $code == $this->getCode() ) { return $this; }
66
67
		$this->values['service.code'] = (string) $this->checkCode( $code );;
68
		$this->setModified();
69
70
		return $this;
71
	}
72
73
74
	/**
75
	 * Returns the type of the service item if available.
76
	 *
77
	 * @return string|null Service item type
78
	 */
79
	public function getType()
80
	{
81
		if( isset( $this->values['service.type'] ) ) {
82
			return (string) $this->values['service.type'];
83
		}
84
85
		return null;
86
	}
87
88
89
	/**
90
	 * Returns the localized name of the type
91
	 *
92
	 * @return string|null Localized name of the type
93
	 */
94
	public function getTypeName()
95
	{
96
		if( isset( $this->values['service.typename'] ) ) {
97
			return (string) $this->values['service.typename'];
98
		}
99
100
		return null;
101
	}
102
103
104
	/**
105
	 * Returns the type ID of the service item if available.
106
	 *
107
	 * @return integer|null Service item type ID
108
	 */
109
	public function getTypeId()
110
	{
111
		if( isset( $this->values['service.typeid'] ) ) {
112
			return (int) $this->values['service.typeid'];
113
		}
114
115
		return null;
116
	}
117
118
119
	/**
120
	 * Sets the type ID of the service item.
121
	 *
122
	 * @param integer Type ID of the service item
123
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
124
	 */
125
	public function setTypeId( $typeId )
126
	{
127
		if( $typeId == $this->getTypeId() ) { return $this; }
128
129
		$this->values['service.typeid'] = (int) $typeId;
130
		$this->setModified();
131
132
		return $this;
133
	}
134
135
136
	/**
137
	 * Returns the name of the service provider the item belongs to.
138
	 *
139
	 * @return string Name of the service provider
140
	 */
141
	public function getProvider()
142
	{
143
		if( isset( $this->values['service.provider'] ) ) {
144
			return (string) $this->values['service.provider'];
145
		}
146
147
		return '';
148
	}
149
150
151
	/**
152
	 * Sets the new name of the service provider the item belongs to.
153
	 *
154
	 * @param string $provider Name of the service provider
155
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
156
	 */
157
	public function setProvider( $provider )
158
	{
159
		if( $provider == $this->getProvider() ) { return $this; }
160
161
		$this->values['service.provider'] = (string) $provider;
162
		$this->setModified();
163
164
		return $this;
165
	}
166
167
168
	/**
169
	 * Returns the label of the service item payment if available.
170
	 *
171
	 * @return string Service item label
172
	 */
173
	public function getLabel()
174
	{
175
		if( isset( $this->values['service.label'] ) ) {
176
			return (string) $this->values['service.label'];
177
		}
178
179
		return '';
180
	}
181
182
183
	/**
184
	 * Sets the label of the service item payment.
185
	 *
186
	 * @param string label of the service item payment
187
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
188
	 */
189
	public function setLabel( $label )
190
	{
191
		if( $label == $this->getLabel() ) { return $this; }
192
193
		$this->values['service.label'] = (string) $label;
194
		$this->setModified();
195
196
		return $this;
197
	}
198
199
200
	/**
201
	 * Returns the starting point of time, in which the service is available.
202
	 *
203
	 * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format
204
	 */
205
	public function getDateStart()
206
	{
207
		if( isset( $this->values['service.datestart'] ) ) {
208
			return (string) $this->values['service.datestart'];
209
		}
210
211
		return null;
212
	}
213
214
215
	/**
216
	 * Sets a new starting point of time, in which the service is available.
217
	 *
218
	 * @param string|null New ISO date in YYYY-MM-DD hh:mm:ss format
219
	 * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls
0 ignored issues
show
Documentation introduced by
Should the return type not be Standard?

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...
220
	 */
221
	public function setDateStart( $date )
222
	{
223
		if( $date === $this->getDateStart() ) { return $this; }
224
225
		$this->values['service.datestart'] = $this->checkDateFormat( $date );
226
		$this->setModified();
227
228
		return $this;
229
	}
230
231
232
	/**
233
	 * Returns the ending point of time, in which the service is available.
234
	 *
235
	 * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format
236
	 */
237
	public function getDateEnd()
238
	{
239
		if( isset( $this->values['service.dateend'] ) ) {
240
			return (string) $this->values['service.dateend'];
241
		}
242
243
		return null;
244
	}
245
246
247
	/**
248
	 * Sets a new ending point of time, in which the service is available.
249
	 *
250
	 * @param string|null New ISO date in YYYY-MM-DD hh:mm:ss format
251
	 * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls
0 ignored issues
show
Documentation introduced by
Should the return type not be Standard?

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...
252
	 */
253
	public function setDateEnd( $date )
254
	{
255
		if( $date === $this->getDateEnd() ) { return $this; }
256
257
		$this->values['service.dateend'] = $this->checkDateFormat( $date );
258
		$this->setModified();
259
260
		return $this;
261
	}
262
263
264
	/**
265
	 * Returns the configuration values of the item
266
	 *
267
	 * @return array Configuration values
268
	 */
269
	public function getConfig()
270
	{
271
		if( isset( $this->values['service.config'] ) ) {
272
			return (array) $this->values['service.config'];
273
		}
274
275
		return [];
276
	}
277
278
279
	/**
280
	 * Sets the configuration values of the item.
281
	 *
282
	 * @param array $config Configuration values
283
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
284
	 */
285
	public function setConfig( array $config )
286
	{
287
		$this->values['service.config'] = $config;
288
		$this->setModified();
289
290
		return $this;
291
	}
292
293
294
	/**
295
	 * Returns the position of the service item in the list of deliveries.
296
	 *
297
	 * @return integer Position in item list
298
	 */
299
	public function getPosition()
300
	{
301
		if( isset( $this->values['service.position'] ) ) {
302
			return (int) $this->values['service.position'];
303
		}
304
305
		return 0;
306
	}
307
308
309
	/**
310
	 * Sets the new position of the service item in the list of deliveries.
311
	 *
312
	 * @param integer $pos Position in item list
313
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
314
	 */
315
	public function setPosition( $pos )
316
	{
317
		if( $pos == $this->getPosition() ) { return $this; }
318
319
		$this->values['service.position'] = (int) $pos;
320
		$this->setModified();
321
322
		return $this;
323
	}
324
325
326
	/**
327
	 * Returns the status of the item.
328
	 *
329
	 * @return integer Status of the item
330
	 */
331
	public function getStatus()
332
	{
333
		if( isset( $this->values['service.status'] ) ) {
334
			return (int) $this->values['service.status'];
335
		}
336
337
		return 0;
338
	}
339
340
341
	/**
342
	 * Sets the status of the item.
343
	 *
344
	 * @param integer $status Status of the item
345
	 * @return \Aimeos\MShop\Service\Item\Iface Service item for chaining method calls
346
	 */
347
	public function setStatus( $status )
348
	{
349
		if( $status == $this->getStatus() ) { return $this; }
350
351
		$this->values['service.status'] = (int) $status;
352
		$this->setModified();
353
354
		return $this;
355
	}
356
357
358
	/**
359
	 * Returns the item type
360
	 *
361
	 * @return string Item type, subtypes are separated by slashes
362
	 */
363
	public function getResourceType()
364
	{
365
		return 'service';
366
	}
367
368
369
	/**
370
	 * Sets the item values from the given array.
371
	 *
372
	 * @param array $list Associative list of item keys and their values
373
	 * @return array Associative list of keys and their values that are unknown
374
	 */
375
	public function fromArray( array $list )
376
	{
377
		$unknown = [];
378
		$list = parent::fromArray( $list );
379
		unset( $list['service.type'], $list['service.typename'] );
380
381
		foreach( $list as $key => $value )
382
		{
383
			switch( $key )
384
			{
385
				case 'service.typeid': $this->setTypeId( $value ); break;
386
				case 'service.code': $this->setCode( $value ); break;
387
				case 'service.label': $this->setLabel( $value ); break;
388
				case 'service.provider': $this->setProvider( $value ); break;
389
				case 'service.position': $this->setPosition( $value ); break;
390
				case 'service.datestart': $this->setDateStart( $value ); break;
391
				case 'service.dateend': $this->setDateEnd( $value ); break;
392
				case 'service.config': $this->setConfig( $value ); break;
393
				case 'service.status': $this->setStatus( $value ); break;
394
				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...
395
			}
396
		}
397
398
		return $unknown;
399
	}
400
401
402
	/**
403
	 * Returns the item values as array.
404
	 *
405
	 * @param boolean True to return private properties, false for public only
406
	 * @return array Associative list of item properties and their values
407
	 */
408
	public function toArray( $private = false )
409
	{
410
		$list = parent::toArray( $private );
411
412
		$list['service.typename'] = $this->getTypeName();
413
		$list['service.type'] = $this->getType();
414
		$list['service.code'] = $this->getCode();
415
		$list['service.label'] = $this->getLabel();
416
		$list['service.provider'] = $this->getProvider();
417
		$list['service.position'] = $this->getPosition();
418
		$list['service.datestart'] = $this->getDateStart();
419
		$list['service.dateend'] = $this->getDateEnd();
420
		$list['service.config'] = $this->getConfig();
421
		$list['service.status'] = $this->getStatus();
422
423
		if( $private === true ) {
424
			$list['service.typeid'] = $this->getTypeId();
425
		}
426
427
		return $list;
428
	}
429
430
}
431