Passed
Push — master ( 411768...2359f2 )
by Aimeos
02:19
created

Base::property()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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