Completed
Push — master ( 56f888...ae1907 )
by Aimeos
03:01
created

Base::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
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), 2020
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Review\Decorator;
12
13
14
/**
15
 * Base for review 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\Review\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\Review\Iface::class;
38
		$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller );
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( string $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
	 * Returns the aggregated count of products for the given key.
67
	 *
68
	 * @param string $key Search key to aggregate for, e.g. "review.rating"
69
	 * @param string|null $value Search key for aggregating the value column
70
	 * @param string|null $type Type of the aggregation, empty string for count or "sum"
71
	 * @return \Aimeos\Map Associative list of key values as key and the product count for this key as value
72
	 * @since 2020.10
73
	 */
74
	public function aggregate( string $key, string $value = null, string $type = null ) : \Aimeos\Map
75
	{
76
		return $this->controller->aggregate( $key, $value, $type );
77
	}
78
79
80
	/**
81
	 * Adds generic condition for filtering
82
	 *
83
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
84
	 * @param string $key Search key defined by the review manager, e.g. "review.status"
85
	 * @param array|string $value Value or list of values to compare to
86
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
87
	 * @since 2020.10
88
	 */
89
	public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Review\Iface
90
	{
91
		$this->controller->compare( $operator, $key, $value );
92
		return $this;
93
	}
94
95
96
	/**
97
	 * Returns a new rating item
98
	 *
99
	 * @param array $values Associative list of key/value pairs to initialize the item
100
	 * @return \Aimeos\MShop\Review\Item\Iface New review item
101
	 */
102
	public function create( array $values = [] ) : \Aimeos\MShop\Review\Item\Iface
103
	{
104
		return $this->controller->create( $values );
105
	}
106
107
108
	/**
109
	 * Deletes the review item for the given ID
110
	 *
111
	 * @param array|string $id Unique review ID or list of IDs
112
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
113
	 * @since 2020.10
114
	 */
115
	public function delete( $ids ) : \Aimeos\Controller\Frontend\Review\Iface
116
	{
117
		$this->controller->delete( $ids );
118
		return $this;
119
	}
120
121
122
	/**
123
	 * Sets the review domain for filtering
124
	 *
125
	 * @param string $domain Domain ("customer" or "product") of the reviewed items
126
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
127
	 * @since 2020.10
128
	 */
129
	public function domain( string $domain ) : \Aimeos\Controller\Frontend\Review\Iface
130
	{
131
		$this->controller->domain( $domain );
132
		return $this;
133
	}
134
135
136
	/**
137
	 * Restricts the reviews to a specific domain item
138
	 *
139
	 * @param string $domain Domain the reviews belong to (e.g. "product")
140
	 * @param string|null $refid Id of the item the reviews belong to or NULL for all reviews from the domain
141
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
142
	 * @since 2020.10
143
	 */
144
	 public function for( string $domain, ?string $refid ) : \Aimeos\Controller\Frontend\Review\Iface
145
	{
146
		$this->controller->for( $domain, $refid );
147
		return $this;
148
	}
149
150
151
	/**
152
	 * Returns the review for the given review ID
153
	 *
154
	 * @param string $id Unique review ID
155
	 * @return \Aimeos\MShop\Review\Item\Iface Review item including the referenced domains items
156
	 * @since 2020.10
157
	 */
158
	public function get( string $id ) : \Aimeos\MShop\Review\Item\Iface
159
	{
160
		return $this->controller->get( $id );
161
	}
162
163
164
	/**
165
	 * Returns the reviews for the logged-in user
166
	 *
167
	 * @param int &$total Parameter where the total number of found reviews will be stored in
168
	 * @return \Aimeos\Map Ordered list of review items implementing \Aimeos\MShop\Review\Item\Iface
169
	 * @since 2020.10
170
	 */
171
	public function list( int &$total = null ) : \Aimeos\Map
172
	{
173
		return $this->controller->list( $total );
174
	}
175
176
177
	/**
178
	 * Parses the given array and adds the conditions to the list of conditions
179
	 *
180
	 * @param array $conditions List of conditions, e.g. ['>' => ['review.rating' => 3]]
181
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
182
	 * @since 2020.10
183
	 */
184
	public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Review\Iface
185
	{
186
		$this->controller->parse( $conditions );
187
		return $this;
188
	}
189
190
191
	/**
192
	 * Saves the modified review item
193
	 *
194
	 * @param \Aimeos\MShop\Review\Item\Iface $item Review object
195
	 * @return \Aimeos\MShop\Review\Item\Iface Saved review item
196
	 */
197
	public function save( \Aimeos\MShop\Review\Item\Iface $item ) : \Aimeos\MShop\Review\Item\Iface
198
	{
199
		return $this->controller->save( $item );
200
	}
201
202
203
	/**
204
	 * Returns the reviews filtered by the previously assigned conditions
205
	 *
206
	 * @param int &$total Parameter where the total number of found reviews will be stored in
207
	 * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Review\Item\Iface
208
	 * @since 2020.10
209
	 */
210
	public function search( int &$total = null ) : \Aimeos\Map
211
	{
212
		return $this->controller->search( $total );
213
	}
214
215
216
	/**
217
	 * Sets the start value and the number of returned review items for slicing the list of found review items
218
	 *
219
	 * @param int $start Start value of the first review item in the list
220
	 * @param int $limit Number of returned review items
221
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
222
	 * @since 2020.10
223
	 */
224
	public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Review\Iface
225
	{
226
		$this->controller->slice( $start, $limit );
227
		return $this;
228
	}
229
230
231
	/**
232
	 * Sets the sorting of the result list
233
	 *
234
	 * @param string|null $key Sorting key of the result list like "interval", null for no sorting
235
	 * @return \Aimeos\Controller\Frontend\Review\Iface Review controller for fluent interface
236
	 * @since 2020.10
237
	 */
238
	public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Review\Iface
239
	{
240
		$this->controller->sort( $key );
241
		return $this;
242
	}
243
244
245
	/**
246
	 * Injects the reference of the outmost object
247
	 *
248
	 * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator
249
	 * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls
250
	 */
251
	public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface
252
	{
253
		parent::setObject( $object );
254
255
		$this->controller->setObject( $object );
256
257
		return $this;
258
	}
259
260
261
	/**
262
	 * Returns the frontend controller
263
	 *
264
	 * @return \Aimeos\Controller\Frontend\Review\Iface Frontend controller object
265
	 */
266
	protected function getController() : \Aimeos\Controller\Frontend\Review\Iface
267
	{
268
		return $this->controller;
269
	}
270
}
271