1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
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 extends \Aimeos\Controller\Frontend\Common\Decorator\Base |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Returns the manager for the given name |
24
|
|
|
* |
25
|
|
|
* @param string $name Name of the manager |
26
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager object |
27
|
|
|
*/ |
28
|
|
|
public function createManager( $name ) |
29
|
|
|
{ |
30
|
|
|
return $this->getController()->createManager( $name ); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the default catalog filter |
36
|
|
|
* |
37
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object for filtering |
38
|
|
|
* @since 2015.08 |
39
|
|
|
*/ |
40
|
|
|
public function createCatalogFilter() |
41
|
|
|
{ |
42
|
|
|
return $this->getController()->createCatalogFilter(); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns the list of categries that are in the path to the root node including the one specified by its ID. |
49
|
|
|
* |
50
|
|
|
* @param integer $id Category ID to start from, null for root node |
51
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
52
|
|
|
* @return array Associative list of items implementing \Aimeos\MShop\Catalog\Item\Iface with their IDs as keys |
53
|
|
|
* @since 2015.08 |
54
|
|
|
*/ |
55
|
|
|
public function getCatalogPath( $id, array $domains = array( 'text', 'media' ) ) |
56
|
|
|
{ |
57
|
|
|
return $this->getController()->getCatalogPath( $id, $domains ); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the hierarchical catalog tree starting from the given ID. |
63
|
|
|
* |
64
|
|
|
* @param integer|null $id Category ID to start from, null for root node |
65
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
66
|
|
|
* @param integer $level Constant from \Aimeos\MW\Tree\Manager\Base for the depth of the returned tree, LEVEL_ONE for |
67
|
|
|
* specific node only, LEVEL_LIST for node and all direct child nodes, LEVEL_TREE for the whole tree |
68
|
|
|
* @param \Aimeos\MW\Criteria\Iface|null $search Optional criteria object with conditions |
69
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog node, maybe with children depending on the level constant |
70
|
|
|
* @since 2015.08 |
71
|
|
|
*/ |
72
|
|
|
public function getCatalogTree( $id = null, array $domains = array( 'text', 'media' ), |
73
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, \Aimeos\MW\Criteria\Iface $search = null ) |
74
|
|
|
{ |
75
|
|
|
return $this->getController()->getCatalogTree( $id, $domains, $level, $search ); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the aggregated count of products from the index for the given key. |
81
|
|
|
* |
82
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
83
|
|
|
* @param string $key Search key to aggregate for, e.g. "index.attribute.id" |
84
|
|
|
* @return array Associative list of key values as key and the product count for this key as value |
85
|
|
|
* @since 2015.08 |
86
|
|
|
*/ |
87
|
|
|
public function aggregateIndex( \Aimeos\MW\Criteria\Iface $filter, $key ) |
88
|
|
|
{ |
89
|
|
|
return $this->getController()->aggregateIndex( $filter, $key ); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the given search filter with the conditions attached for filtering by category. |
95
|
|
|
* |
96
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Criteria object used for product search |
97
|
|
|
* @param string $catid Selected category by the user |
98
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
99
|
|
|
* @since 2015.08 |
100
|
|
|
*/ |
101
|
|
|
public function addIndexFilterCategory( \Aimeos\MW\Criteria\Iface $search, $catid ) |
102
|
|
|
{ |
103
|
|
|
return $this->getController()->addIndexFilterCategory( $search, $catid ); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the given search filter with the conditions attached for filtering texts. |
109
|
|
|
* |
110
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Criteria object used for product search |
111
|
|
|
* @param string $input Search string entered by the user |
112
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
113
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
114
|
|
|
* @since 2015.08 |
115
|
|
|
*/ |
116
|
|
|
public function addIndexFilterText( \Aimeos\MW\Criteria\Iface $search, $input, $listtype = 'default' ) |
117
|
|
|
{ |
118
|
|
|
return $this->getController()->addIndexFilterText( $search, $input, $listtype ); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns the default index filter. |
124
|
|
|
* |
125
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
126
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
127
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
128
|
|
|
* @param integer $size Number of products that should be returned |
129
|
|
|
* @param string $listtype Type of the product list, e.g. default, promotion, etc. |
130
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
131
|
|
|
* @since 2015.08 |
132
|
|
|
*/ |
133
|
|
|
public function createIndexFilter( $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' ) |
134
|
|
|
{ |
135
|
|
|
return $this->getController()->createIndexFilter( $sort, $direction, $start, $size, $listtype ); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Returns a index filter for the given category ID. |
141
|
|
|
* |
142
|
|
|
* @param integer $catid ID of the category to get the product list from |
143
|
|
|
* @param string $sort Sortation of the product list like "name", "price" and "position" |
144
|
|
|
* @param string $direction Sort direction of the product list ("asc", "desc") |
145
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
146
|
|
|
* @param integer $size Number of products that should be returned |
147
|
|
|
* @param string $listtype Type of the product list, e.g. default, promotion, etc. |
148
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
149
|
|
|
* @since 2015.08 |
150
|
|
|
*/ |
151
|
|
|
public function createIndexFilterCategory( $catid, $sort = 'position', $direction = 'asc', $start = 0, $size = 100, $listtype = 'default' ) |
152
|
|
|
{ |
153
|
|
|
return $this->getController()->createIndexFilter( $catid, $sort, $direction, $start, $size, $listtype ); |
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns the index filter for the given search string. |
159
|
|
|
* |
160
|
|
|
* @param string $input Search string entered by the user |
161
|
|
|
* @param string $sort Sortation of the product list like "name", "price" and "relevance" |
162
|
|
|
* @param string $direction Sort direction of the product list ("asc", "desc", but not for relevance ) |
163
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
164
|
|
|
* @param integer $size Number of products that should be returned |
165
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
166
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
167
|
|
|
* @since 2015.08 |
168
|
|
|
*/ |
169
|
|
|
public function createIndexFilterText( $input, $sort = 'relevance', $direction = 'asc', $start = 0, $size = 100, $listtype = 'default' ) |
170
|
|
|
{ |
171
|
|
|
return $this->getController()->createIndexFilter( $input, $sort, $direction, $start, $size, $listtype ); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Returns the products from the index filtered by the given criteria object. |
177
|
|
|
* |
178
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
179
|
|
|
* @param string[] $domains Domain names of items that are associated with the products and that should be fetched too |
180
|
|
|
* @param integer &$total Parameter where the total number of found products will be stored in |
181
|
|
|
* @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface |
182
|
|
|
* @since 2015.08 |
183
|
|
|
*/ |
184
|
|
|
public function getIndexItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null ) |
185
|
|
|
{ |
186
|
|
|
return $this->getController()->getIndexItems( $filter, $domains, $total ); |
|
|
|
|
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Returns the product item for the given ID if it's available |
192
|
|
|
* |
193
|
|
|
* @param array $ids List of product IDs |
194
|
|
|
* @param array $domains Domain names of items that are associated with the products and that should be fetched too |
195
|
|
|
* @return array List of product items implementing \Aimeos\MShop\Product\Item\Iface |
196
|
|
|
* @since 2015.08 |
197
|
|
|
*/ |
198
|
|
|
public function getProductItems( array $ids, array $domains = array( 'media', 'price', 'text' ) ) |
199
|
|
|
{ |
200
|
|
|
return $this->getController()->getProductItems( $ids, $domains ); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Returns text filter for the given search string. |
206
|
|
|
* |
207
|
|
|
* @param string $input Search string entered by the user |
208
|
|
|
* @param string|null $sort Sortation of the product list like "name" and "relevance", null for no sortation |
209
|
|
|
* @param string $direction Sort direction of the product list ("asc", "desc") |
210
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
211
|
|
|
* @param integer $size Number of products that should be returned |
212
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
213
|
|
|
* @param string $type Type of the text like "name", "short", "long", etc. |
214
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
215
|
|
|
*/ |
216
|
|
|
public function createTextFilter( $input, $sort = null, $direction = 'desc', $start = 0, $size = 25, $listtype = 'default', $type = 'name' ) |
217
|
|
|
{ |
218
|
|
|
return $this->getController()->createTextFilter( $input, $sort, $direction, $start, $size, $listtype, $type ); |
|
|
|
|
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns an list of product text strings matched by the filter. |
224
|
|
|
* |
225
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
226
|
|
|
* @return array Associative list of the product ID as key and the product text as value |
227
|
|
|
*/ |
228
|
|
|
public function getTextList( \Aimeos\MW\Criteria\Iface $filter ) |
229
|
|
|
{ |
230
|
|
|
return $this->getController()->getTextList( $filter ); |
|
|
|
|
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: