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