Passed
Push — master ( c4e37e...d53723 )
by Aimeos
02:45
created

Base   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 373
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 26
eloc 51
c 0
b 0
f 0
dl 0
loc 373
rs 10

26 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 3 1
A aggregate() 0 3 1
A get() 0 3 1
A parse() 0 4 1
A compare() 0 4 1
A product() 0 4 1
A __call() 0 3 1
A oneOf() 0 4 1
A category() 0 4 1
A allOf() 0 4 1
A property() 0 4 1
A function() 0 3 1
A price() 0 4 1
A __construct() 0 6 1
A __clone() 0 3 1
A has() 0 4 1
A search() 0 3 1
A setObject() 0 7 1
A radius() 0 4 1
A slice() 0 4 1
A supplier() 0 4 1
A getController() 0 3 1
A text() 0 4 1
A uses() 0 4 1
A resolve() 0 3 1
A sort() 0 4 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2022
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Product\Decorator;
12
13
14
/**
15
 * Base for product 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\Product\Iface
23
{
24
	use \Aimeos\Controller\Frontend\Common\Decorator\Traits;
25
26
27
	private $controller;
28
29
30
	/**
31
	 * Initializes the controller decorator.
32
	 *
33
	 * @param \Aimeos\Controller\Frontend\Iface $controller Controller object
34
	 * @param \Aimeos\MShop\ContextIface $context Context object with required objects
35
	 */
36
	public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\ContextIface $context )
37
	{
38
		parent::__construct( $context );
39
40
		$iface = \Aimeos\Controller\Frontend\Product\Iface::class;
41
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
42
	}
43
44
45
	/**
46
	 * Clones objects in decorator
47
	 */
48
	public function __clone()
49
	{
50
		$this->controller = clone $this->controller;
51
	}
52
53
54
	/**
55
	 * Passes unknown methods to wrapped objects.
56
	 *
57
	 * @param string $name Name of the method
58
	 * @param array $param List of method parameter
59
	 * @return mixed Returns the value of the called method
60
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
61
	 */
62
	public function __call( string $name, array $param )
63
	{
64
		return @call_user_func_array( array( $this->controller, $name ), $param );
65
	}
66
67
68
	/**
69
	 * Returns the aggregated count of products for the given key.
70
	 *
71
	 * @param string $key Search key to aggregate for, e.g. "index.attribute.id"
72
	 * @param string|null $value Search key for aggregating the value column
73
	 * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average)
74
	 * @return \Aimeos\Map Associative list of key values as key and the product count for this key as value
75
	 * @since 2019.04
76
	 */
77
	public function aggregate( string $key, string $value = null, string $type = null ) : \Aimeos\Map
78
	{
79
		return $this->controller->aggregate( $key, $value, $type );
80
	}
81
82
83
	/**
84
	 * Adds attribute IDs for filtering where products must reference all IDs
85
	 *
86
	 * @param array|string $attrIds Attribute ID or list of IDs
87
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
88
	 * @since 2019.04
89
	 */
90
	public function allOf( $attrIds ) : \Aimeos\Controller\Frontend\Product\Iface
91
	{
92
		$this->controller->allOf( $attrIds );
93
		return $this;
94
	}
95
96
97
	/**
98
	 * Adds catalog IDs for filtering
99
	 *
100
	 * @param array|string $catIds Catalog ID or list of IDs
101
	 * @param string $listtype List type of the products referenced by the categories
102
	 * @param int $level Constant from \Aimeos\MW\Tree\Manager\Base if products in subcategories are matched too
103
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
104
	 * @since 2019.04
105
	 */
106
	public function category( $catIds, string $listtype = 'default', int $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ) : \Aimeos\Controller\Frontend\Product\Iface
107
	{
108
		$this->controller->category( $catIds, $listtype, $level );
109
		return $this;
110
	}
111
112
113
	/**
114
	 * Adds generic condition for filtering products
115
	 *
116
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
117
	 * @param string $key Search key defined by the product manager, e.g. "product.status"
118
	 * @param array|string $value Value or list of values to compare to
119
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
120
	 * @since 2019.04
121
	 */
122
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Product\Iface
123
	{
124
		$this->controller->compare( $operator, $key, $value );
125
		return $this;
126
	}
127
128
129
	/**
130
	 * Returns the product for the given product code
131
	 *
132
	 * @param string $code Unique product code
133
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
134
	 * @since 2019.04
135
	 */
136
	public function find( string $code ) : \Aimeos\MShop\Product\Item\Iface
137
	{
138
		return $this->controller->find( $code );
139
	}
140
141
142
	/**
143
	 * Creates a search function string for the given name and parameters
144
	 *
145
	 * @param string $name Name of the search function without parenthesis, e.g. "product:has"
146
	 * @param array $params List of parameters for the search function with numeric keys starting at 0
147
	 * @return string Search function string that can be used in compare()
148
	 */
149
	public function function( string $name, array $params ) : string
150
	{
151
		return $this->controller->function( $name, $params );
152
	}
153
154
155
	/**
156
	 * Returns the product for the given product ID
157
	 *
158
	 * @param string $id Unique product ID
159
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
160
	 * @since 2019.04
161
	 */
162
	public function get( string $id ) : \Aimeos\MShop\Product\Item\Iface
163
	{
164
		return $this->controller->get( $id );
165
	}
166
167
168
	/**
169
	 * Adds a filter to return only items containing a reference to the given ID
170
	 *
171
	 * @param string $domain Domain name of the referenced item, e.g. "attribute"
172
	 * @param string|null $type Type code of the reference, e.g. "variant" or null for all types
173
	 * @param string|null $refId ID of the referenced item of the given domain or null for all references
174
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
175
	 * @since 2019.04
176
	 */
177
	public function has( string $domain, string $type = null, string $refId = null ) : \Aimeos\Controller\Frontend\Product\Iface
178
	{
179
		$this->controller->has( $domain, $type, $refId );
180
		return $this;
181
	}
182
183
184
	/**
185
	 * Adds attribute IDs for filtering where products must reference at least one ID
186
	 *
187
	 * @param array|string $attrIds Attribute ID or list of IDs
188
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
189
	 * @since 2019.04
190
	 */
191
	public function oneOf( $attrIds ) : \Aimeos\Controller\Frontend\Product\Iface
192
	{
193
		$this->controller->oneOf( $attrIds );
194
		return $this;
195
	}
196
197
198
	/**
199
	 * Parses the given array and adds the conditions to the list of conditions
200
	 *
201
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]]
202
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
203
	 * @since 2019.04
204
	 */
205
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Product\Iface
206
	{
207
		$this->controller->parse( $conditions );
208
		return $this;
209
	}
210
211
212
	/**
213
	 * Adds price restrictions for filtering
214
	 *
215
	 * @param array|string|null $value Upper price limit, list of lower and upper price or NULL for no restrictions
216
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
217
	 * @since 2020.10
218
	 */
219
	public function price( $value = null ) : \Aimeos\Controller\Frontend\Product\Iface
220
	{
221
		$this->controller->price( $value );
222
		return $this;
223
	}
224
225
226
	/**
227
	 * Adds product IDs for filtering
228
	 *
229
	 * @param array|string $prodIds Product ID or list of IDs
230
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
231
	 * @since 2019.04
232
	 */
233
	public function product( $prodIds ) : \Aimeos\Controller\Frontend\Product\Iface
234
	{
235
		$this->controller->product( $prodIds );
236
		return $this;
237
	}
238
239
240
	/**
241
	 * Adds a filter to return only items containing the property
242
	 *
243
	 * @param string $type Type code of the property, e.g. "isbn"
244
	 * @param string|null $value Exact value of the property
245
	 * @param string|null $langId ISO country code (en or en_US) or null if not language specific
246
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
247
	 * @since 2019.04
248
	 */
249
	public function property( string $type, string $value = null, string $langId = null ) : \Aimeos\Controller\Frontend\Product\Iface
250
	{
251
		$this->controller->property( $type, $value, $langId );
252
		return $this;
253
	}
254
255
256
	/**
257
	 * Adds radius restrictions for filtering
258
	 *
259
	 * @param array $latlon Latitude and longitude value or empty for no restrictions
260
	 * @param float|null $dist Distance around latitude/longitude or NULL for no restrictions
261
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
262
	 * @since 2021.10
263
	 */
264
	public function radius( array $latlon, float $dist = null ) : \Aimeos\Controller\Frontend\Product\Iface
265
	{
266
		$this->controller->radius( $latlon, $dist );
267
		return $this;
268
	}
269
270
271
	/**
272
	 * Returns the product for the given product URL name
273
	 *
274
	 * @param string $name Product URL name
275
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
276
	 * @since 2019.04
277
	 */
278
	public function resolve( string $name ) : \Aimeos\MShop\Product\Item\Iface
279
	{
280
		return $this->controller->resolve( $name );
281
	}
282
283
284
	/**
285
	 * Returns the products filtered by the previously assigned conditions
286
	 *
287
	 * @param int &$total Parameter where the total number of found products will be stored in
288
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Product\Item\Iface
289
	 * @since 2019.04
290
	 */
291
	public function search( int &$total = null ) : \Aimeos\Map
292
	{
293
		return $this->controller->search( $total );
294
	}
295
296
297
	/**
298
	 * Sets the start value and the number of returned products for slicing the list of found products
299
	 *
300
	 * @param int $start Start value of the first product in the list
301
	 * @param int $limit Number of returned products
302
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
303
	 * @since 2019.04
304
	 */
305
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Product\Iface
306
	{
307
		$this->controller->slice( $start, $limit );
308
		return $this;
309
	}
310
311
312
	/**
313
	 * Sets the sorting of the result list
314
	 *
315
	 * @param string|null $key Sorting of the result list like "name", "-name", "price", "-price", "code", "-code", "ctime, "-ctime" and "relevance", null for no sorting
316
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
317
	 * @since 2019.04
318
	 */
319
	public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Product\Iface
320
	{
321
		$this->controller->sort( $key );
322
		return $this;
323
	}
324
325
326
	/**
327
	 * Adds supplier IDs for filtering
328
	 *
329
	 * @param array|string $supIds Supplier ID or list of IDs
330
	 * @param string $listtype List type of the products referenced by the suppliers
331
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
332
	 * @since 2019.04
333
	 */
334
	public function supplier( $supIds, string $listtype = 'default' ) : \Aimeos\Controller\Frontend\Product\Iface
335
	{
336
		$this->controller->supplier( $supIds, $listtype );
337
		return $this;
338
	}
339
340
341
	/**
342
	 * Adds input string for full text search
343
	 *
344
	 * @param string|null $text User input for full text search
345
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
346
	 * @since 2019.04
347
	 */
348
	public function text( string $text = null ) : \Aimeos\Controller\Frontend\Product\Iface
349
	{
350
		$this->controller->text( $text );
351
		return $this;
352
	}
353
354
355
	/**
356
	 * Sets the referenced domains that will be fetched too when retrieving items
357
	 *
358
	 * @param array $domains Domain names of the referenced items that should be fetched too
359
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
360
	 * @since 2019.04
361
	 */
362
	public function uses( array $domains ) : \Aimeos\Controller\Frontend\Product\Iface
363
	{
364
		$this->controller->uses( $domains );
365
		return $this;
366
	}
367
368
369
	/**
370
	 * Injects the reference of the outmost object
371
	 *
372
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
373
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
374
	 */
375
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
376
	{
377
		parent::setObject( $object );
378
379
		$this->controller->setObject( $object );
380
381
		return $this;
382
	}
383
384
385
	/**
386
	 * Returns the frontend controller
387
	 *
388
	 * @return \Aimeos\Controller\Frontend\Iface Frontend controller object
389
	 */
390
	protected function getController() : \Aimeos\Controller\Frontend\Iface
391
	{
392
		return $this->controller;
393
	}
394
}
395