|
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\Cms; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default implementation of the cms frontend controller |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Frontend |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Controller\Frontend\Base |
|
22
|
|
|
implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
private $conditions = []; |
|
25
|
|
|
private $domains = []; |
|
26
|
|
|
private $filter; |
|
27
|
|
|
private $manager; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Common initialization for controller classes |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Common MShop context object |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct( $context ); |
|
38
|
|
|
|
|
39
|
|
|
$this->manager = \Aimeos\MShop::create( $context, 'cms' ); |
|
40
|
|
|
$this->filter = $this->manager->filter( true ); |
|
41
|
|
|
$this->conditions[] = $this->filter->getConditions(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Clones objects in controller and resets values |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __clone() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->filter = clone $this->filter; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Adds generic condition for filtering |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
|
58
|
|
|
* @param string $key Search key defined by the cms manager, e.g. "cms.status" |
|
59
|
|
|
* @param array|string $value Value or list of values to compare to |
|
60
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
61
|
|
|
* @since 2021.04 |
|
62
|
|
|
*/ |
|
63
|
|
|
public function compare( string $operator, string $key, $value ) : Iface |
|
64
|
|
|
{ |
|
65
|
|
|
$this->conditions[] = $this->filter->compare( $operator, $key, $value ); |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the cms for the given cms code |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $code Unique cms code |
|
74
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface Cms item including the referenced domains items |
|
75
|
|
|
* @since 2021.04 |
|
76
|
|
|
*/ |
|
77
|
|
|
public function find( string $code ) : \Aimeos\MShop\Cms\Item\Iface |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->manager->find( $code, $this->domains, null, null, true ); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Creates a search function string for the given name and parameters |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $name Name of the search function without parenthesis, e.g. "cms:has" |
|
87
|
|
|
* @param array $params List of parameters for the search function with numeric keys starting at 0 |
|
88
|
|
|
* @return string Search function string that can be used in compare() |
|
89
|
|
|
*/ |
|
90
|
|
|
public function function( string $name, array $params ) : string |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->filter->make( $name, $params ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Returns the cms for the given cms ID |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $id Unique cms ID |
|
100
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface Cms item including the referenced domains items |
|
101
|
|
|
* @since 2021.04 |
|
102
|
|
|
*/ |
|
103
|
|
|
public function get( string $id ) : \Aimeos\MShop\Cms\Item\Iface |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->manager->get( $id, $this->domains, true ); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Adds a filter to return only items containing a reference to the given ID |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $domain Domain name of the referenced item, e.g. "product" |
|
113
|
|
|
* @param string|null $type Type code of the reference, e.g. "default" or null for all types |
|
114
|
|
|
* @param string|null $refId ID of the referenced item of the given domain or null for all references |
|
115
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
116
|
|
|
* @since 2019.10 |
|
117
|
|
|
*/ |
|
118
|
|
|
public function has( string $domain, string $type = null, string $refId = null ) : Iface |
|
119
|
|
|
{ |
|
120
|
|
|
$params = [$domain]; |
|
121
|
|
|
!$type ?: $params[] = $type; |
|
122
|
|
|
!$refId ?: $params[] = $refId; |
|
123
|
|
|
|
|
124
|
|
|
$func = $this->filter->make( 'cms:has', $params ); |
|
125
|
|
|
$this->conditions[] = $this->filter->compare( '!=', $func, null ); |
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
|
132
|
|
|
* |
|
133
|
|
|
* @param array $conditions List of conditions, e.g. ['=~' => ['cms.label' => 'test']] |
|
134
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
135
|
|
|
* @since 2021.04 |
|
136
|
|
|
*/ |
|
137
|
|
|
public function parse( array $conditions ) : Iface |
|
138
|
|
|
{ |
|
139
|
|
|
if( ( $cond = $this->filter->parse( $conditions ) ) !== null ) { |
|
140
|
|
|
$this->conditions[] = $cond; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns the cmss filtered by the previously assigned conditions |
|
149
|
|
|
* |
|
150
|
|
|
* @param int &$total Parameter where the total number of found cmss will be stored in |
|
151
|
|
|
* @return \Aimeos\Map Ordered list of cms items implementing \Aimeos\MShop\Cms\Item\Iface |
|
152
|
|
|
* @since 2021.04 |
|
153
|
|
|
*/ |
|
154
|
|
|
public function search( int &$total = null ) : \Aimeos\Map |
|
155
|
|
|
{ |
|
156
|
|
|
$this->filter->setConditions( $this->filter->and( $this->conditions ) ); |
|
157
|
|
|
return $this->manager->search( $this->filter, $this->domains, $total ); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Sets the start value and the number of returned cms items for slicing the list of found cms items |
|
163
|
|
|
* |
|
164
|
|
|
* @param int $start Start value of the first cms item in the list |
|
165
|
|
|
* @param int $limit Number of returned cms items |
|
166
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
167
|
|
|
* @since 2021.04 |
|
168
|
|
|
*/ |
|
169
|
|
|
public function slice( int $start, int $limit ) : Iface |
|
170
|
|
|
{ |
|
171
|
|
|
$this->filter->slice( $start, $limit ); |
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Sets the sorting of the result list |
|
178
|
|
|
* |
|
179
|
|
|
* @param string|null $key Sorting key of the result list like "cms.label", null for no sorting |
|
180
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
181
|
|
|
* @since 2021.04 |
|
182
|
|
|
*/ |
|
183
|
|
|
public function sort( string $key = null ) : Iface |
|
184
|
|
|
{ |
|
185
|
|
|
$sort = []; |
|
186
|
|
|
$list = ( $key ? explode( ',', $key ) : [] ); |
|
187
|
|
|
|
|
188
|
|
|
foreach( $list as $sortkey ) |
|
189
|
|
|
{ |
|
190
|
|
|
$direction = ( $sortkey[0] === '-' ? '-' : '+' ); |
|
191
|
|
|
$sort[] = $this->filter->sort( $direction, ltrim( $sortkey, '+-' ) ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
$this->filter->setSortations( $sort ); |
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
|
201
|
|
|
* |
|
202
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
|
203
|
|
|
* @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface |
|
204
|
|
|
* @since 2021.04 |
|
205
|
|
|
*/ |
|
206
|
|
|
public function uses( array $domains ) : Iface |
|
207
|
|
|
{ |
|
208
|
|
|
$this->domains = $domains; |
|
209
|
|
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|