Passed
Push — master ( 6cf50b...92e939 )
by Aimeos
01:45
created

Base::has()   A

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 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
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
	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\Attribute\Iface::class;
36
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
37
38
		parent::__construct( $context );
39
	}
40
41
42
	/**
43
	 * Passes unknown methods to wrapped objects.
44
	 *
45
	 * @param string $name Name of the method
46
	 * @param array $param List of method parameter
47
	 * @return mixed Returns the value of the called method
48
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
49
	 */
50
	public function __call( $name, array $param )
51
	{
52
		return @call_user_func_array( array( $this->controller, $name ), $param );
53
	}
54
55
56
	/**
57
	 * Clones objects in controller and resets values
58
	 */
59
	public function __clone()
60
	{
61
		$this->controller = clone $this->controller;
62
	}
63
64
65
	/**
66
	 * Adds attribute IDs for filtering
67
	 *
68
	 * @param array|string $attrIds Attribute ID or list of IDs
69
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
70
	 * @since 2019.04
71
	 */
72
	public function attribute( $attrIds )
73
	{
74
		$this->controller->attribute( $attrIds );
75
		return $this;
76
	}
77
78
79
	/**
80
	 * Adds generic condition for filtering attributes
81
	 *
82
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
83
	 * @param string $key Search key defined by the attribute manager, e.g. "attribute.status"
84
	 * @param array|string $value Value or list of values to compare to
85
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
86
	 * @since 2019.04
87
	 */
88
	public function compare( $operator, $key, $value )
89
	{
90
		$this->controller->compare( $operator, $key, $value );
91
		return $this;
92
	}
93
94
95
	/**
96
	 * Adds the domain of the attributes for filtering
97
	 *
98
	 * @param string $domain Domain of the attributes
99
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
100
	 * @since 2019.04
101
	 */
102
	public function domain( $domain )
103
	{
104
		$this->controller->domain( $domain );
105
		return $this;
106
	}
107
108
109
	/**
110
	 * Returns the attribute for the given attribute code
111
	 *
112
	 * @param string $code Unique attribute code
113
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
114
	 * @param string $type Type assigned to the attribute
115
	 * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items
116
	 * @since 2019.04
117
	 */
118
	public function find( $code, $domains = ['media', 'price', 'text'], $type = 'product' )
119
	{
120
		return $this->controller->find( $code, $domains, $type );
121
	}
122
123
124
	/**
125
	 * Returns the attribute for the given attribute ID
126
	 *
127
	 * @param string $id Unique attribute ID
128
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
129
	 * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items
130
	 * @since 2019.04
131
	 */
132
	public function get( $id, $domains = ['media', 'price', 'text'] )
133
	{
134
		return $this->controller->get( $id, $domains );
135
	}
136
137
138
	/**
139
	 * Adds a filter to return only items containing a reference to the given ID
140
	 *
141
	 * @param string $domain Domain name of the referenced item, e.g. "price"
142
	 * @param string|null $type Type code of the reference, e.g. "default" or null for all types
143
	 * @param string|null $refId ID of the referenced item of the given domain or null for all references
144
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
145
	 * @since 2019.04
146
	 */
147
	public function has( $domain, $type = null, $refId = null )
148
	{
149
		return $this->controller->has( $domain, $type, $refId );
150
	}
151
152
153
	/**
154
	 * Parses the given array and adds the conditions to the list of conditions
155
	 *
156
	 * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]]
157
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
158
	 * @since 2019.04
159
	 */
160
	public function parse( array $conditions )
161
	{
162
		$this->controller->parse( $conditions );
163
		return $this;
164
	}
165
166
167
	/**
168
	 * Adds a filter to return only items containing the property
169
	 *
170
	 * @param string $type Type code of the property, e.g. "htmlcolor"
171
	 * @param string|null $value Exact value of the property
172
	 * @param string|null $langId ISO country code (en or en_US) or null if not language specific
173
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
174
	 * @since 2019.04
175
	 */
176
	public function property( $type, $value = null, $langId = null )
177
	{
178
		$this->controller->property( $type, $value, $langId );
179
		return $this;
180
	}
181
182
183
	/**
184
	 * Returns the attributes filtered by the previously assigned conditions
185
	 *
186
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
187
	 * @param integer &$total Parameter where the total number of found attributes will be stored in
188
	 * @return \Aimeos\MShop\Attribute\Item\Iface[] Ordered list of attribute items
189
	 * @since 2019.04
190
	 */
191
	public function search( $domains = ['media', 'price', 'text'], &$total = null )
192
	{
193
		return $this->controller->search( $domains, $total );
194
	}
195
196
197
	/**
198
	 * Sets the start value and the number of returned attributes for slicing the list of found attributes
199
	 *
200
	 * @param integer $start Start value of the first attribute in the list
201
	 * @param integer $limit Number of returned attributes
202
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
203
	 * @since 2019.04
204
	 */
205
	public function slice( $start, $limit )
206
	{
207
		$this->controller->slice( $start, $limit );
208
		return $this;
209
	}
210
211
212
	/**
213
	 * Sets the sorting of the result list
214
	 *
215
	 * @param string|null $key Sorting of the result list like "position", null for no sorting
216
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
217
	 * @since 2019.04
218
	 */
219
	public function sort( $key = null )
220
	{
221
		$this->controller->sort( $key );
222
		return $this;
223
	}
224
225
226
	/**
227
	 * Adds attribute types for filtering
228
	 *
229
	 * @param array|string $codes Attribute ID or list of IDs
230
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Attribute controller for fluent interface
231
	 * @since 2019.04
232
	 */
233
	public function type( $codes )
234
	{
235
		$this->controller->type( $codes );
236
		return $this;
237
	}
238
239
240
	/**
241
	 * Returns the frontend controller
242
	 *
243
	 * @return \Aimeos\Controller\Frontend\Attribute\Iface Frontend controller object
244
	 */
245
	protected function getController()
246
	{
247
		return $this->controller;
248
	}
249
}
250