|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2023 |
|
6
|
|
|
* @package MShop |
|
7
|
|
|
* @subpackage Cms |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Cms\Manager; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default cms manager implementation |
|
16
|
|
|
* |
|
17
|
|
|
* @package MShop |
|
18
|
|
|
* @subpackage Cms |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
|
22
|
|
|
implements \Aimeos\MShop\Cms\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
/** mshop/cms/manager/name |
|
25
|
|
|
* Class name of the used cms manager implementation |
|
26
|
|
|
* |
|
27
|
|
|
* Each default manager can be replace by an alternative imlementation. |
|
28
|
|
|
* To use this implementation, you have to set the last part of the class |
|
29
|
|
|
* name as configuration value so the manager factory knows which class it |
|
30
|
|
|
* has to instantiate. |
|
31
|
|
|
* |
|
32
|
|
|
* For example, if the name of the default class is |
|
33
|
|
|
* |
|
34
|
|
|
* \Aimeos\MShop\Cms\Manager\Standard |
|
35
|
|
|
* |
|
36
|
|
|
* and you want to replace it with your own version named |
|
37
|
|
|
* |
|
38
|
|
|
* \Aimeos\MShop\Cms\Manager\Mymanager |
|
39
|
|
|
* |
|
40
|
|
|
* then you have to set the this configuration option: |
|
41
|
|
|
* |
|
42
|
|
|
* mshop/cms/manager/name = Mymanager |
|
43
|
|
|
* |
|
44
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
|
45
|
|
|
* so take care that the configuration value is exactly named like the last |
|
46
|
|
|
* part of the class name. |
|
47
|
|
|
* |
|
48
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
|
49
|
|
|
* characters are possible! You should always start the last part of the class |
|
50
|
|
|
* name with an upper case character and continue only with lower case characters |
|
51
|
|
|
* or numbers. Avoid chamel case names like "MyManager"! |
|
52
|
|
|
* |
|
53
|
|
|
* @param string Last part of the class name |
|
54
|
|
|
* @since 2020.10 |
|
55
|
|
|
* @category Developer |
|
56
|
|
|
*/ |
|
57
|
|
|
|
|
58
|
|
|
/** mshop/cms/manager/decorators/excludes |
|
59
|
|
|
* Excludes decorators added by the "common" option from the cms manager |
|
60
|
|
|
* |
|
61
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
62
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
63
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
64
|
|
|
* modify what is returned to the caller. |
|
65
|
|
|
* |
|
66
|
|
|
* This option allows you to remove a decorator added via |
|
67
|
|
|
* "mshop/common/manager/decorators/default" before they are wrapped |
|
68
|
|
|
* around the cms manager. |
|
69
|
|
|
* |
|
70
|
|
|
* mshop/cms/manager/decorators/excludes = array( 'decorator1' ) |
|
71
|
|
|
* |
|
72
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
73
|
|
|
* common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
|
74
|
|
|
* "mshop/common/manager/decorators/default" for the cms manager. |
|
75
|
|
|
* |
|
76
|
|
|
* @param array List of decorator names |
|
77
|
|
|
* @since 2020.10 |
|
78
|
|
|
* @category Developer |
|
79
|
|
|
* @see mshop/common/manager/decorators/default |
|
80
|
|
|
* @see mshop/cms/manager/decorators/global |
|
81
|
|
|
* @see mshop/cms/manager/decorators/local |
|
82
|
|
|
*/ |
|
83
|
|
|
|
|
84
|
|
|
/** mshop/cms/manager/decorators/global |
|
85
|
|
|
* Adds a list of globally available decorators only to the cms manager |
|
86
|
|
|
* |
|
87
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
88
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
89
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
90
|
|
|
* modify what is returned to the caller. |
|
91
|
|
|
* |
|
92
|
|
|
* This option allows you to wrap global decorators |
|
93
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the cms manager. |
|
94
|
|
|
* |
|
95
|
|
|
* mshop/cms/manager/decorators/global = array( 'decorator1' ) |
|
96
|
|
|
* |
|
97
|
|
|
* This would add the decorator named "decorator1" defined by |
|
98
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the cms |
|
99
|
|
|
* manager. |
|
100
|
|
|
* |
|
101
|
|
|
* @param array List of decorator names |
|
102
|
|
|
* @since 2020.10 |
|
103
|
|
|
* @category Developer |
|
104
|
|
|
* @see mshop/common/manager/decorators/default |
|
105
|
|
|
* @see mshop/cms/manager/decorators/excludes |
|
106
|
|
|
* @see mshop/cms/manager/decorators/local |
|
107
|
|
|
*/ |
|
108
|
|
|
|
|
109
|
|
|
/** mshop/cms/manager/decorators/local |
|
110
|
|
|
* Adds a list of local decorators only to the cms manager |
|
111
|
|
|
* |
|
112
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
113
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
114
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
115
|
|
|
* modify what is returned to the caller. |
|
116
|
|
|
* |
|
117
|
|
|
* This option allows you to wrap local decorators |
|
118
|
|
|
* ("\Aimeos\MShop\Cms\Manager\Decorator\*") around the cms manager. |
|
119
|
|
|
* |
|
120
|
|
|
* mshop/cms/manager/decorators/local = array( 'decorator2' ) |
|
121
|
|
|
* |
|
122
|
|
|
* This would add the decorator named "decorator2" defined by |
|
123
|
|
|
* "\Aimeos\MShop\Cms\Manager\Decorator\Decorator2" only to the cms |
|
124
|
|
|
* manager. |
|
125
|
|
|
* |
|
126
|
|
|
* @param array List of decorator names |
|
127
|
|
|
* @since 2020.10 |
|
128
|
|
|
* @category Developer |
|
129
|
|
|
* @see mshop/common/manager/decorators/default |
|
130
|
|
|
* @see mshop/cms/manager/decorators/excludes |
|
131
|
|
|
* @see mshop/cms/manager/decorators/global |
|
132
|
|
|
*/ |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
use \Aimeos\MShop\Common\Manager\ListsRef\Traits; |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
private array $searchConfig = array( |
|
139
|
|
|
'cms.id' => array( |
|
140
|
|
|
'code' => 'cms.id', |
|
141
|
|
|
'internalcode' => 'mcms."id"', |
|
142
|
|
|
'label' => 'ID', |
|
143
|
|
|
'type' => 'integer', |
|
144
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
|
145
|
|
|
'public' => false, |
|
146
|
|
|
), |
|
147
|
|
|
'cms.siteid' => array( |
|
148
|
|
|
'code' => 'cms.siteid', |
|
149
|
|
|
'internalcode' => 'mcms."siteid"', |
|
150
|
|
|
'label' => 'Site ID', |
|
151
|
|
|
'type' => 'string', |
|
152
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
153
|
|
|
'public' => false, |
|
154
|
|
|
), |
|
155
|
|
|
'cms.url' => array( |
|
156
|
|
|
'code' => 'cms.url', |
|
157
|
|
|
'internalcode' => 'mcms."url"', |
|
158
|
|
|
'label' => 'Type', |
|
159
|
|
|
'type' => 'string', |
|
160
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
161
|
|
|
), |
|
162
|
|
|
'cms.label' => array( |
|
163
|
|
|
'code' => 'cms.label', |
|
164
|
|
|
'internalcode' => 'mcms."label"', |
|
165
|
|
|
'label' => 'Label', |
|
166
|
|
|
'type' => 'string', |
|
167
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
168
|
|
|
), |
|
169
|
|
|
'cms.status' => array( |
|
170
|
|
|
'code' => 'cms.status', |
|
171
|
|
|
'internalcode' => 'mcms."status"', |
|
172
|
|
|
'label' => 'Status', |
|
173
|
|
|
'type' => 'integer', |
|
174
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
|
175
|
|
|
), |
|
176
|
|
|
'cms.ctime' => array( |
|
177
|
|
|
'code' => 'cms.ctime', |
|
178
|
|
|
'internalcode' => 'mcms."ctime"', |
|
179
|
|
|
'label' => 'create date/time', |
|
180
|
|
|
'type' => 'datetime', |
|
181
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
182
|
|
|
'public' => false, |
|
183
|
|
|
), |
|
184
|
|
|
'cms.mtime' => array( |
|
185
|
|
|
'code' => 'cms.mtime', |
|
186
|
|
|
'internalcode' => 'mcms."mtime"', |
|
187
|
|
|
'label' => 'modify date/time', |
|
188
|
|
|
'type' => 'datetime', |
|
189
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
190
|
|
|
'public' => false, |
|
191
|
|
|
), |
|
192
|
|
|
'cms.editor' => array( |
|
193
|
|
|
'code' => 'cms.editor', |
|
194
|
|
|
'internalcode' => 'mcms."editor"', |
|
195
|
|
|
'label' => 'editor', |
|
196
|
|
|
'type' => 'string', |
|
197
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
|
198
|
|
|
'public' => false, |
|
199
|
|
|
), |
|
200
|
|
|
'cms:has' => array( |
|
201
|
|
|
'code' => 'cms:has()', |
|
202
|
|
|
'internalcode' => ':site AND :key AND mcmsli."id"', |
|
203
|
|
|
'internaldeps' => ['LEFT JOIN "mshop_cms_list" AS mcmsli ON ( mcmsli."parentid" = mcms."id" )'], |
|
204
|
|
|
'label' => 'Cms has list item, parameter(<domain>[,<list type>[,<reference ID>)]]', |
|
205
|
|
|
'type' => 'null', |
|
206
|
|
|
'internaltype' => 'null', |
|
207
|
|
|
'public' => false, |
|
208
|
|
|
), |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Initializes the object. |
|
214
|
|
|
* |
|
215
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object |
|
216
|
|
|
*/ |
|
217
|
|
|
public function __construct( \Aimeos\MShop\ContextIface $context ) |
|
218
|
|
|
{ |
|
219
|
|
|
parent::__construct( $context ); |
|
220
|
|
|
|
|
221
|
|
|
/** madmin/cms/manager/resource |
|
222
|
|
|
* Name of the database connection resource to use |
|
223
|
|
|
* |
|
224
|
|
|
* You can configure a different database connection for each data domain |
|
225
|
|
|
* and if no such connection name exists, the "db" connection will be used. |
|
226
|
|
|
* It's also possible to use the same database connection for different |
|
227
|
|
|
* data domains by configuring the same connection name using this setting. |
|
228
|
|
|
* |
|
229
|
|
|
* @param string Database connection name |
|
230
|
|
|
* @since 2023.04 |
|
231
|
|
|
*/ |
|
232
|
|
|
$this->setResourceName( $context->config()->get( 'mshop/cms/manager/resource', 'db-cms' ) ); |
|
233
|
|
|
|
|
234
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE; |
|
235
|
|
|
$level = $context->config()->get( 'mshop/cms/manager/sitemode', $level ); |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
$this->searchConfig['cms:has']['function'] = function( &$source, array $params ) use ( $level ) { |
|
239
|
|
|
|
|
240
|
|
|
$keys = []; |
|
241
|
|
|
|
|
242
|
|
|
foreach( (array) ( $params[1] ?? '' ) as $type ) { |
|
243
|
|
|
foreach( (array) ( $params[2] ?? '' ) as $id ) { |
|
244
|
|
|
$keys[] = $params[0] . '|' . ( $type ? $type . '|' : '' ) . $id; |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
$sitestr = $this->siteString( 'mcmsli."siteid"', $level ); |
|
249
|
|
|
$keystr = $this->toExpression( 'mcmsli."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' ); |
|
250
|
|
|
$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source ); |
|
251
|
|
|
|
|
252
|
|
|
return $params; |
|
253
|
|
|
}; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Removes old entries from the storage. |
|
259
|
|
|
* |
|
260
|
|
|
* @param iterable $siteids List of IDs for sites whose entries should be deleted |
|
261
|
|
|
* @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls |
|
262
|
|
|
*/ |
|
263
|
|
|
public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface |
|
264
|
|
|
{ |
|
265
|
|
|
$path = 'mshop/cms/manager/submanagers'; |
|
266
|
|
|
foreach( $this->context()->config()->get( $path, ['lists'] ) as $domain ) { |
|
267
|
|
|
$this->object()->getSubManager( $domain )->clear( $siteids ); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
return $this->clearBase( $siteids, 'mshop/cms/manager/delete' ); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Creates a new empty item instance |
|
276
|
|
|
* |
|
277
|
|
|
* @param array $values Values the item should be initialized with |
|
278
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface New cms item object |
|
279
|
|
|
*/ |
|
280
|
|
|
public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface |
|
281
|
|
|
{ |
|
282
|
|
|
$values['cms.siteid'] = $this->context()->locale()->getSiteId(); |
|
283
|
|
|
return $this->createItemBase( $values ); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* Adds or updates an item object or a list of them. |
|
289
|
|
|
* |
|
290
|
|
|
* @param \Aimeos\Map|\Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface $items Item or list of items whose data should be saved |
|
291
|
|
|
* @param bool $fetch True if the new ID should be returned in the item |
|
292
|
|
|
* @return \Aimeos\Map|\Aimeos\MShop\Common\Item\Iface Saved item or items |
|
293
|
|
|
*/ |
|
294
|
|
|
public function save( $items, bool $fetch = true ) |
|
295
|
|
|
{ |
|
296
|
|
|
$items = parent::save( $items, $fetch ); |
|
297
|
|
|
|
|
298
|
|
|
$this->context()->cache()->deleteByTags( map( $items )->getId()->prefix( 'cms-' ) ); |
|
299
|
|
|
|
|
300
|
|
|
return $items; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Updates or adds a cms item object. |
|
306
|
|
|
* This method doesn't update the type string that belongs to the type ID |
|
307
|
|
|
* |
|
308
|
|
|
* @param \Aimeos\MShop\Cms\Item\Iface $item Cms item which should be saved |
|
309
|
|
|
* @param bool $fetch True if the new ID should be returned in the item |
|
310
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface Updated item including the generated ID |
|
311
|
|
|
*/ |
|
312
|
|
|
protected function saveItem( \Aimeos\MShop\Cms\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Cms\Item\Iface |
|
313
|
|
|
{ |
|
314
|
|
|
if( !$item->isModified() ) { |
|
315
|
|
|
return $this->saveListItems( $item, 'cms', $fetch ); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
$context = $this->context(); |
|
319
|
|
|
$conn = $context->db( $this->getResourceName() ); |
|
320
|
|
|
|
|
321
|
|
|
$id = $item->getId(); |
|
322
|
|
|
$date = date( 'Y-m-d H:i:s' ); |
|
323
|
|
|
$columns = $this->object()->getSaveAttributes(); |
|
324
|
|
|
|
|
325
|
|
|
if( $id === null ) |
|
326
|
|
|
{ |
|
327
|
|
|
/** mshop/cms/manager/insert/mysql |
|
328
|
|
|
* Inserts a new cms record into the database table |
|
329
|
|
|
* |
|
330
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
331
|
|
|
*/ |
|
332
|
|
|
|
|
333
|
|
|
/** mshop/cms/manager/insert/ansi |
|
334
|
|
|
* Inserts a new cms record into the database table |
|
335
|
|
|
* |
|
336
|
|
|
* Items with no ID yet (i.e. the ID is NULL) will be created in |
|
337
|
|
|
* the database and the newly created ID retrieved afterwards |
|
338
|
|
|
* using the "newid" SQL statement. |
|
339
|
|
|
* |
|
340
|
|
|
* The SQL statement must be a string suitable for being used as |
|
341
|
|
|
* prepared statement. It must include question marks for binding |
|
342
|
|
|
* the values from the cms item to the statement before they are |
|
343
|
|
|
* sent to the database server. The number of question marks must |
|
344
|
|
|
* be the same as the number of columns listed in the INSERT |
|
345
|
|
|
* statement. The order of the columns must correspond to the |
|
346
|
|
|
* order in the save() method, so the correct values are |
|
347
|
|
|
* bound to the columns. |
|
348
|
|
|
* |
|
349
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
350
|
|
|
* compatible with most relational database systems. This also |
|
351
|
|
|
* includes using double quotes for table and column names. |
|
352
|
|
|
* |
|
353
|
|
|
* @param string SQL statement for inserting records |
|
354
|
|
|
* @since 2020.10 |
|
355
|
|
|
* @category Developer |
|
356
|
|
|
* @see mshop/cms/manager/update/ansi |
|
357
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
358
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
359
|
|
|
* @see mshop/cms/manager/search/ansi |
|
360
|
|
|
* @see mshop/cms/manager/count/ansi |
|
361
|
|
|
*/ |
|
362
|
|
|
$path = 'mshop/cms/manager/insert'; |
|
363
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) ); |
|
|
|
|
|
|
364
|
|
|
} |
|
365
|
|
|
else |
|
366
|
|
|
{ |
|
367
|
|
|
/** mshop/cms/manager/update/mysql |
|
368
|
|
|
* Updates an existing cms record in the database |
|
369
|
|
|
* |
|
370
|
|
|
* @see mshop/cms/manager/update/ansi |
|
371
|
|
|
*/ |
|
372
|
|
|
|
|
373
|
|
|
/** mshop/cms/manager/update/ansi |
|
374
|
|
|
* Updates an existing cms record in the database |
|
375
|
|
|
* |
|
376
|
|
|
* Items which already have an ID (i.e. the ID is not NULL) will |
|
377
|
|
|
* be updated in the database. |
|
378
|
|
|
* |
|
379
|
|
|
* The SQL statement must be a string suitable for being used as |
|
380
|
|
|
* prepared statement. It must include question marks for binding |
|
381
|
|
|
* the values from the cms item to the statement before they are |
|
382
|
|
|
* sent to the database server. The order of the columns must |
|
383
|
|
|
* correspond to the order in the save() method, so the |
|
384
|
|
|
* correct values are bound to the columns. |
|
385
|
|
|
* |
|
386
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
387
|
|
|
* compatible with most relational database systems. This also |
|
388
|
|
|
* includes using double quotes for table and column names. |
|
389
|
|
|
* |
|
390
|
|
|
* @param string SQL statement for updating records |
|
391
|
|
|
* @since 2020.10 |
|
392
|
|
|
* @category Developer |
|
393
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
394
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
395
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
396
|
|
|
* @see mshop/cms/manager/search/ansi |
|
397
|
|
|
* @see mshop/cms/manager/count/ansi |
|
398
|
|
|
*/ |
|
399
|
|
|
$path = 'mshop/cms/manager/update'; |
|
400
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false ); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
$idx = 1; |
|
404
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
|
405
|
|
|
|
|
406
|
|
|
foreach( $columns as $name => $entry ) { |
|
407
|
|
|
$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() ); |
|
|
|
|
|
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
$stmt->bind( $idx++, $item->getUrl() ); |
|
411
|
|
|
$stmt->bind( $idx++, $item->getLabel() ); |
|
412
|
|
|
$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
|
413
|
|
|
$stmt->bind( $idx++, $date ); // mtime |
|
414
|
|
|
$stmt->bind( $idx++, $context->editor() ); |
|
415
|
|
|
|
|
416
|
|
|
if( $id !== null ) { |
|
417
|
|
|
$stmt->bind( $idx++, $context->locale()->getSiteId() . '%' ); |
|
418
|
|
|
$stmt->bind( $idx++, $id, \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
|
419
|
|
|
} else { |
|
420
|
|
|
$stmt->bind( $idx++, $this->siteId( $item->getSiteId(), \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) ); |
|
421
|
|
|
$stmt->bind( $idx++, $date ); // ctime |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
$stmt->execute()->finish(); |
|
425
|
|
|
|
|
426
|
|
|
if( $id === null ) |
|
427
|
|
|
{ |
|
428
|
|
|
/** mshop/cms/manager/newid/mysql |
|
429
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
|
430
|
|
|
* |
|
431
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
432
|
|
|
*/ |
|
433
|
|
|
|
|
434
|
|
|
/** mshop/cms/manager/newid/ansi |
|
435
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
|
436
|
|
|
* |
|
437
|
|
|
* As soon as a new record is inserted into the database table, |
|
438
|
|
|
* the database server generates a new and unique identifier for |
|
439
|
|
|
* that record. This ID can be used for retrieving, updating and |
|
440
|
|
|
* deleting that specific record from the table again. |
|
441
|
|
|
* |
|
442
|
|
|
* For MySQL: |
|
443
|
|
|
* SELECT LAST_INSERT_ID() |
|
444
|
|
|
* For PostgreSQL: |
|
445
|
|
|
* SELECT currval('seq_mcms_id') |
|
446
|
|
|
* For SQL Server: |
|
447
|
|
|
* SELECT SCOPE_IDENTITY() |
|
448
|
|
|
* For Oracle: |
|
449
|
|
|
* SELECT "seq_mcms_id".CURRVAL FROM DUAL |
|
450
|
|
|
* |
|
451
|
|
|
* There's no way to retrive the new ID by a SQL statements that |
|
452
|
|
|
* fits for most database servers as they implement their own |
|
453
|
|
|
* specific way. |
|
454
|
|
|
* |
|
455
|
|
|
* @param string SQL statement for retrieving the last inserted record ID |
|
456
|
|
|
* @since 2020.10 |
|
457
|
|
|
* @category Developer |
|
458
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
459
|
|
|
* @see mshop/cms/manager/update/ansi |
|
460
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
461
|
|
|
* @see mshop/cms/manager/search/ansi |
|
462
|
|
|
* @see mshop/cms/manager/count/ansi |
|
463
|
|
|
*/ |
|
464
|
|
|
$path = 'mshop/cms/manager/newid'; |
|
465
|
|
|
$id = $this->newId( $conn, $path ); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
$item->setId( $id ); |
|
469
|
|
|
|
|
470
|
|
|
return $this->saveListItems( $item, 'cms', $fetch ); |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
|
|
474
|
|
|
/** |
|
475
|
|
|
* Removes multiple items. |
|
476
|
|
|
* |
|
477
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items |
|
478
|
|
|
* @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls |
|
479
|
|
|
*/ |
|
480
|
|
|
public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface |
|
481
|
|
|
{ |
|
482
|
|
|
/** mshop/cms/manager/delete/mysql |
|
483
|
|
|
* Deletes the items matched by the given IDs from the database |
|
484
|
|
|
* |
|
485
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
486
|
|
|
*/ |
|
487
|
|
|
|
|
488
|
|
|
/** mshop/cms/manager/delete/ansi |
|
489
|
|
|
* Deletes the items matched by the given IDs from the database |
|
490
|
|
|
* |
|
491
|
|
|
* Removes the records specified by the given IDs from the cms database. |
|
492
|
|
|
* The records must be from the site that is configured via the |
|
493
|
|
|
* context item. |
|
494
|
|
|
* |
|
495
|
|
|
* The ":cond" placeholder is replaced by the name of the ID column and |
|
496
|
|
|
* the given ID or list of IDs while the site ID is bound to the question |
|
497
|
|
|
* mark. |
|
498
|
|
|
* |
|
499
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
500
|
|
|
* compatible with most relational database systems. This also |
|
501
|
|
|
* includes using double quotes for table and column names. |
|
502
|
|
|
* |
|
503
|
|
|
* @param string SQL statement for deleting items |
|
504
|
|
|
* @since 2020.10 |
|
505
|
|
|
* @category Developer |
|
506
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
507
|
|
|
* @see mshop/cms/manager/update/ansi |
|
508
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
509
|
|
|
* @see mshop/cms/manager/search/ansi |
|
510
|
|
|
* @see mshop/cms/manager/count/ansi |
|
511
|
|
|
*/ |
|
512
|
|
|
$path = 'mshop/cms/manager/delete'; |
|
513
|
|
|
|
|
514
|
|
|
return $this->deleteItemsBase( $itemIds, $path )->deleteRefItems( $itemIds ); |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
/** |
|
519
|
|
|
* Returns the item specified by its URL |
|
520
|
|
|
* |
|
521
|
|
|
* @param string $code URL of the item |
|
522
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
|
523
|
|
|
* @param string|null $domain Domain of the item if necessary to identify the item uniquely |
|
524
|
|
|
* @param string|null $type Type code of the item if necessary to identify the item uniquely |
|
525
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
526
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface Item object |
|
527
|
|
|
*/ |
|
528
|
|
|
public function find( string $code, array $ref = [], string $domain = null, string $type = null, |
|
529
|
|
|
?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
|
530
|
|
|
{ |
|
531
|
|
|
return $this->findBase( array( 'cms.url' => $code ), $ref, $default ); |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
|
|
535
|
|
|
/** |
|
536
|
|
|
* Returns the cms item object specified by the given ID. |
|
537
|
|
|
* |
|
538
|
|
|
* @param string $id Id of the cms item |
|
539
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
|
540
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
541
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface Returns the cms item of the given id |
|
542
|
|
|
* @throws \Aimeos\MShop\Exception If item couldn't be found |
|
543
|
|
|
*/ |
|
544
|
|
|
public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
|
545
|
|
|
{ |
|
546
|
|
|
return $this->getItemBase( 'cms.id', $id, $ref, $default ); |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
|
|
550
|
|
|
/** |
|
551
|
|
|
* Returns the available manager types |
|
552
|
|
|
* |
|
553
|
|
|
* @param bool $withsub Return also the resource type of sub-managers if true |
|
554
|
|
|
* @return string[] Type of the manager and submanagers, subtypes are separated by slashes |
|
555
|
|
|
*/ |
|
556
|
|
|
public function getResourceType( bool $withsub = true ) : array |
|
557
|
|
|
{ |
|
558
|
|
|
$path = 'mshop/cms/manager/submanagers'; |
|
559
|
|
|
return $this->getResourceTypeBase( 'cms', $path, ['lists'], $withsub ); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
|
|
563
|
|
|
/** |
|
564
|
|
|
* Returns the attributes that can be used for searching. |
|
565
|
|
|
* |
|
566
|
|
|
* @param bool $withsub Return also attributes of sub-managers if true |
|
567
|
|
|
* @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items |
|
568
|
|
|
*/ |
|
569
|
|
|
public function getSearchAttributes( bool $withsub = true ) : array |
|
570
|
|
|
{ |
|
571
|
|
|
/** mshop/cms/manager/submanagers |
|
572
|
|
|
* List of manager names that can be instantiated by the cms manager |
|
573
|
|
|
* |
|
574
|
|
|
* Managers provide a generic interface to the underlying storage. |
|
575
|
|
|
* Each manager has or can have sub-managers caring about particular |
|
576
|
|
|
* aspects. Each of these sub-managers can be instantiated by its |
|
577
|
|
|
* parent manager using the getSubManager() method. |
|
578
|
|
|
* |
|
579
|
|
|
* The search keys from sub-managers can be normally used in the |
|
580
|
|
|
* manager as well. It allows you to search for items of the manager |
|
581
|
|
|
* using the search keys of the sub-managers to further limit the |
|
582
|
|
|
* retrieved list of items. |
|
583
|
|
|
* |
|
584
|
|
|
* @param array List of sub-manager names |
|
585
|
|
|
* @since 2020.10 |
|
586
|
|
|
* @category Developer |
|
587
|
|
|
*/ |
|
588
|
|
|
$path = 'mshop/cms/manager/submanagers'; |
|
589
|
|
|
|
|
590
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
|
|
594
|
|
|
/** |
|
595
|
|
|
* Searches for all cms items matching the given critera. |
|
596
|
|
|
* |
|
597
|
|
|
* @param \Aimeos\Base\Criteria\Iface $search Search criteria object |
|
598
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
|
599
|
|
|
* @param int|null &$total Number of items that are available in total |
|
600
|
|
|
* @return \Aimeos\Map List of items implementing \Aimeos\MShop\Cms\Item\Iface with ids as keys |
|
601
|
|
|
*/ |
|
602
|
|
|
public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map |
|
603
|
|
|
{ |
|
604
|
|
|
$map = []; |
|
605
|
|
|
$context = $this->context(); |
|
606
|
|
|
$conn = $context->db( $this->getResourceName() ); |
|
607
|
|
|
|
|
608
|
|
|
$required = array( 'cms' ); |
|
609
|
|
|
|
|
610
|
|
|
/** mshop/cms/manager/sitemode |
|
611
|
|
|
* Mode how items from levels below or above in the site tree are handled |
|
612
|
|
|
* |
|
613
|
|
|
* By default, only items from the current site are fetched from the |
|
614
|
|
|
* storage. If the ai-sites extension is installed, you can create a |
|
615
|
|
|
* tree of sites. Then, this setting allows you to define for the |
|
616
|
|
|
* whole cms domain if items from parent sites are inherited, |
|
617
|
|
|
* sites from child sites are aggregated or both. |
|
618
|
|
|
* |
|
619
|
|
|
* Available constants for the site mode are: |
|
620
|
|
|
* * 0 = only items from the current site |
|
621
|
|
|
* * 1 = inherit items from parent sites |
|
622
|
|
|
* * 2 = aggregate items from child sites |
|
623
|
|
|
* * 3 = inherit and aggregate items at the same time |
|
624
|
|
|
* |
|
625
|
|
|
* You also need to set the mode in the locale manager |
|
626
|
|
|
* (mshop/locale/manager/sitelevel) to one of the constants. |
|
627
|
|
|
* If you set it to the same value, it will work as described but you |
|
628
|
|
|
* can also use different modes. For example, if inheritance and |
|
629
|
|
|
* aggregation is configured the locale manager but only inheritance |
|
630
|
|
|
* in the domain manager because aggregating items makes no sense in |
|
631
|
|
|
* this domain, then items wil be only inherited. Thus, you have full |
|
632
|
|
|
* control over inheritance and aggregation in each domain. |
|
633
|
|
|
* |
|
634
|
|
|
* @param int Constant from Aimeos\MShop\Locale\Manager\Base class |
|
635
|
|
|
* @category Developer |
|
636
|
|
|
* @since 2020.10 |
|
637
|
|
|
* @see mshop/locale/manager/sitelevel |
|
638
|
|
|
*/ |
|
639
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE; |
|
640
|
|
|
$level = $context->config()->get( 'mshop/cms/manager/sitemode', $level ); |
|
641
|
|
|
|
|
642
|
|
|
/** mshop/cms/manager/search/mysql |
|
643
|
|
|
* Retrieves the records matched by the given criteria in the database |
|
644
|
|
|
* |
|
645
|
|
|
* @see mshop/cms/manager/search/ansi |
|
646
|
|
|
*/ |
|
647
|
|
|
|
|
648
|
|
|
/** mshop/cms/manager/search/ansi |
|
649
|
|
|
* Retrieves the records matched by the given criteria in the database |
|
650
|
|
|
* |
|
651
|
|
|
* Fetches the records matched by the given criteria from the cms |
|
652
|
|
|
* database. The records must be from one of the sites that are |
|
653
|
|
|
* configured via the context item. If the current site is part of |
|
654
|
|
|
* a tree of sites, the SELECT statement can retrieve all records |
|
655
|
|
|
* from the current site and the complete sub-tree of sites. |
|
656
|
|
|
* |
|
657
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
|
658
|
|
|
* their tables must be joined in the SQL context. This is done by |
|
659
|
|
|
* using the "internaldeps" property from the definition of the ID |
|
660
|
|
|
* column of the sub-managers. These internal dependencies specify |
|
661
|
|
|
* the JOIN between the tables and the used columns for joining. The |
|
662
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
|
663
|
|
|
* the sub-managers. |
|
664
|
|
|
* |
|
665
|
|
|
* To limit the records matched, conditions can be added to the given |
|
666
|
|
|
* criteria object. It can contain comparisons like column names that |
|
667
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
|
668
|
|
|
* operators. The resulting string of SQL conditions replaces the |
|
669
|
|
|
* ":cond" placeholder before the statement is sent to the database |
|
670
|
|
|
* server. |
|
671
|
|
|
* |
|
672
|
|
|
* If the records that are retrieved should be ordered by one or more |
|
673
|
|
|
* columns, the generated string of column / sort direction pairs |
|
674
|
|
|
* replaces the ":order" placeholder. In case no ordering is required, |
|
675
|
|
|
* the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
|
676
|
|
|
* markers is removed to speed up retrieving the records. Columns of |
|
677
|
|
|
* sub-managers can also be used for ordering the result set but then |
|
678
|
|
|
* no index can be used. |
|
679
|
|
|
* |
|
680
|
|
|
* The number of returned records can be limited and can start at any |
|
681
|
|
|
* number between the begining and the end of the result set. For that |
|
682
|
|
|
* the ":size" and ":start" placeholders are replaced by the |
|
683
|
|
|
* corresponding values from the criteria object. The default values |
|
684
|
|
|
* are 0 for the start and 100 for the size value. |
|
685
|
|
|
* |
|
686
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
687
|
|
|
* compatible with most relational database systems. This also |
|
688
|
|
|
* includes using double quotes for table and column names. |
|
689
|
|
|
* |
|
690
|
|
|
* @param string SQL statement for searching items |
|
691
|
|
|
* @since 2020.10 |
|
692
|
|
|
* @category Developer |
|
693
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
694
|
|
|
* @see mshop/cms/manager/update/ansi |
|
695
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
696
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
697
|
|
|
* @see mshop/cms/manager/count/ansi |
|
698
|
|
|
*/ |
|
699
|
|
|
$cfgPathSearch = 'mshop/cms/manager/search'; |
|
700
|
|
|
|
|
701
|
|
|
/** mshop/cms/manager/count/mysql |
|
702
|
|
|
* Counts the number of records matched by the given criteria in the database |
|
703
|
|
|
* |
|
704
|
|
|
* @see mshop/cms/manager/count/ansi |
|
705
|
|
|
*/ |
|
706
|
|
|
|
|
707
|
|
|
/** mshop/cms/manager/count/ansi |
|
708
|
|
|
* Counts the number of records matched by the given criteria in the database |
|
709
|
|
|
* |
|
710
|
|
|
* Counts all records matched by the given criteria from the cms |
|
711
|
|
|
* database. The records must be from one of the sites that are |
|
712
|
|
|
* configured via the context item. If the current site is part of |
|
713
|
|
|
* a tree of sites, the statement can count all records from the |
|
714
|
|
|
* current site and the complete sub-tree of sites. |
|
715
|
|
|
* |
|
716
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
|
717
|
|
|
* their tables must be joined in the SQL context. This is done by |
|
718
|
|
|
* using the "internaldeps" property from the definition of the ID |
|
719
|
|
|
* column of the sub-managers. These internal dependencies specify |
|
720
|
|
|
* the JOIN between the tables and the used columns for joining. The |
|
721
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
|
722
|
|
|
* the sub-managers. |
|
723
|
|
|
* |
|
724
|
|
|
* To limit the records matched, conditions can be added to the given |
|
725
|
|
|
* criteria object. It can contain comparisons like column names that |
|
726
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
|
727
|
|
|
* operators. The resulting string of SQL conditions replaces the |
|
728
|
|
|
* ":cond" placeholder before the statement is sent to the database |
|
729
|
|
|
* server. |
|
730
|
|
|
* |
|
731
|
|
|
* Both, the strings for ":joins" and for ":cond" are the same as for |
|
732
|
|
|
* the "search" SQL statement. |
|
733
|
|
|
* |
|
734
|
|
|
* Contrary to the "search" statement, it doesn't return any records |
|
735
|
|
|
* but instead the number of records that have been found. As counting |
|
736
|
|
|
* thousands of records can be a long running task, the maximum number |
|
737
|
|
|
* of counted records is limited for performance reasons. |
|
738
|
|
|
* |
|
739
|
|
|
* The SQL statement should conform to the ANSI standard to be |
|
740
|
|
|
* compatible with most relational database systems. This also |
|
741
|
|
|
* includes using double quotes for table and column names. |
|
742
|
|
|
* |
|
743
|
|
|
* @param string SQL statement for counting items |
|
744
|
|
|
* @since 2020.10 |
|
745
|
|
|
* @category Developer |
|
746
|
|
|
* @see mshop/cms/manager/insert/ansi |
|
747
|
|
|
* @see mshop/cms/manager/update/ansi |
|
748
|
|
|
* @see mshop/cms/manager/newid/ansi |
|
749
|
|
|
* @see mshop/cms/manager/delete/ansi |
|
750
|
|
|
* @see mshop/cms/manager/search/ansi |
|
751
|
|
|
*/ |
|
752
|
|
|
$cfgPathCount = 'mshop/cms/manager/count'; |
|
753
|
|
|
|
|
754
|
|
|
$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level ); |
|
755
|
|
|
|
|
756
|
|
|
while( ( $row = $results->fetch() ) !== null ) { |
|
757
|
|
|
$map[$row['cms.id']] = $row; |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
return $this->buildItems( $map, $ref, 'cms' ); |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
|
|
764
|
|
|
/** |
|
765
|
|
|
* Returns a new manager for cms extensions |
|
766
|
|
|
* |
|
767
|
|
|
* @param string $manager Name of the sub manager type in lower case |
|
768
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
|
769
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g types, lists etc. |
|
770
|
|
|
*/ |
|
771
|
|
|
public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface |
|
772
|
|
|
{ |
|
773
|
|
|
return $this->getSubManagerBase( 'cms', $manager, $name ); |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
|
|
777
|
|
|
/** |
|
778
|
|
|
* Creates a filter object. |
|
779
|
|
|
* |
|
780
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
|
781
|
|
|
* @param bool $site TRUE for adding site criteria to limit items by the site of related items |
|
782
|
|
|
* @return \Aimeos\Base\Criteria\Iface Returns the filter object |
|
783
|
|
|
*/ |
|
784
|
|
|
public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface |
|
785
|
|
|
{ |
|
786
|
|
|
if( $default === true ) { |
|
787
|
|
|
return $this->filterBase( 'cms' ); |
|
788
|
|
|
} |
|
789
|
|
|
|
|
790
|
|
|
return parent::filter(); |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
|
|
794
|
|
|
/** |
|
795
|
|
|
* Creates a new cms item instance. |
|
796
|
|
|
* |
|
797
|
|
|
* @param array $values Associative list of key/value pairs |
|
798
|
|
|
* @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems List of list items |
|
799
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface $refItems List of referenced items |
|
800
|
|
|
* @return \Aimeos\MShop\Cms\Item\Iface New cms item |
|
801
|
|
|
*/ |
|
802
|
|
|
protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [] ) : \Aimeos\MShop\Common\Item\Iface |
|
803
|
|
|
{ |
|
804
|
|
|
return new \Aimeos\MShop\Cms\Item\Standard( $values, $listItems, $refItems ); |
|
805
|
|
|
} |
|
806
|
|
|
} |
|
807
|
|
|
|