Base::search()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
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), 2017-2025
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
	use \Aimeos\Controller\Frontend\Common\Decorator\Traits;
25
26
27
	private \Aimeos\Controller\Frontend\Attribute\Iface $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
		$this->controller = $controller;
41
	}
42
43
44
	/**
45
	 * Passes unknown methods to wrapped objects.
46
	 *
47
	 * @param string $name Name of the method
48
	 * @param array $param List of method parameter
49
	 * @return mixed Returns the value of the called method
50
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
51
	 */
52
	public function __call( string $name, array $param )
53
	{
54
		return @call_user_func_array( array( $this->controller, $name ), $param );
55
	}
56
57
58
	/**
59
	 * Clones objects in controller and resets values
60
	 */
61
	public function __clone()
62
	{
63
		$this->controller = clone $this->controller;
64
	}
65
66
67
	/**
68
	 * Adds attribute IDs for filtering
69
	 *
70
	 * @param array|string $attrIds Attribute ID or list of IDs
71
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
72
	 * @since 2019.04
73
	 */
74
	public function attribute( $attrIds ) : \Aimeos\Controller\Frontend\Attribute\Iface
75
	{
76
		$this->controller->attribute( $attrIds );
77
		return $this;
78
	}
79
80
81
	/**
82
	 * Adds generic condition for filtering attributes
83
	 *
84
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
85
	 * @param string $key Search key defined by the attribute manager, e.g. "attribute.status"
86
	 * @param array|string $value Value or list of values to compare to
87
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
88
	 * @since 2019.04
89
	 */
90
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Attribute\Iface
91
	{
92
		$this->controller->compare( $operator, $key, $value );
93
		return $this;
94
	}
95
96
97
	/**
98
	 * Adds the domain of the attributes for filtering
99
	 *
100
	 * @param string $domain Domain of the attributes
101
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
102
	 * @since 2019.04
103
	 */
104
	public function domain( string $domain ) : \Aimeos\Controller\Frontend\Attribute\Iface
105
	{
106
		$this->controller->domain( $domain );
107
		return $this;
108
	}
109
110
111
	/**
112
	 * Returns the attribute for the given attribute code
113
	 *
114
	 * @param string $code Unique attribute code
115
	 * @param string $type Type assigned to the attribute
116
	 * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items
117
	 * @since 2019.04
118
	 */
119
	public function find( string $code, string $type ) : \Aimeos\MShop\Attribute\Item\Iface
120
	{
121
		return $this->controller->find( $code, $type );
122
	}
123
124
125
	/**
126
	 * Creates a search function string for the given name and parameters
127
	 *
128
	 * @param string $name Name of the search function without parenthesis, e.g. "attribute:prop"
129
	 * @param array $params List of parameters for the search function with numeric keys starting at 0
130
	 * @return string Search function string that can be used in compare()
131
	 */
132
	public function function( string $name, array $params ) : string
133
	{
134
		return $this->controller->function( $name, $params );
135
	}
136
137
138
	/**
139
	 * Returns the attribute for the given attribute ID
140
	 *
141
	 * @param string $id Unique attribute ID
142
	 * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items
143
	 * @since 2019.04
144
	 */
145
	public function get( string $id ) : \Aimeos\MShop\Attribute\Item\Iface
146
	{
147
		return $this->controller->get( $id );
148
	}
149
150
151
	/**
152
	 * Adds a filter to return only items containing a reference to the given ID
153
	 *
154
	 * @param string $domain Domain name of the referenced item, e.g. "price"
155
	 * @param string|null $type Type code of the reference, e.g. "default" or null for all types
156
	 * @param string|null $refId ID of the referenced item of the given domain or null for all references
157
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
158
	 * @since 2019.04
159
	 */
160
	public function has( string $domain, ?string $type = null, ?string $refId = null ) : \Aimeos\Controller\Frontend\Attribute\Iface
161
	{
162
		$this->controller->has( $domain, $type, $refId );
163
		return $this;
164
	}
165
166
167
	/**
168
	 * Parses the given array and adds the conditions to the list of conditions
169
	 *
170
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]]
171
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
172
	 * @since 2019.04
173
	 */
174
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Attribute\Iface
175
	{
176
		$this->controller->parse( $conditions );
177
		return $this;
178
	}
179
180
181
	/**
182
	 * Adds a filter to return only items containing the property
183
	 *
184
	 * @param string $type Type code of the property, e.g. "htmlcolor"
185
	 * @param string|null $value Exact value of the property
186
	 * @param string|null $langId ISO country code (en or en_US) or null if not language specific
187
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
188
	 * @since 2019.04
189
	 */
190
	public function property( string $type, ?string $value = null, ?string $langId = null ) : \Aimeos\Controller\Frontend\Attribute\Iface
191
	{
192
		$this->controller->property( $type, $value, $langId );
193
		return $this;
194
	}
195
196
197
	/**
198
	 * Returns the attributes filtered by the previously assigned conditions
199
	 *
200
	 * @param integer &$total Parameter where the total number of found attributes will be stored in
201
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Attribute\Item\Iface
202
	 * @since 2019.04
203
	 */
204
	public function search( ?int &$total = null ) : \Aimeos\Map
205
	{
206
		return $this->controller->search( $total );
207
	}
208
209
210
	/**
211
	 * Sets the start value and the number of returned attributes for slicing the list of found attributes
212
	 *
213
	 * @param int $start Start value of the first attribute in the list
214
	 * @param int $limit Number of returned attributes
215
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
216
	 * @since 2019.04
217
	 */
218
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Attribute\Iface
219
	{
220
		$this->controller->slice( $start, $limit );
221
		return $this;
222
	}
223
224
225
	/**
226
	 * Sets the sorting of the result list
227
	 *
228
	 * @param string|null $key Sorting of the result list like "position", null for no sorting
229
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
230
	 * @since 2019.04
231
	 */
232
	public function sort( ?string $key = null ) : \Aimeos\Controller\Frontend\Attribute\Iface
233
	{
234
		$this->controller->sort( $key );
235
		return $this;
236
	}
237
238
239
	/**
240
	 * Adds attribute types for filtering
241
	 *
242
	 * @param array|string $codes Attribute ID or list of IDs
243
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
244
	 * @since 2019.04
245
	 */
246
	public function type( $codes ) : \Aimeos\Controller\Frontend\Attribute\Iface
247
	{
248
		$this->controller->type( $codes );
249
		return $this;
250
	}
251
252
253
	/**
254
	 * Sets the referenced domains that will be fetched too when retrieving items
255
	 *
256
	 * @param array $domains Domain names of the referenced items that should be fetched too
257
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
258
	 * @since 2019.04
259
	 */
260
	public function uses( array $domains ) : \Aimeos\Controller\Frontend\Attribute\Iface
261
	{
262
		$this->controller->uses( $domains );
263
		return $this;
264
	}
265
266
267
	/**
268
	 * Injects the reference of the outmost object
269
	 *
270
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
271
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
272
	 */
273
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
274
	{
275
		parent::setObject( $object );
276
277
		$this->controller->setObject( $object );
0 ignored issues
show
Bug introduced by
The method setObject() does not exist on Aimeos\Controller\Frontend\Attribute\Iface. Since it exists in all sub-types, consider adding an abstract or default implementation to Aimeos\Controller\Frontend\Attribute\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

277
		$this->controller->/** @scrutinizer ignore-call */ 
278
                     setObject( $object );
Loading history...
278
279
		return $this;
280
	}
281
282
283
	/**
284
	 * Returns the frontend controller
285
	 *
286
	 * @return \Aimeos\Controller\Frontend\Iface Frontend controller object
287
	 */
288
	protected function getController() : \Aimeos\Controller\Frontend\Iface
289
	{
290
		return $this->controller;
291
	}
292
}
293