1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Attribute\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for attribute frontend controller decorators |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
abstract class Base |
21
|
|
|
extends \Aimeos\Controller\Frontend\Base |
22
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Attribute\Iface |
23
|
|
|
{ |
24
|
|
|
private $controller; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the controller decorator. |
29
|
|
|
* |
30
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
31
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
32
|
|
|
*/ |
33
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
34
|
|
|
{ |
35
|
|
|
parent::__construct( $context ); |
36
|
|
|
|
37
|
|
|
$iface = \Aimeos\Controller\Frontend\Attribute\Iface::class; |
38
|
|
|
$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Passes unknown methods to wrapped objects. |
44
|
|
|
* |
45
|
|
|
* @param string $name Name of the method |
46
|
|
|
* @param array $param List of method parameter |
47
|
|
|
* @return mixed Returns the value of the called method |
48
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
49
|
|
|
*/ |
50
|
|
|
public function __call( $name, array $param ) |
51
|
|
|
{ |
52
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Clones objects in controller and resets values |
58
|
|
|
*/ |
59
|
|
|
public function __clone() |
60
|
|
|
{ |
61
|
|
|
$this->controller = clone $this->controller; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Adds attribute IDs for filtering |
67
|
|
|
* |
68
|
|
|
* @param array|string $attrIds Attribute ID or list of IDs |
69
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
70
|
|
|
* @since 2019.04 |
71
|
|
|
*/ |
72
|
|
|
public function attribute( $attrIds ) |
73
|
|
|
{ |
74
|
|
|
$this->controller->attribute( $attrIds ); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Adds generic condition for filtering attributes |
81
|
|
|
* |
82
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
83
|
|
|
* @param string $key Search key defined by the attribute manager, e.g. "attribute.status" |
84
|
|
|
* @param array|string $value Value or list of values to compare to |
85
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
86
|
|
|
* @since 2019.04 |
87
|
|
|
*/ |
88
|
|
|
public function compare( $operator, $key, $value ) |
89
|
|
|
{ |
90
|
|
|
$this->controller->compare( $operator, $key, $value ); |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Adds the domain of the attributes for filtering |
97
|
|
|
* |
98
|
|
|
* @param string $domain Domain of the attributes |
99
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
100
|
|
|
* @since 2019.04 |
101
|
|
|
*/ |
102
|
|
|
public function domain( $domain ) |
103
|
|
|
{ |
104
|
|
|
$this->controller->domain( $domain ); |
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the attribute for the given attribute code |
111
|
|
|
* |
112
|
|
|
* @param string $code Unique attribute code |
113
|
|
|
* @param string $type Type assigned to the attribute |
114
|
|
|
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items |
115
|
|
|
* @since 2019.04 |
116
|
|
|
*/ |
117
|
|
|
public function find( $code, $type ) |
118
|
|
|
{ |
119
|
|
|
return $this->controller->find( $code, $type ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns the attribute for the given attribute ID |
125
|
|
|
* |
126
|
|
|
* @param string $id Unique attribute ID |
127
|
|
|
* @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items |
128
|
|
|
* @since 2019.04 |
129
|
|
|
*/ |
130
|
|
|
public function get( $id ) |
131
|
|
|
{ |
132
|
|
|
return $this->controller->get( $id ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Adds a filter to return only items containing a reference to the given ID |
138
|
|
|
* |
139
|
|
|
* @param string $domain Domain name of the referenced item, e.g. "price" |
140
|
|
|
* @param string|null $type Type code of the reference, e.g. "default" or null for all types |
141
|
|
|
* @param string|null $refId ID of the referenced item of the given domain or null for all references |
142
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
143
|
|
|
* @since 2019.04 |
144
|
|
|
*/ |
145
|
|
|
public function has( $domain, $type = null, $refId = null ) |
146
|
|
|
{ |
147
|
|
|
$this->controller->has( $domain, $type, $refId ); |
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
154
|
|
|
* |
155
|
|
|
* @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]] |
156
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
157
|
|
|
* @since 2019.04 |
158
|
|
|
*/ |
159
|
|
|
public function parse( array $conditions ) |
160
|
|
|
{ |
161
|
|
|
$this->controller->parse( $conditions ); |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Adds a filter to return only items containing the property |
168
|
|
|
* |
169
|
|
|
* @param string $type Type code of the property, e.g. "htmlcolor" |
170
|
|
|
* @param string|null $value Exact value of the property |
171
|
|
|
* @param string|null $langId ISO country code (en or en_US) or null if not language specific |
172
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
173
|
|
|
* @since 2019.04 |
174
|
|
|
*/ |
175
|
|
|
public function property( $type, $value = null, $langId = null ) |
176
|
|
|
{ |
177
|
|
|
$this->controller->property( $type, $value, $langId ); |
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Returns the attributes filtered by the previously assigned conditions |
184
|
|
|
* |
185
|
|
|
* @param integer &$total Parameter where the total number of found attributes will be stored in |
186
|
|
|
* @return \Aimeos\MShop\Attribute\Item\Iface[] Ordered list of attribute items |
187
|
|
|
* @since 2019.04 |
188
|
|
|
*/ |
189
|
|
|
public function search( &$total = null ) |
190
|
|
|
{ |
191
|
|
|
return $this->controller->search( $total ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Sets the start value and the number of returned attributes for slicing the list of found attributes |
197
|
|
|
* |
198
|
|
|
* @param integer $start Start value of the first attribute in the list |
199
|
|
|
* @param integer $limit Number of returned attributes |
200
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
201
|
|
|
* @since 2019.04 |
202
|
|
|
*/ |
203
|
|
|
public function slice( $start, $limit ) |
204
|
|
|
{ |
205
|
|
|
$this->controller->slice( $start, $limit ); |
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Sets the sorting of the result list |
212
|
|
|
* |
213
|
|
|
* @param string|null $key Sorting of the result list like "position", null for no sorting |
214
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
215
|
|
|
* @since 2019.04 |
216
|
|
|
*/ |
217
|
|
|
public function sort( $key = null ) |
218
|
|
|
{ |
219
|
|
|
$this->controller->sort( $key ); |
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Adds attribute types for filtering |
226
|
|
|
* |
227
|
|
|
* @param array|string $codes Attribute ID or list of IDs |
228
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
229
|
|
|
* @since 2019.04 |
230
|
|
|
*/ |
231
|
|
|
public function type( $codes ) |
232
|
|
|
{ |
233
|
|
|
$this->controller->type( $codes ); |
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
240
|
|
|
* |
241
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
242
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface |
243
|
|
|
* @since 2019.04 |
244
|
|
|
*/ |
245
|
|
|
public function uses( array $domains ) |
246
|
|
|
{ |
247
|
|
|
$this->controller->uses( $domains ); |
248
|
|
|
return $this; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Injects the reference of the outmost object |
254
|
|
|
* |
255
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
256
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
257
|
|
|
*/ |
258
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) |
259
|
|
|
{ |
260
|
|
|
parent::setObject( $object ); |
261
|
|
|
|
262
|
|
|
$this->controller->setObject( $object ); |
263
|
|
|
|
264
|
|
|
return $this; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Returns the frontend controller |
270
|
|
|
* |
271
|
|
|
* @return \Aimeos\Controller\Frontend\Attribute\Iface Frontend controller object |
272
|
|
|
*/ |
273
|
|
|
protected function getController() |
274
|
|
|
{ |
275
|
|
|
return $this->controller; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|