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