1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Site\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for site 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\Site\Iface |
23
|
|
|
{ |
24
|
|
|
use \Aimeos\Controller\Frontend\Common\Decorator\Traits; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
private $controller; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes the controller decorator. |
32
|
|
|
* |
33
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
34
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
35
|
|
|
*/ |
36
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
37
|
|
|
{ |
38
|
|
|
parent::__construct( $context ); |
39
|
|
|
|
40
|
|
|
$iface = \Aimeos\Controller\Frontend\Site\Iface::class; |
41
|
|
|
$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Passes unknown methods to wrapped objects. |
47
|
|
|
* |
48
|
|
|
* @param string $name Name of the method |
49
|
|
|
* @param array $param List of method parameter |
50
|
|
|
* @return mixed Returns the value of the called method |
51
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
52
|
|
|
*/ |
53
|
|
|
public function __call( string $name, array $param ) |
54
|
|
|
{ |
55
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Clones objects in controller and resets values |
61
|
|
|
*/ |
62
|
|
|
public function __clone() |
63
|
|
|
{ |
64
|
|
|
$this->controller = clone $this->controller; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Adds generic condition for filtering attributes |
70
|
|
|
* |
71
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
72
|
|
|
* @param string $key Search key defined by the site manager, e.g. "site.status" |
73
|
|
|
* @param array|string $value Value or list of values to compare to |
74
|
|
|
* @return \Aimeos\Controller\Frontend\Site\Iface Site controller for fluent interface |
75
|
|
|
* @since 2021.04 |
76
|
|
|
*/ |
77
|
|
|
public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Site\Iface |
78
|
|
|
{ |
79
|
|
|
$this->controller->compare( $operator, $key, $value ); |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the category for the given site code |
86
|
|
|
* |
87
|
|
|
* @param string $code Unique site code |
88
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Site item |
89
|
|
|
* @since 2021.04 |
90
|
|
|
*/ |
91
|
|
|
public function find( string $code ) : \Aimeos\MShop\Locale\Item\Site\Iface |
92
|
|
|
{ |
93
|
|
|
return $this->controller->find( $code ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns the category for the given site ID |
99
|
|
|
* |
100
|
|
|
* @param string $id Unique site ID |
101
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Site item |
102
|
|
|
* @since 2021.04 |
103
|
|
|
*/ |
104
|
|
|
public function get( string $id ) : \Aimeos\MShop\Locale\Item\Site\Iface |
105
|
|
|
{ |
106
|
|
|
return $this->controller->get( $id ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns the list of sites up to the root node including the node given by its ID |
112
|
|
|
* |
113
|
|
|
* @param string $id Current category ID |
114
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface[] Associative list of sites |
115
|
|
|
* @since 2021.04 |
116
|
|
|
*/ |
117
|
|
|
public function getPath( string $id ) |
118
|
|
|
{ |
119
|
|
|
return $this->controller->getPath( $id ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns the sites filtered by the previously assigned conditions |
125
|
|
|
* |
126
|
|
|
* @param int $level Tree level constant, e.g. ONE, LIST or TREE |
127
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Site tree |
128
|
|
|
* @since 2021.04 |
129
|
|
|
*/ |
130
|
|
|
public function getTree( int $level = \Aimeos\Controller\Frontend\Site\Iface::TREE ) : \Aimeos\MShop\Locale\Item\Site\Iface |
131
|
|
|
{ |
132
|
|
|
return $this->controller->getTree( $level ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
138
|
|
|
* |
139
|
|
|
* @param array $conditions List of conditions, e.g. ['>' => ['site.status' => 0]] |
140
|
|
|
* @return \Aimeos\Controller\Frontend\Site\Iface Site controller for fluent interface |
141
|
|
|
* @since 2021.04 |
142
|
|
|
*/ |
143
|
|
|
public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Site\Iface |
144
|
|
|
{ |
145
|
|
|
$this->controller->parse( $conditions ); |
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Sets the site ID of node that is used as root node |
152
|
|
|
* |
153
|
|
|
* @param string|null $id Site ID |
154
|
|
|
* @return \Aimeos\Controller\Frontend\Site\Iface Site controller for fluent interface |
155
|
|
|
* @since 2021.04 |
156
|
|
|
*/ |
157
|
|
|
public function root( string $id = null ) : \Aimeos\Controller\Frontend\Site\Iface |
158
|
|
|
{ |
159
|
|
|
$this->controller->root( $id ); |
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Returns the sites filtered by the previously assigned conditions |
165
|
|
|
* |
166
|
|
|
* @param int &$total Parameter where the total number of found sites will be stored in |
167
|
|
|
* @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Locale\Item\Site\Iface |
168
|
|
|
* @since 2021.04 |
169
|
|
|
*/ |
170
|
|
|
public function search( int &$total = null ) : \Aimeos\Map |
171
|
|
|
{ |
172
|
|
|
return $this->controller->search( $total ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets the start value and the number of returned products for slicing the list of found products |
178
|
|
|
* |
179
|
|
|
* @param int $start Start value of the first product in the list |
180
|
|
|
* @param int $limit Number of returned products |
181
|
|
|
* @return \Aimeos\Controller\Frontend\Site\Iface Site controller for fluent interface |
182
|
|
|
* @since 2021.04 |
183
|
|
|
*/ |
184
|
|
|
public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Site\Iface |
185
|
|
|
{ |
186
|
|
|
$this->controller->slice( $start, $limit ); |
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Sets the sorting of the result list |
193
|
|
|
* |
194
|
|
|
* @param string|null $key Search key for sorting of the result list and null for no sorting |
195
|
|
|
* @return \Aimeos\Controller\Frontend\Site\Iface Site controller for fluent interface |
196
|
|
|
* @since 2021.04 |
197
|
|
|
*/ |
198
|
|
|
public function sort( ?string $key = null ) : \Aimeos\Controller\Frontend\Site\Iface |
199
|
|
|
{ |
200
|
|
|
$this->controller->sort( $key ); |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Injects the reference of the outmost object |
207
|
|
|
* |
208
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
209
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
210
|
|
|
*/ |
211
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface |
212
|
|
|
{ |
213
|
|
|
parent::setObject( $object ); |
214
|
|
|
|
215
|
|
|
$this->controller->setObject( $object ); |
216
|
|
|
|
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Returns the frontend controller |
223
|
|
|
* |
224
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Frontend controller object |
225
|
|
|
*/ |
226
|
|
|
protected function getController() : \Aimeos\Controller\Frontend\Iface |
227
|
|
|
{ |
228
|
|
|
return $this->controller; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|