Completed
Push — master ( 32309c...101584 )
by Aimeos
03:33
created

Base::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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