Passed
Push — master ( 91b6db...c8efcd )
by Aimeos
27:02 queued 24:35
created

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