This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
/
Default.php
241 lines (193 loc) · 5.28 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
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2012
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @package MShop
* @subpackage Coupon
*/
/**
* Default coupon item implementation.
*
* @package MShop
* @subpackage Coupon
*/
class MShop_Coupon_Item_Default
extends MShop_Common_Item_Abstract
implements MShop_Coupon_Item_Interface
{
private $_values;
/**
* Initializes the coupon item.
*
* @param array $values Optional; Associative array with id, label, provider,
* config and status to initialize the item properties
*/
public function __construct( array $values = array( ) )
{
parent::__construct( 'coupon.', $values );
$this->_values = $values;
}
/**
* Returns the label of the coupon item.
*
* @return string Name/label for this coupon
*/
public function getLabel()
{
return ( isset( $this->_values['label'] ) ? (string) $this->_values['label'] : '' );
}
/**
* Sets the label of the coupon item.
*
* @param string $name Coupon name, esp. short coupon class name
*/
public function setLabel( $name )
{
if( $name == $this->getLabel() ) { return; }
$this->_values['label'] = (string) $name;
$this->setModified();
}
/**
* Returns the starting point of time, in which the coupon is available.
*
* @return string ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function getDateStart()
{
return ( isset( $this->_values['start'] ) ? (string) $this->_values['start'] : null );
}
/**
* Sets a new starting point of time, in which the coupon is available.
*
* @param string New ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function setDateStart( $date )
{
if( $date == $this->getDateStart() ) { return; }
$this->_checkDateFormat( $date );
$this->_values['start'] = ( $date !== null ? (string) $date : null );
$this->setModified();
}
/**
* Returns the ending point of time, in which the coupon is available.
*
* @return string ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function getDateEnd()
{
return ( isset( $this->_values['end'] ) ? (string) $this->_values['end'] : null );
}
/**
* Sets a new ending point of time, in which the coupon is available.
*
* @param string New ISO date in YYYY-MM-DD hh:mm:ss format
*/
public function setDateEnd( $date )
{
if( $date == $this->getDateEnd() ) { return; }
$this->_checkDateFormat( $date );
$this->_values['end'] = ( $date !== null ? (string) $date : null );
$this->setModified();
}
/**
* Returns the name of the provider class to be used.
*
* @return string Returns the methode name to use
*/
public function getProvider()
{
return ( isset( $this->_values['provider'] ) ? (string) $this->_values['provider'] : '' );
}
/**
* Set the name of the provider class to be used.
*
* @param string $provider
*/
public function setProvider( $provider )
{
if( $provider == $this->getProvider() ) { return; }
$this->_values['provider'] = (string) $provider;
$this->setModified();
}
/**
* Returns the configuration of the coupon item.
*
* @return array Custom configuration values
*/
public function getConfig()
{
return ( isset( $this->_values['config'] ) && is_array( $this->_values['config'] ) ? (array) $this->_values['config'] : array() );
}
/**
* Sets the new configuration for the coupon item.
*
* @param array $config Custom configuration values
*/
public function setConfig( array $config )
{
if( $config == $this->getConfig() ) { return; }
$this->_values['config'] = $config;
$this->setModified();
}
/**
* Returns the status of the coupon item.
*
* @return integer Status of the item
*/
public function getStatus()
{
return ( isset( $this->_values['status'] ) ? (int) $this->_values['status'] : 0 );
}
/**
* Sets the new status of the coupon item.
*
* @param integer $status Status of the item
*/
public function setStatus( $status )
{
if( $status == $this->getStatus() ) { return; }
$this->_values['status'] = (int) $status;
$this->setModified();
}
/**
* 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 );
foreach( $list as $key => $value )
{
switch( $key )
{
case 'coupon.config': $this->setConfig( $value ); break;
case 'coupon.label': $this->setLabel( $value ); break;
case 'coupon.datestart': $this->setDateStart( $value ); break;
case 'coupon.dateend': $this->setDateEnd( $value ); break;
case 'coupon.provider': $this->setProvider( $value ); break;
case 'coupon.status': $this->setStatus( $value ); break;
default: $unknown[$key] = $value;
}
}
return $unknown;
}
/**
* Returns the item values as array.
*
* @return Associative list of item properties and their values
*/
public function toArray()
{
$list = parent::toArray();
$list['coupon.config'] = $this->getConfig();
$list['coupon.label'] = $this->getLabel();
$list['coupon.datestart'] = $this->getDateStart();
$list['coupon.dateend'] = $this->getDateEnd();
$list['coupon.provider'] = $this->getProvider();
$list['coupon.status'] = $this->getStatus();
return $list;
}
}