Standard::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021-2022
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 $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
		$this->setResourceName( 'db-cms' );
221
222
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE;
223
		$level = $context->config()->get( 'mshop/cms/manager/sitemode', $level );
224
225
226
		$this->searchConfig['cms:has']['function'] = function( &$source, array $params ) use ( $level ) {
227
228
			$keys = [];
229
230
			foreach( (array) ( $params[1] ?? '' ) as $type ) {
231
				foreach( (array) ( $params[2] ?? '' ) as $id ) {
232
					$keys[] = $params[0] . '|' . ( $type ? $type . '|' : '' ) . $id;
233
				}
234
			}
235
236
			$sitestr = $this->siteString( 'mcmsli."siteid"', $level );
237
			$keystr = $this->toExpression( 'mcmsli."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' );
238
			$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );
239
240
			return $params;
241
		};
242
	}
243
244
245
	/**
246
	 * Removes old entries from the storage.
247
	 *
248
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
249
	 * @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls
250
	 */
251
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
252
	{
253
		$path = 'mshop/cms/manager/submanagers';
254
		foreach( $this->context()->config()->get( $path, ['lists'] ) as $domain ) {
255
			$this->object()->getSubManager( $domain )->clear( $siteids );
256
		}
257
258
		return $this->clearBase( $siteids, 'mshop/cms/manager/delete' );
259
	}
260
261
262
	/**
263
	 * Creates a new empty item instance
264
	 *
265
	 * @param array $values Values the item should be initialized with
266
	 * @return \Aimeos\MShop\Cms\Item\Iface New cms item object
267
	 */
268
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
269
	{
270
		$values['cms.siteid'] = $this->context()->locale()->getSiteId();
271
		return $this->createItemBase( $values );
272
	}
273
274
275
	/**
276
	 * Updates or adds a cms item object.
277
	 * This method doesn't update the type string that belongs to the type ID
278
	 *
279
	 * @param \Aimeos\MShop\Cms\Item\Iface $item Cms item which should be saved
280
	 * @param bool $fetch True if the new ID should be returned in the item
281
	 * @return \Aimeos\MShop\Cms\Item\Iface Updated item including the generated ID
282
	 */
283
	public function saveItem( \Aimeos\MShop\Cms\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Cms\Item\Iface
284
	{
285
		if( !$item->isModified() ) {
286
			return $this->saveListItems( $item, 'cms', $fetch );
287
		}
288
289
		$context = $this->context();
290
		$conn = $context->db( $this->getResourceName() );
291
292
			$id = $item->getId();
293
			$date = date( 'Y-m-d H:i:s' );
294
			$columns = $this->object()->getSaveAttributes();
295
296
			if( $id === null )
297
			{
298
				/** mshop/cms/manager/insert/mysql
299
				 * Inserts a new cms record into the database table
300
				 *
301
				 * @see mshop/cms/manager/insert/ansi
302
				 */
303
304
				/** mshop/cms/manager/insert/ansi
305
				 * Inserts a new cms record into the database table
306
				 *
307
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
308
				 * the database and the newly created ID retrieved afterwards
309
				 * using the "newid" SQL statement.
310
				 *
311
				 * The SQL statement must be a string suitable for being used as
312
				 * prepared statement. It must include question marks for binding
313
				 * the values from the cms item to the statement before they are
314
				 * sent to the database server. The number of question marks must
315
				 * be the same as the number of columns listed in the INSERT
316
				 * statement. The order of the columns must correspond to the
317
				 * order in the save() method, so the correct values are
318
				 * bound to the columns.
319
				 *
320
				 * The SQL statement should conform to the ANSI standard to be
321
				 * compatible with most relational database systems. This also
322
				 * includes using double quotes for table and column names.
323
				 *
324
				 * @param string SQL statement for inserting records
325
				 * @since 2020.10
326
				 * @category Developer
327
				 * @see mshop/cms/manager/update/ansi
328
				 * @see mshop/cms/manager/newid/ansi
329
				 * @see mshop/cms/manager/delete/ansi
330
				 * @see mshop/cms/manager/search/ansi
331
				 * @see mshop/cms/manager/count/ansi
332
				 */
333
				$path = 'mshop/cms/manager/insert';
334
				$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) );
0 ignored issues
show
Bug introduced by
It seems like $this->getSqlConfig($path) can also be of type array; however, parameter $sql of Aimeos\MShop\Common\Manager\Base::addSqlColumns() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

334
				$sql = $this->addSqlColumns( array_keys( $columns ), /** @scrutinizer ignore-type */ $this->getSqlConfig( $path ) );
Loading history...
335
			}
336
			else
337
			{
338
				/** mshop/cms/manager/update/mysql
339
				 * Updates an existing cms record in the database
340
				 *
341
				 * @see mshop/cms/manager/update/ansi
342
				 */
343
344
				/** mshop/cms/manager/update/ansi
345
				 * Updates an existing cms record in the database
346
				 *
347
				 * Items which already have an ID (i.e. the ID is not NULL) will
348
				 * be updated in the database.
349
				 *
350
				 * The SQL statement must be a string suitable for being used as
351
				 * prepared statement. It must include question marks for binding
352
				 * the values from the cms item to the statement before they are
353
				 * sent to the database server. The order of the columns must
354
				 * correspond to the order in the save() method, so the
355
				 * correct values are bound to the columns.
356
				 *
357
				 * The SQL statement should conform to the ANSI standard to be
358
				 * compatible with most relational database systems. This also
359
				 * includes using double quotes for table and column names.
360
				 *
361
				 * @param string SQL statement for updating records
362
				 * @since 2020.10
363
				 * @category Developer
364
				 * @see mshop/cms/manager/insert/ansi
365
				 * @see mshop/cms/manager/newid/ansi
366
				 * @see mshop/cms/manager/delete/ansi
367
				 * @see mshop/cms/manager/search/ansi
368
				 * @see mshop/cms/manager/count/ansi
369
				 */
370
				$path = 'mshop/cms/manager/update';
371
				$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false );
372
			}
373
374
			$idx = 1;
375
			$stmt = $this->getCachedStatement( $conn, $path, $sql );
376
377
			foreach( $columns as $name => $entry ) {
378
				$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() );
0 ignored issues
show
Bug introduced by
It seems like $entry->getInternalType() can also be of type string; however, parameter $type of Aimeos\Base\DB\Statement\Iface::bind() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

378
				$stmt->bind( $idx++, $item->get( $name ), /** @scrutinizer ignore-type */ $entry->getInternalType() );
Loading history...
379
			}
380
381
			$stmt->bind( $idx++, $item->getUrl() );
382
			$stmt->bind( $idx++, $item->getLabel() );
383
			$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
384
			$stmt->bind( $idx++, $date ); // mtime
385
			$stmt->bind( $idx++, $context->editor() );
386
387
			if( $id !== null ) {
388
				$stmt->bind( $idx++, $context->locale()->getSiteId() . '%' );
389
				$stmt->bind( $idx++, $id, \Aimeos\Base\DB\Statement\Base::PARAM_INT );
390
			} else {
391
				$stmt->bind( $idx++, $this->siteId( $item->getSiteId(), \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) );
392
				$stmt->bind( $idx++, $date ); // ctime
393
			}
394
395
			$stmt->execute()->finish();
396
397
			if( $id === null )
398
			{
399
				/** mshop/cms/manager/newid/mysql
400
				 * Retrieves the ID generated by the database when inserting a new record
401
				 *
402
				 * @see mshop/cms/manager/newid/ansi
403
				 */
404
405
				/** mshop/cms/manager/newid/ansi
406
				 * Retrieves the ID generated by the database when inserting a new record
407
				 *
408
				 * As soon as a new record is inserted into the database table,
409
				 * the database server generates a new and unique identifier for
410
				 * that record. This ID can be used for retrieving, updating and
411
				 * deleting that specific record from the table again.
412
				 *
413
				 * For MySQL:
414
				 *  SELECT LAST_INSERT_ID()
415
				 * For PostgreSQL:
416
				 *  SELECT currval('seq_mcms_id')
417
				 * For SQL Server:
418
				 *  SELECT SCOPE_IDENTITY()
419
				 * For Oracle:
420
				 *  SELECT "seq_mcms_id".CURRVAL FROM DUAL
421
				 *
422
				 * There's no way to retrive the new ID by a SQL statements that
423
				 * fits for most database servers as they implement their own
424
				 * specific way.
425
				 *
426
				 * @param string SQL statement for retrieving the last inserted record ID
427
				 * @since 2020.10
428
				 * @category Developer
429
				 * @see mshop/cms/manager/insert/ansi
430
				 * @see mshop/cms/manager/update/ansi
431
				 * @see mshop/cms/manager/delete/ansi
432
				 * @see mshop/cms/manager/search/ansi
433
				 * @see mshop/cms/manager/count/ansi
434
				 */
435
				$path = 'mshop/cms/manager/newid';
436
				$id = $this->newId( $conn, $path );
437
			}
438
439
			$item->setId( $id );
440
441
		return $this->saveListItems( $item, 'cms', $fetch );
442
	}
443
444
445
	/**
446
	 * Removes multiple items.
447
	 *
448
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
449
	 * @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls
450
	 */
451
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
452
	{
453
		/** mshop/cms/manager/delete/mysql
454
		 * Deletes the items matched by the given IDs from the database
455
		 *
456
		 * @see mshop/cms/manager/delete/ansi
457
		 */
458
459
		/** mshop/cms/manager/delete/ansi
460
		 * Deletes the items matched by the given IDs from the database
461
		 *
462
		 * Removes the records specified by the given IDs from the cms database.
463
		 * The records must be from the site that is configured via the
464
		 * context item.
465
		 *
466
		 * The ":cond" placeholder is replaced by the name of the ID column and
467
		 * the given ID or list of IDs while the site ID is bound to the question
468
		 * mark.
469
		 *
470
		 * The SQL statement should conform to the ANSI standard to be
471
		 * compatible with most relational database systems. This also
472
		 * includes using double quotes for table and column names.
473
		 *
474
		 * @param string SQL statement for deleting items
475
		 * @since 2020.10
476
		 * @category Developer
477
		 * @see mshop/cms/manager/insert/ansi
478
		 * @see mshop/cms/manager/update/ansi
479
		 * @see mshop/cms/manager/newid/ansi
480
		 * @see mshop/cms/manager/search/ansi
481
		 * @see mshop/cms/manager/count/ansi
482
		 */
483
		$path = 'mshop/cms/manager/delete';
484
485
		return $this->deleteItemsBase( $itemIds, $path )->deleteRefItems( $itemIds );
486
	}
487
488
489
	/**
490
	 * Returns the item specified by its URL
491
	 *
492
	 * @param string $code URL of the item
493
	 * @param string[] $ref List of domains to fetch list items and referenced items for
494
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
495
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
496
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
497
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
498
	 */
499
	public function find( string $code, array $ref = [], string $domain = null, string $type = null,
500
		?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
501
	{
502
		return $this->findBase( array( 'cms.url' => $code ), $ref, $default );
503
	}
504
505
506
	/**
507
	 * Returns the cms item object specified by the given ID.
508
	 *
509
	 * @param string $id Id of the cms item
510
	 * @param string[] $ref List of domains to fetch list items and referenced items for
511
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
512
	 * @return \Aimeos\MShop\Cms\Item\Iface Returns the cms item of the given id
513
	 * @throws \Aimeos\MShop\Exception If item couldn't be found
514
	 */
515
	public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
516
	{
517
		return $this->getItemBase( 'cms.id', $id, $ref, $default );
518
	}
519
520
521
	/**
522
	 * Returns the available manager types
523
	 *
524
	 * @param bool $withsub Return also the resource type of sub-managers if true
525
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
526
	 */
527
	public function getResourceType( bool $withsub = true ) : array
528
	{
529
		$path = 'mshop/cms/manager/submanagers';
530
		return $this->getResourceTypeBase( 'cms', $path, ['lists'], $withsub );
531
	}
532
533
534
	/**
535
	 * Returns the attributes that can be used for searching.
536
	 *
537
	 * @param bool $withsub Return also attributes of sub-managers if true
538
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
539
	 */
540
	public function getSearchAttributes( bool $withsub = true ) : array
541
	{
542
		/** mshop/cms/manager/submanagers
543
		 * List of manager names that can be instantiated by the cms manager
544
		 *
545
		 * Managers provide a generic interface to the underlying storage.
546
		 * Each manager has or can have sub-managers caring about particular
547
		 * aspects. Each of these sub-managers can be instantiated by its
548
		 * parent manager using the getSubManager() method.
549
		 *
550
		 * The search keys from sub-managers can be normally used in the
551
		 * manager as well. It allows you to search for items of the manager
552
		 * using the search keys of the sub-managers to further limit the
553
		 * retrieved list of items.
554
		 *
555
		 * @param array List of sub-manager names
556
		 * @since 2020.10
557
		 * @category Developer
558
		 */
559
		$path = 'mshop/cms/manager/submanagers';
560
561
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
562
	}
563
564
565
	/**
566
	 * Searches for all cms items matching the given critera.
567
	 *
568
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria object
569
	 * @param string[] $ref List of domains to fetch list items and referenced items for
570
	 * @param int|null &$total Number of items that are available in total
571
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Cms\Item\Iface with ids as keys
572
	 */
573
	public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
574
	{
575
		$map = [];
576
		$context = $this->context();
577
		$conn = $context->db( $this->getResourceName() );
578
579
			$required = array( 'cms' );
580
581
			/** mshop/cms/manager/sitemode
582
			 * Mode how items from levels below or above in the site tree are handled
583
			 *
584
			 * By default, only items from the current site are fetched from the
585
			 * storage. If the ai-sites extension is installed, you can create a
586
			 * tree of sites. Then, this setting allows you to define for the
587
			 * whole cms domain if items from parent sites are inherited,
588
			 * sites from child sites are aggregated or both.
589
			 *
590
			 * Available constants for the site mode are:
591
			 * * 0 = only items from the current site
592
			 * * 1 = inherit items from parent sites
593
			 * * 2 = aggregate items from child sites
594
			 * * 3 = inherit and aggregate items at the same time
595
			 *
596
			 * You also need to set the mode in the locale manager
597
			 * (mshop/locale/manager/sitelevel) to one of the constants.
598
			 * If you set it to the same value, it will work as described but you
599
			 * can also use different modes. For example, if inheritance and
600
			 * aggregation is configured the locale manager but only inheritance
601
			 * in the domain manager because aggregating items makes no sense in
602
			 * this domain, then items wil be only inherited. Thus, you have full
603
			 * control over inheritance and aggregation in each domain.
604
			 *
605
			 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
606
			 * @category Developer
607
			 * @since 2020.10
608
			 * @see mshop/locale/manager/sitelevel
609
			 */
610
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE;
611
			$level = $context->config()->get( 'mshop/cms/manager/sitemode', $level );
612
613
			/** mshop/cms/manager/search/mysql
614
			 * Retrieves the records matched by the given criteria in the database
615
			 *
616
			 * @see mshop/cms/manager/search/ansi
617
			 */
618
619
			/** mshop/cms/manager/search/ansi
620
			 * Retrieves the records matched by the given criteria in the database
621
			 *
622
			 * Fetches the records matched by the given criteria from the cms
623
			 * database. The records must be from one of the sites that are
624
			 * configured via the context item. If the current site is part of
625
			 * a tree of sites, the SELECT statement can retrieve all records
626
			 * from the current site and the complete sub-tree of sites.
627
			 *
628
			 * As the records can normally be limited by criteria from sub-managers,
629
			 * their tables must be joined in the SQL context. This is done by
630
			 * using the "internaldeps" property from the definition of the ID
631
			 * column of the sub-managers. These internal dependencies specify
632
			 * the JOIN between the tables and the used columns for joining. The
633
			 * ":joins" placeholder is then replaced by the JOIN strings from
634
			 * the sub-managers.
635
			 *
636
			 * To limit the records matched, conditions can be added to the given
637
			 * criteria object. It can contain comparisons like column names that
638
			 * must match specific values which can be combined by AND, OR or NOT
639
			 * operators. The resulting string of SQL conditions replaces the
640
			 * ":cond" placeholder before the statement is sent to the database
641
			 * server.
642
			 *
643
			 * If the records that are retrieved should be ordered by one or more
644
			 * columns, the generated string of column / sort direction pairs
645
			 * replaces the ":order" placeholder. In case no ordering is required,
646
			 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
647
			 * markers is removed to speed up retrieving the records. Columns of
648
			 * sub-managers can also be used for ordering the result set but then
649
			 * no index can be used.
650
			 *
651
			 * The number of returned records can be limited and can start at any
652
			 * number between the begining and the end of the result set. For that
653
			 * the ":size" and ":start" placeholders are replaced by the
654
			 * corresponding values from the criteria object. The default values
655
			 * are 0 for the start and 100 for the size value.
656
			 *
657
			 * The SQL statement should conform to the ANSI standard to be
658
			 * compatible with most relational database systems. This also
659
			 * includes using double quotes for table and column names.
660
			 *
661
			 * @param string SQL statement for searching items
662
			 * @since 2020.10
663
			 * @category Developer
664
			 * @see mshop/cms/manager/insert/ansi
665
			 * @see mshop/cms/manager/update/ansi
666
			 * @see mshop/cms/manager/newid/ansi
667
			 * @see mshop/cms/manager/delete/ansi
668
			 * @see mshop/cms/manager/count/ansi
669
			 */
670
			$cfgPathSearch = 'mshop/cms/manager/search';
671
672
			/** mshop/cms/manager/count/mysql
673
			 * Counts the number of records matched by the given criteria in the database
674
			 *
675
			 * @see mshop/cms/manager/count/ansi
676
			 */
677
678
			/** mshop/cms/manager/count/ansi
679
			 * Counts the number of records matched by the given criteria in the database
680
			 *
681
			 * Counts all records matched by the given criteria from the cms
682
			 * database. The records must be from one of the sites that are
683
			 * configured via the context item. If the current site is part of
684
			 * a tree of sites, the statement can count all records from the
685
			 * current site and the complete sub-tree of sites.
686
			 *
687
			 * As the records can normally be limited by criteria from sub-managers,
688
			 * their tables must be joined in the SQL context. This is done by
689
			 * using the "internaldeps" property from the definition of the ID
690
			 * column of the sub-managers. These internal dependencies specify
691
			 * the JOIN between the tables and the used columns for joining. The
692
			 * ":joins" placeholder is then replaced by the JOIN strings from
693
			 * the sub-managers.
694
			 *
695
			 * To limit the records matched, conditions can be added to the given
696
			 * criteria object. It can contain comparisons like column names that
697
			 * must match specific values which can be combined by AND, OR or NOT
698
			 * operators. The resulting string of SQL conditions replaces the
699
			 * ":cond" placeholder before the statement is sent to the database
700
			 * server.
701
			 *
702
			 * Both, the strings for ":joins" and for ":cond" are the same as for
703
			 * the "search" SQL statement.
704
			 *
705
			 * Contrary to the "search" statement, it doesn't return any records
706
			 * but instead the number of records that have been found. As counting
707
			 * thousands of records can be a long running task, the maximum number
708
			 * of counted records is limited for performance reasons.
709
			 *
710
			 * The SQL statement should conform to the ANSI standard to be
711
			 * compatible with most relational database systems. This also
712
			 * includes using double quotes for table and column names.
713
			 *
714
			 * @param string SQL statement for counting items
715
			 * @since 2020.10
716
			 * @category Developer
717
			 * @see mshop/cms/manager/insert/ansi
718
			 * @see mshop/cms/manager/update/ansi
719
			 * @see mshop/cms/manager/newid/ansi
720
			 * @see mshop/cms/manager/delete/ansi
721
			 * @see mshop/cms/manager/search/ansi
722
			 */
723
			$cfgPathCount = 'mshop/cms/manager/count';
724
725
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
726
727
			while( ( $row = $results->fetch() ) !== null ) {
728
				$map[$row['cms.id']] = $row;
729
			}
730
731
		return $this->buildItems( $map, $ref, 'cms' );
732
	}
733
734
735
	/**
736
	 * Returns a new manager for cms extensions
737
	 *
738
	 * @param string $manager Name of the sub manager type in lower case
739
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
740
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g types, lists etc.
741
	 */
742
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
743
	{
744
		return $this->getSubManagerBase( 'cms', $manager, $name );
745
	}
746
747
748
	/**
749
	 * Creates a filter object.
750
	 *
751
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
752
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
753
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
754
	 */
755
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
756
	{
757
		if( $default === true ) {
758
			return $this->filterBase( 'cms' );
759
		}
760
761
		return parent::filter();
762
	}
763
764
765
	/**
766
	 * Creates a new cms item instance.
767
	 *
768
	 * @param array $values Associative list of key/value pairs
769
	 * @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems List of list items
770
	 * @param \Aimeos\MShop\Common\Item\Iface $refItems List of referenced items
771
	 * @return \Aimeos\MShop\Cms\Item\Iface New cms item
772
	 */
773
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [] ) : \Aimeos\MShop\Common\Item\Iface
774
	{
775
		return new \Aimeos\MShop\Cms\Item\Standard( $values, $listItems, $refItems );
776
	}
777
}
778