|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
7
|
|
|
* @package MShop |
|
8
|
|
|
* @subpackage Plugin |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Plugin\Item; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Default implementation of plugin items. |
|
17
|
|
|
* |
|
18
|
|
|
* @package MShop |
|
19
|
|
|
* @subpackage Plugin |
|
20
|
|
|
*/ |
|
21
|
|
|
class Standard |
|
22
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
|
23
|
|
|
implements \Aimeos\MShop\Plugin\Item\Iface |
|
24
|
|
|
{ |
|
25
|
|
|
use \Aimeos\MShop\Common\Item\Config\Traits; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns the type of the plugin. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string Plugin type |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getType() : string |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->get( 'plugin.type', 'order' ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Sets the new type of the plugin item. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $type New plugin type |
|
43
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->set( 'plugin.type', $this->checkCode( $type ) ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns the provider of the plugin. |
|
53
|
|
|
* |
|
54
|
|
|
* @return string Plugin provider which is the short plugin class name |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getProvider() : string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->get( 'plugin.provider', '' ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sets the new provider of the plugin item which is the short |
|
64
|
|
|
* name of the plugin class name. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $provider Plugin provider, esp. short plugin class name |
|
67
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setProvider( string $provider ) : \Aimeos\MShop\Plugin\Item\Iface |
|
70
|
|
|
{ |
|
71
|
|
|
if( preg_match( '/^[A-Za-z0-9]+(,[A-Za-z0-9]+)*$/', $provider ) !== 1 ) { |
|
72
|
|
|
throw new \Aimeos\MShop\Plugin\Exception( sprintf( 'Invalid provider name "%1$s"', $provider ) ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->set( 'plugin.provider', $provider ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Returns the name of the plugin item. |
|
81
|
|
|
* |
|
82
|
|
|
* @return string Label of the plugin item |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getLabel() : string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->get( 'plugin.label', '' ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Sets the new label of the plugin item. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $label New label of the plugin item |
|
94
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setLabel( string $label ) : \Aimeos\MShop\Plugin\Item\Iface |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->set( 'plugin.label', $label ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the configuration of the plugin item. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array Custom configuration values |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getConfig() : array |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->get( 'plugin.config', [] ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Sets the new configuration for the plugin item. |
|
115
|
|
|
* |
|
116
|
|
|
* @param array $config Custom configuration values |
|
117
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setConfig( array $config ) : \Aimeos\MShop\Common\Item\Iface |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->set( 'plugin.config', $config ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Returns the position of the plugin item. |
|
127
|
|
|
* |
|
128
|
|
|
* @return int Position of the item |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getPosition() : int |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->get( 'plugin.position', 0 ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Sets the new position of the plugin item. |
|
138
|
|
|
* |
|
139
|
|
|
* @param int $position Position of the item |
|
140
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setPosition( int $position ) : \Aimeos\MShop\Common\Item\Iface |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->set( 'plugin.position', $position ); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Returns the status of the plugin item. |
|
150
|
|
|
* |
|
151
|
|
|
* @return int Status of the item |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getStatus() : int |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->get( 'plugin.status', 1 ); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Sets the new status of the plugin item. |
|
161
|
|
|
* |
|
162
|
|
|
* @param int $status Status of the item |
|
163
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->set( 'plugin.status', $status ); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Tests if the item is available based on status, time, language and currency |
|
173
|
|
|
* |
|
174
|
|
|
* @return bool True if available, false if not |
|
175
|
|
|
*/ |
|
176
|
|
|
public function isAvailable() : bool |
|
177
|
|
|
{ |
|
178
|
|
|
return parent::isAvailable() && $this->getStatus() > 0; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
184
|
|
|
* |
|
185
|
|
|
* @param array &$list Associative list of item keys and their values |
|
186
|
|
|
* @param bool True to set private properties too, false for public only |
|
187
|
|
|
* @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
|
188
|
|
|
*/ |
|
189
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
190
|
|
|
{ |
|
191
|
|
|
$item = parent::fromArray( $list, $private ); |
|
192
|
|
|
|
|
193
|
|
|
foreach( $list as $key => $value ) |
|
194
|
|
|
{ |
|
195
|
|
|
switch( $key ) |
|
196
|
|
|
{ |
|
197
|
|
|
case 'plugin.type': $item = $item->setType( $value ); break; |
|
198
|
|
|
case 'plugin.label': $item = $item->setLabel( $value ); break; |
|
199
|
|
|
case 'plugin.provider': $item = $item->setProvider( $value ); break; |
|
200
|
|
|
case 'plugin.status': $item = $item->setStatus( (int) $value ); break; |
|
201
|
|
|
case 'plugin.config': $item = $item->setConfig( (array) $value ); break; |
|
202
|
|
|
case 'plugin.position': $item = $item->setPosition( (int) $value ); break; |
|
203
|
|
|
default: continue 2; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
unset( $list[$key] ); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return $item; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Returns the item values as array. |
|
215
|
|
|
* |
|
216
|
|
|
* @param bool True to return private properties, false for public only |
|
217
|
|
|
* @return array Associative list of item properties and their values |
|
218
|
|
|
*/ |
|
219
|
|
|
public function toArray( bool $private = false ) : array |
|
220
|
|
|
{ |
|
221
|
|
|
$list = parent::toArray( $private ); |
|
222
|
|
|
|
|
223
|
|
|
$list['plugin.type'] = $this->getType(); |
|
224
|
|
|
$list['plugin.label'] = $this->getLabel(); |
|
225
|
|
|
$list['plugin.provider'] = $this->getProvider(); |
|
226
|
|
|
$list['plugin.config'] = $this->getConfig(); |
|
227
|
|
|
$list['plugin.status'] = $this->getStatus(); |
|
228
|
|
|
$list['plugin.position'] = $this->getPosition(); |
|
229
|
|
|
|
|
230
|
|
|
return $list; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
|