Passed
Push — master ( 6cf50b...92e939 )
by Aimeos
01:45
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
		$iface = \Aimeos\Controller\Frontend\Product\Iface::class;
36
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
37
38
		parent::__construct( $context );
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( $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( $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 )
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 integer $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, $listtype = 'default', $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE )
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( $operator, $key, $value )
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
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
129
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
130
	 * @since 2019.04
131
	 */
132
	public function find( $code, $domains = ['media', 'price', 'text'] )
133
	{
134
		return $this->controller->find( $code, $domains );
135
	}
136
137
138
	/**
139
	 * Returns the product for the given product ID
140
	 *
141
	 * @param string $id Unique product ID
142
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
143
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
144
	 * @since 2019.04
145
	 */
146
	public function get( $id, $domains = ['media', 'price', 'text'] )
147
	{
148
		return $this->controller->get( $id, $domains );
149
	}
150
151
152
	/**
153
	 * Adds a filter to return only items containing a reference to the given ID
154
	 *
155
	 * @param string $domain Domain name of the referenced item, e.g. "attribute"
156
	 * @param string|null $type Type code of the reference, e.g. "variant" or null for all types
157
	 * @param string|null $refId ID of the referenced item of the given domain or null for all references
158
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
159
	 * @since 2019.04
160
	 */
161
	public function has( $domain, $type = null, $refId = null )
162
	{
163
		return $this->controller->has( $domain, $type, $refId );
164
	}
165
166
167
	/**
168
	 * Adds attribute IDs for filtering where products must reference at least one ID
169
	 *
170
	 * @param array|string $attrIds Attribute ID or list of IDs
171
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
172
	 * @since 2019.04
173
	 */
174
	public function oneOf( $attrIds )
175
	{
176
		$this->controller->oneOf( $attrIds );
177
		return $this;
178
	}
179
180
181
	/**
182
	 * Parses the given array and adds the conditions to the list of conditions
183
	 *
184
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]]
185
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
186
	 * @since 2019.04
187
	 */
188
	public function parse( array $conditions )
189
	{
190
		$this->controller->parse( $conditions );
191
		return $this;
192
	}
193
194
195
	/**
196
	 * Adds product IDs for filtering
197
	 *
198
	 * @param array|string $prodIds Product ID or list of IDs
199
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
200
	 * @since 2019.04
201
	 */
202
	public function product( $prodIds )
203
	{
204
		$this->controller->product( $prodIds );
205
		return $this;
206
	}
207
208
209
	/**
210
	 * Adds a filter to return only items containing the property
211
	 *
212
	 * @param string $type Type code of the property, e.g. "isbn"
213
	 * @param string|null $value Exact value of the property
214
	 * @param string|null $langId ISO country code (en or en_US) or null if not language specific
215
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
216
	 * @since 2019.04
217
	 */
218
	public function property( $type, $value = null, $langId = null )
219
	{
220
		$this->controller->property( $type, $value, $langId );
221
		return $this;
222
	}
223
224
225
	/**
226
	 * Returns the products filtered by the previously assigned conditions
227
	 *
228
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
229
	 * @param integer &$total Parameter where the total number of found products will be stored in
230
	 * @return \Aimeos\MShop\Product\Item\Iface[] Ordered list of product items
231
	 * @since 2019.04
232
	 */
233
	public function search( $domains = ['media', 'price', 'text'], &$total = null )
234
	{
235
		return $this->controller->search( $domains, $total );
236
	}
237
238
239
	/**
240
	 * Sets the start value and the number of returned products for slicing the list of found products
241
	 *
242
	 * @param integer $start Start value of the first product in the list
243
	 * @param integer $limit Number of returned products
244
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
245
	 * @since 2019.04
246
	 */
247
	public function slice( $start, $limit )
248
	{
249
		$this->controller->slice( $start, $limit );
250
		return $this;
251
	}
252
253
254
	/**
255
	 * Sets the sorting of the result list
256
	 *
257
	 * @param string|null $key Sorting of the result list like "name", "-name", "price", "-price", "code", "-code", "ctime, "-ctime" and "relevance", null for no sorting
258
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
259
	 * @since 2019.04
260
	 */
261
	public function sort( $key = null )
262
	{
263
		$this->controller->sort( $key );
264
		return $this;
265
	}
266
267
268
	/**
269
	 * Adds supplier IDs for filtering
270
	 *
271
	 * @param array|string $supIds Supplier ID or list of IDs
272
	 * @param string $listtype List type of the products referenced by the suppliers
273
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
274
	 * @since 2019.04
275
	 */
276
	public function supplier( $supIds, $listtype = 'default' )
277
	{
278
		$this->controller->supplier( $supIds, $listtype );
279
		return $this;
280
	}
281
282
283
	/**
284
	 * Adds input string for full text search
285
	 *
286
	 * @param string|null $text User input for full text search
287
	 * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
288
	 * @since 2019.04
289
	 */
290
	public function text( $text )
291
	{
292
		$this->controller->text( $text );
293
		return $this;
294
	}
295
296
297
	/**
298
	 * Returns the frontend controller
299
	 *
300
	 * @return \Aimeos\Controller\Frontend\Product\Iface Frontend controller object
301
	 */
302
	protected function getController()
303
	{
304
		return $this->controller;
305
	}
306
}
307