1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2018 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Catalog\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for catalog 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\Catalog\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\Catalog\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 attributes |
67
|
|
|
* |
68
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
69
|
|
|
* @param string $key Search key defined by the catalog manager, e.g. "catalog.status" |
70
|
|
|
* @param array|string $value Value or list of values to compare to |
71
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
72
|
|
|
* @since 2019.04 |
73
|
|
|
*/ |
74
|
|
|
public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Catalog\Iface |
75
|
|
|
{ |
76
|
|
|
$this->controller->compare( $operator, $key, $value ); |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the category for the given catalog code |
83
|
|
|
* |
84
|
|
|
* @param string $code Unique catalog code |
85
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog item including the referenced domains items |
86
|
|
|
* @since 2019.04 |
87
|
|
|
*/ |
88
|
|
|
public function find( string $code ) : \Aimeos\MShop\Catalog\Item\Iface |
89
|
|
|
{ |
90
|
|
|
return $this->controller->find( $code ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Creates a search function string for the given name and parameters |
96
|
|
|
* |
97
|
|
|
* @param string $name Name of the search function without parenthesis, e.g. "catalog:has" |
98
|
|
|
* @param array $params List of parameters for the search function with numeric keys starting at 0 |
99
|
|
|
* @return string Search function string that can be used in compare() |
100
|
|
|
*/ |
101
|
|
|
public function function( string $name, array $params ) : string |
102
|
|
|
{ |
103
|
|
|
return $this->controller->function( $name, $params ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the category for the given catalog ID |
109
|
|
|
* |
110
|
|
|
* @param string $id Unique catalog ID |
111
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog item including the referenced domains items |
112
|
|
|
* @since 2019.04 |
113
|
|
|
*/ |
114
|
|
|
public function get( string $id ) : \Aimeos\MShop\Catalog\Item\Iface |
115
|
|
|
{ |
116
|
|
|
return $this->controller->get( $id ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the list of categories up to the root node including the node given by its ID |
122
|
|
|
* |
123
|
|
|
* @param string $id Current category ID |
124
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface[] Associative list of categories |
125
|
|
|
* @since 2017.03 |
126
|
|
|
*/ |
127
|
|
|
public function getPath( string $id ) |
128
|
|
|
{ |
129
|
|
|
return $this->controller->getPath( $id ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns the categories filtered by the previously assigned conditions |
135
|
|
|
* |
136
|
|
|
* @param int $level Constant from \Aimeos\MW\Tree\Manager\Base, e.g. LEVEL_ONE, LEVEL_LIST or LEVEL_TREE |
137
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Category tree |
138
|
|
|
* @since 2019.04 |
139
|
|
|
*/ |
140
|
|
|
public function getTree( int $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ) : \Aimeos\MShop\Catalog\Item\Iface |
141
|
|
|
{ |
142
|
|
|
return $this->controller->getTree( $level ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
148
|
|
|
* |
149
|
|
|
* @param array $conditions List of conditions, e.g. ['>' => ['catalog.status' => 0]] |
150
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
151
|
|
|
* @since 2019.04 |
152
|
|
|
*/ |
153
|
|
|
public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Catalog\Iface |
154
|
|
|
{ |
155
|
|
|
$this->controller->parse( $conditions ); |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Sets the catalog ID of node that is used as root node |
162
|
|
|
* |
163
|
|
|
* @param string|null $id Catalog ID |
164
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
165
|
|
|
* @since 2019.04 |
166
|
|
|
*/ |
167
|
|
|
public function root( string $id = null ) : \Aimeos\Controller\Frontend\Catalog\Iface |
168
|
|
|
{ |
169
|
|
|
$this->controller->root( $id ); |
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
176
|
|
|
* |
177
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
178
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
179
|
|
|
* @since 2019.04 |
180
|
|
|
*/ |
181
|
|
|
public function uses( array $domains ) : \Aimeos\Controller\Frontend\Catalog\Iface |
182
|
|
|
{ |
183
|
|
|
$this->controller->uses( $domains ); |
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Limits categories returned to only visible ones depending on the given category IDs |
190
|
|
|
* |
191
|
|
|
* @param array $catIds List of category IDs |
192
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
193
|
|
|
*/ |
194
|
|
|
public function visible( array $catIds ) : \Aimeos\Controller\Frontend\Catalog\Iface |
195
|
|
|
{ |
196
|
|
|
$this->controller->visible( $catIds ); |
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Injects the reference of the outmost object |
203
|
|
|
* |
204
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
205
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
206
|
|
|
*/ |
207
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface |
208
|
|
|
{ |
209
|
|
|
parent::setObject( $object ); |
210
|
|
|
|
211
|
|
|
$this->controller->setObject( $object ); |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Returns the frontend controller |
219
|
|
|
* |
220
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Frontend controller object |
221
|
|
|
*/ |
222
|
|
|
protected function getController() : \Aimeos\Controller\Frontend\Catalog\Iface |
223
|
|
|
{ |
224
|
|
|
return $this->controller; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|