Standard::saveItem()   B
last analyzed

Complexity

Conditions 7
Paths 108

Size

Total Lines 171
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
nc 108
nop 2
dl 0
loc 171
c 1
b 0
f 0
cc 7
rs 8.2933

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
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
	use \Aimeos\MShop\Common\Manager\ListsRef\Traits;
25
26
27
	private $searchConfig = array(
28
		'cms.id' => array(
29
			'code' => 'cms.id',
30
			'internalcode' => 'mcms."id"',
31
			'label' => 'ID',
32
			'type' => 'integer',
33
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
34
			'public' => false,
35
		),
36
		'cms.siteid' => array(
37
			'code' => 'cms.siteid',
38
			'internalcode' => 'mcms."siteid"',
39
			'label' => 'Site ID',
40
			'type' => 'string',
41
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
42
			'public' => false,
43
		),
44
		'cms.url' => array(
45
			'code' => 'cms.url',
46
			'internalcode' => 'mcms."url"',
47
			'label' => 'Type',
48
			'type' => 'string',
49
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
50
		),
51
		'cms.label' => array(
52
			'code' => 'cms.label',
53
			'internalcode' => 'mcms."label"',
54
			'label' => 'Label',
55
			'type' => 'string',
56
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
57
		),
58
		'cms.status' => array(
59
			'code' => 'cms.status',
60
			'internalcode' => 'mcms."status"',
61
			'label' => 'Status',
62
			'type' => 'integer',
63
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
64
		),
65
		'cms.ctime' => array(
66
			'code' => 'cms.ctime',
67
			'internalcode' => 'mcms."ctime"',
68
			'label' => 'create date/time',
69
			'type' => 'datetime',
70
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
71
			'public' => false,
72
		),
73
		'cms.mtime' => array(
74
			'code' => 'cms.mtime',
75
			'internalcode' => 'mcms."mtime"',
76
			'label' => 'modify date/time',
77
			'type' => 'datetime',
78
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
79
			'public' => false,
80
		),
81
		'cms.editor' => array(
82
			'code' => 'cms.editor',
83
			'internalcode' => 'mcms."editor"',
84
			'label' => 'editor',
85
			'type' => 'string',
86
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
87
			'public' => false,
88
		),
89
		'cms:has' => array(
90
			'code' => 'cms:has()',
91
			'internalcode' => ':site AND :key AND mcmsli."id"',
92
			'internaldeps' => ['LEFT JOIN "mshop_cms_list" AS mcmsli ON ( mcmsli."parentid" = mcms."id" )'],
93
			'label' => 'Cms has list item, parameter(<domain>[,<list type>[,<reference ID>)]]',
94
			'type' => 'null',
95
			'internaltype' => 'null',
96
			'public' => false,
97
		),
98
	);
99
100
101
	/**
102
	 * Initializes the object.
103
	 *
104
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
105
	 */
106
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
107
	{
108
		parent::__construct( $context );
109
110
		$this->setResourceName( 'db-cms' );
111
		$this->languageId = $context->getLocale()->getLanguageId();
0 ignored issues
show
Bug Best Practice introduced by
The property languageId does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
112
113
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE;
114
		$level = $context->getConfig()->get( 'mshop/cms/manager/sitemode', $level );
115
116
117
		$this->searchConfig['cms:has']['function'] = function( &$source, array $params ) use ( $level ) {
118
119
			$keys = [];
120
121
			foreach( (array) ( $params[1] ?? '' ) as $type ) {
122
				foreach( (array) ( $params[2] ?? '' ) as $id ) {
123
					$keys[] = $params[0] . '|' . ( $type ? $type . '|' : '' ) . $id;
124
				}
125
			}
126
127
			$sitestr = $this->getSiteString( 'mcmsli."siteid"', $level );
128
			$keystr = $this->toExpression( 'mcmsli."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' );
129
			$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );
130
131
			return $params;
132
		};
133
	}
134
135
136
	/**
137
	 * Removes old entries from the storage.
138
	 *
139
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
140
	 * @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls
141
	 */
142
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
143
	{
144
		$path = 'mshop/cms/manager/submanagers';
145
		foreach( $this->getContext()->getConfig()->get( $path, ['lists'] ) as $domain ) {
146
			$this->getObject()->getSubManager( $domain )->clear( $siteids );
147
		}
148
149
		return $this->clearBase( $siteids, 'mshop/cms/manager/delete' );
150
	}
151
152
153
	/**
154
	 * Creates a new empty item instance
155
	 *
156
	 * @param array $values Values the item should be initialized with
157
	 * @return \Aimeos\MShop\Cms\Item\Iface New cms item object
158
	 */
159
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
160
	{
161
		$values['cms.siteid'] = $this->getContext()->getLocale()->getSiteId();
162
		return $this->createItemBase( $values );
163
	}
164
165
166
	/**
167
	 * Updates or adds a cms item object.
168
	 * This method doesn't update the type string that belongs to the type ID
169
	 *
170
	 * @param \Aimeos\MShop\Cms\Item\Iface $item Cms item which should be saved
171
	 * @param bool $fetch True if the new ID should be returned in the item
172
	 * @return \Aimeos\MShop\Cms\Item\Iface Updated item including the generated ID
173
	 */
174
	public function saveItem( \Aimeos\MShop\Cms\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Cms\Item\Iface
175
	{
176
		if( !$item->isModified() ) {
177
			return $this->saveListItems( $item, 'cms', $fetch );
178
		}
179
180
		$context = $this->getContext();
181
182
		$dbm = $context->getDatabaseManager();
183
		$dbname = $this->getResourceName();
184
		$conn = $dbm->acquire( $dbname );
185
186
		try
187
		{
188
			$id = $item->getId();
189
			$date = date( 'Y-m-d H:i:s' );
190
			$columns = $this->getObject()->getSaveAttributes();
191
192
			if( $id === null )
193
			{
194
				/** mshop/cms/manager/insert/mysql
195
				 * Inserts a new cms record into the database table
196
				 *
197
				 * @see mshop/cms/manager/insert/ansi
198
				 */
199
200
				/** mshop/cms/manager/insert/ansi
201
				 * Inserts a new cms record into the database table
202
				 *
203
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
204
				 * the database and the newly created ID retrieved afterwards
205
				 * using the "newid" SQL statement.
206
				 *
207
				 * The SQL statement must be a string suitable for being used as
208
				 * prepared statement. It must include question marks for binding
209
				 * the values from the cms item to the statement before they are
210
				 * sent to the database server. The number of question marks must
211
				 * be the same as the number of columns listed in the INSERT
212
				 * statement. The order of the columns must correspond to the
213
				 * order in the save() method, so the correct values are
214
				 * bound to the columns.
215
				 *
216
				 * The SQL statement should conform to the ANSI standard to be
217
				 * compatible with most relational database systems. This also
218
				 * includes using double quotes for table and column names.
219
				 *
220
				 * @param string SQL statement for inserting records
221
				 * @since 2020.10
222
				 * @category Developer
223
				 * @see mshop/cms/manager/update/ansi
224
				 * @see mshop/cms/manager/newid/ansi
225
				 * @see mshop/cms/manager/delete/ansi
226
				 * @see mshop/cms/manager/search/ansi
227
				 * @see mshop/cms/manager/count/ansi
228
				 */
229
				$path = 'mshop/cms/manager/insert';
230
				$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

230
				$sql = $this->addSqlColumns( array_keys( $columns ), /** @scrutinizer ignore-type */ $this->getSqlConfig( $path ) );
Loading history...
231
			}
232
			else
233
			{
234
				/** mshop/cms/manager/update/mysql
235
				 * Updates an existing cms record in the database
236
				 *
237
				 * @see mshop/cms/manager/update/ansi
238
				 */
239
240
				/** mshop/cms/manager/update/ansi
241
				 * Updates an existing cms record in the database
242
				 *
243
				 * Items which already have an ID (i.e. the ID is not NULL) will
244
				 * be updated in the database.
245
				 *
246
				 * The SQL statement must be a string suitable for being used as
247
				 * prepared statement. It must include question marks for binding
248
				 * the values from the cms item to the statement before they are
249
				 * sent to the database server. The order of the columns must
250
				 * correspond to the order in the save() method, so the
251
				 * correct values are bound to the columns.
252
				 *
253
				 * The SQL statement should conform to the ANSI standard to be
254
				 * compatible with most relational database systems. This also
255
				 * includes using double quotes for table and column names.
256
				 *
257
				 * @param string SQL statement for updating records
258
				 * @since 2020.10
259
				 * @category Developer
260
				 * @see mshop/cms/manager/insert/ansi
261
				 * @see mshop/cms/manager/newid/ansi
262
				 * @see mshop/cms/manager/delete/ansi
263
				 * @see mshop/cms/manager/search/ansi
264
				 * @see mshop/cms/manager/count/ansi
265
				 */
266
				$path = 'mshop/cms/manager/update';
267
				$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false );
268
			}
269
270
			$idx = 1;
271
			$stmt = $this->getCachedStatement( $conn, $path, $sql );
272
273
			foreach( $columns as $name => $entry ) {
274
				$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() );
275
			}
276
277
			$stmt->bind( $idx++, $item->getUrl() );
278
			$stmt->bind( $idx++, $item->getLabel() );
279
			$stmt->bind( $idx++, $item->getStatus(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
280
			$stmt->bind( $idx++, $date ); // mtime
281
			$stmt->bind( $idx++, $context->getEditor() );
282
			$stmt->bind( $idx++, $context->getLocale()->getSiteId() );
283
284
			if( $id !== null ) {
285
				$stmt->bind( $idx++, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
286
			} else {
287
				$stmt->bind( $idx++, $date ); // ctime
288
			}
289
290
			$stmt->execute()->finish();
291
292
			if( $id === null )
293
			{
294
				/** mshop/cms/manager/newid/mysql
295
				 * Retrieves the ID generated by the database when inserting a new record
296
				 *
297
				 * @see mshop/cms/manager/newid/ansi
298
				 */
299
300
				/** mshop/cms/manager/newid/ansi
301
				 * Retrieves the ID generated by the database when inserting a new record
302
				 *
303
				 * As soon as a new record is inserted into the database table,
304
				 * the database server generates a new and unique identifier for
305
				 * that record. This ID can be used for retrieving, updating and
306
				 * deleting that specific record from the table again.
307
				 *
308
				 * For MySQL:
309
				 *  SELECT LAST_INSERT_ID()
310
				 * For PostgreSQL:
311
				 *  SELECT currval('seq_mcms_id')
312
				 * For SQL Server:
313
				 *  SELECT SCOPE_IDENTITY()
314
				 * For Oracle:
315
				 *  SELECT "seq_mcms_id".CURRVAL FROM DUAL
316
				 *
317
				 * There's no way to retrive the new ID by a SQL statements that
318
				 * fits for most database servers as they implement their own
319
				 * specific way.
320
				 *
321
				 * @param string SQL statement for retrieving the last inserted record ID
322
				 * @since 2020.10
323
				 * @category Developer
324
				 * @see mshop/cms/manager/insert/ansi
325
				 * @see mshop/cms/manager/update/ansi
326
				 * @see mshop/cms/manager/delete/ansi
327
				 * @see mshop/cms/manager/search/ansi
328
				 * @see mshop/cms/manager/count/ansi
329
				 */
330
				$path = 'mshop/cms/manager/newid';
331
				$id = $this->newId( $conn, $path );
332
			}
333
334
			$item->setId( $id );
335
336
			$dbm->release( $conn, $dbname );
337
		}
338
		catch( \Exception $e )
339
		{
340
			$dbm->release( $conn, $dbname );
341
			throw $e;
342
		}
343
344
		return $this->saveListItems( $item, 'cms', $fetch );
345
	}
346
347
348
	/**
349
	 * Removes multiple items.
350
	 *
351
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
352
	 * @return \Aimeos\MShop\Cms\Manager\Iface Manager object for chaining method calls
353
	 */
354
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
355
	{
356
		/** mshop/cms/manager/delete/mysql
357
		 * Deletes the items matched by the given IDs from the database
358
		 *
359
		 * @see mshop/cms/manager/delete/ansi
360
		 */
361
362
		/** mshop/cms/manager/delete/ansi
363
		 * Deletes the items matched by the given IDs from the database
364
		 *
365
		 * Removes the records specified by the given IDs from the cms database.
366
		 * The records must be from the site that is configured via the
367
		 * context item.
368
		 *
369
		 * The ":cond" placeholder is replaced by the name of the ID column and
370
		 * the given ID or list of IDs while the site ID is bound to the question
371
		 * mark.
372
		 *
373
		 * The SQL statement should conform to the ANSI standard to be
374
		 * compatible with most relational database systems. This also
375
		 * includes using double quotes for table and column names.
376
		 *
377
		 * @param string SQL statement for deleting items
378
		 * @since 2020.10
379
		 * @category Developer
380
		 * @see mshop/cms/manager/insert/ansi
381
		 * @see mshop/cms/manager/update/ansi
382
		 * @see mshop/cms/manager/newid/ansi
383
		 * @see mshop/cms/manager/search/ansi
384
		 * @see mshop/cms/manager/count/ansi
385
		 */
386
		$path = 'mshop/cms/manager/delete';
387
388
		return $this->deleteItemsBase( $itemIds, $path )->deleteRefItems( $itemIds );
389
	}
390
391
392
	/**
393
	 * Returns the item specified by its URL
394
	 *
395
	 * @param string $code URL of the item
396
	 * @param string[] $ref List of domains to fetch list items and referenced items for
397
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
398
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
399
	 * @param bool $default True to add default criteria
400
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
401
	 */
402
	public function find( string $code, array $ref = [], string $domain = null, string $type = null,
403
		bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
404
	{
405
		return $this->findBase( array( 'cms.url' => $code ), $ref, $default );
406
	}
407
408
409
	/**
410
	 * Returns the cms item object specified by the given ID.
411
	 *
412
	 * @param string $id Id of the cms item
413
	 * @param string[] $ref List of domains to fetch list items and referenced items for
414
	 * @param bool $default Add default criteria
415
	 * @return \Aimeos\MShop\Cms\Item\Iface Returns the cms item of the given id
416
	 * @throws \Aimeos\MShop\Exception If item couldn't be found
417
	 */
418
	public function get( string $id, array $ref = [], bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
419
	{
420
		return $this->getItemBase( 'cms.id', $id, $ref, $default );
421
	}
422
423
424
	/**
425
	 * Returns the available manager types
426
	 *
427
	 * @param bool $withsub Return also the resource type of sub-managers if true
428
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
429
	 */
430
	public function getResourceType( bool $withsub = true ) : array
431
	{
432
		$path = 'mshop/cms/manager/submanagers';
433
		return $this->getResourceTypeBase( 'cms', $path, ['lists'], $withsub );
434
	}
435
436
437
	/**
438
	 * Returns the attributes that can be used for searching.
439
	 *
440
	 * @param bool $withsub Return also attributes of sub-managers if true
441
	 * @return \Aimeos\MW\Criteria\Attribute\Iface[] List of search attribute items
442
	 */
443
	public function getSearchAttributes( bool $withsub = true ) : array
444
	{
445
		/** mshop/cms/manager/submanagers
446
		 * List of manager names that can be instantiated by the cms manager
447
		 *
448
		 * Managers provide a generic interface to the underlying storage.
449
		 * Each manager has or can have sub-managers caring about particular
450
		 * aspects. Each of these sub-managers can be instantiated by its
451
		 * parent manager using the getSubManager() method.
452
		 *
453
		 * The search keys from sub-managers can be normally used in the
454
		 * manager as well. It allows you to search for items of the manager
455
		 * using the search keys of the sub-managers to further limit the
456
		 * retrieved list of items.
457
		 *
458
		 * @param array List of sub-manager names
459
		 * @since 2020.10
460
		 * @category Developer
461
		 */
462
		$path = 'mshop/cms/manager/submanagers';
463
464
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
465
	}
466
467
468
	/**
469
	 * Searches for all cms items matching the given critera.
470
	 *
471
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
472
	 * @param string[] $ref List of domains to fetch list items and referenced items for
473
	 * @param int|null &$total Number of items that are available in total
474
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Cms\Item\Iface with ids as keys
475
	 */
476
	public function search( \Aimeos\MW\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
477
	{
478
		$map = [];
479
		$context = $this->getContext();
480
481
		$dbm = $context->getDatabaseManager();
482
		$dbname = $this->getResourceName();
483
		$conn = $dbm->acquire( $dbname );
484
485
		try
486
		{
487
			$required = array( 'cms' );
488
489
			/** mshop/cms/manager/sitemode
490
			 * Mode how items from levels below or above in the site tree are handled
491
			 *
492
			 * By default, only items from the current site are fetched from the
493
			 * storage. If the ai-sites extension is installed, you can create a
494
			 * tree of sites. Then, this setting allows you to define for the
495
			 * whole cms domain if items from parent sites are inherited,
496
			 * sites from child sites are aggregated or both.
497
			 *
498
			 * Available constants for the site mode are:
499
			 * * 0 = only items from the current site
500
			 * * 1 = inherit items from parent sites
501
			 * * 2 = aggregate items from child sites
502
			 * * 3 = inherit and aggregate items at the same time
503
			 *
504
			 * You also need to set the mode in the locale manager
505
			 * (mshop/locale/manager/sitelevel) to one of the constants.
506
			 * If you set it to the same value, it will work as described but you
507
			 * can also use different modes. For example, if inheritance and
508
			 * aggregation is configured the locale manager but only inheritance
509
			 * in the domain manager because aggregating items makes no sense in
510
			 * this domain, then items wil be only inherited. Thus, you have full
511
			 * control over inheritance and aggregation in each domain.
512
			 *
513
			 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
514
			 * @category Developer
515
			 * @since 2020.10
516
			 * @see mshop/locale/manager/sitelevel
517
			 */
518
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ONE;
519
			$level = $context->getConfig()->get( 'mshop/cms/manager/sitemode', $level );
520
521
			/** mshop/cms/manager/search/mysql
522
			 * Retrieves the records matched by the given criteria in the database
523
			 *
524
			 * @see mshop/cms/manager/search/ansi
525
			 */
526
527
			/** mshop/cms/manager/search/ansi
528
			 * Retrieves the records matched by the given criteria in the database
529
			 *
530
			 * Fetches the records matched by the given criteria from the cms
531
			 * database. The records must be from one of the sites that are
532
			 * configured via the context item. If the current site is part of
533
			 * a tree of sites, the SELECT statement can retrieve all records
534
			 * from the current site and the complete sub-tree of sites.
535
			 *
536
			 * As the records can normally be limited by criteria from sub-managers,
537
			 * their tables must be joined in the SQL context. This is done by
538
			 * using the "internaldeps" property from the definition of the ID
539
			 * column of the sub-managers. These internal dependencies specify
540
			 * the JOIN between the tables and the used columns for joining. The
541
			 * ":joins" placeholder is then replaced by the JOIN strings from
542
			 * the sub-managers.
543
			 *
544
			 * To limit the records matched, conditions can be added to the given
545
			 * criteria object. It can contain comparisons like column names that
546
			 * must match specific values which can be combined by AND, OR or NOT
547
			 * operators. The resulting string of SQL conditions replaces the
548
			 * ":cond" placeholder before the statement is sent to the database
549
			 * server.
550
			 *
551
			 * If the records that are retrieved should be ordered by one or more
552
			 * columns, the generated string of column / sort direction pairs
553
			 * replaces the ":order" placeholder. In case no ordering is required,
554
			 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
555
			 * markers is removed to speed up retrieving the records. Columns of
556
			 * sub-managers can also be used for ordering the result set but then
557
			 * no index can be used.
558
			 *
559
			 * The number of returned records can be limited and can start at any
560
			 * number between the begining and the end of the result set. For that
561
			 * the ":size" and ":start" placeholders are replaced by the
562
			 * corresponding values from the criteria object. The default values
563
			 * are 0 for the start and 100 for the size value.
564
			 *
565
			 * The SQL statement should conform to the ANSI standard to be
566
			 * compatible with most relational database systems. This also
567
			 * includes using double quotes for table and column names.
568
			 *
569
			 * @param string SQL statement for searching items
570
			 * @since 2020.10
571
			 * @category Developer
572
			 * @see mshop/cms/manager/insert/ansi
573
			 * @see mshop/cms/manager/update/ansi
574
			 * @see mshop/cms/manager/newid/ansi
575
			 * @see mshop/cms/manager/delete/ansi
576
			 * @see mshop/cms/manager/count/ansi
577
			 */
578
			$cfgPathSearch = 'mshop/cms/manager/search';
579
580
			/** mshop/cms/manager/count/mysql
581
			 * Counts the number of records matched by the given criteria in the database
582
			 *
583
			 * @see mshop/cms/manager/count/ansi
584
			 */
585
586
			/** mshop/cms/manager/count/ansi
587
			 * Counts the number of records matched by the given criteria in the database
588
			 *
589
			 * Counts all records matched by the given criteria from the cms
590
			 * database. The records must be from one of the sites that are
591
			 * configured via the context item. If the current site is part of
592
			 * a tree of sites, the statement can count all records from the
593
			 * current site and the complete sub-tree of sites.
594
			 *
595
			 * As the records can normally be limited by criteria from sub-managers,
596
			 * their tables must be joined in the SQL context. This is done by
597
			 * using the "internaldeps" property from the definition of the ID
598
			 * column of the sub-managers. These internal dependencies specify
599
			 * the JOIN between the tables and the used columns for joining. The
600
			 * ":joins" placeholder is then replaced by the JOIN strings from
601
			 * the sub-managers.
602
			 *
603
			 * To limit the records matched, conditions can be added to the given
604
			 * criteria object. It can contain comparisons like column names that
605
			 * must match specific values which can be combined by AND, OR or NOT
606
			 * operators. The resulting string of SQL conditions replaces the
607
			 * ":cond" placeholder before the statement is sent to the database
608
			 * server.
609
			 *
610
			 * Both, the strings for ":joins" and for ":cond" are the same as for
611
			 * the "search" SQL statement.
612
			 *
613
			 * Contrary to the "search" statement, it doesn't return any records
614
			 * but instead the number of records that have been found. As counting
615
			 * thousands of records can be a long running task, the maximum number
616
			 * of counted records is limited for performance reasons.
617
			 *
618
			 * The SQL statement should conform to the ANSI standard to be
619
			 * compatible with most relational database systems. This also
620
			 * includes using double quotes for table and column names.
621
			 *
622
			 * @param string SQL statement for counting items
623
			 * @since 2020.10
624
			 * @category Developer
625
			 * @see mshop/cms/manager/insert/ansi
626
			 * @see mshop/cms/manager/update/ansi
627
			 * @see mshop/cms/manager/newid/ansi
628
			 * @see mshop/cms/manager/delete/ansi
629
			 * @see mshop/cms/manager/search/ansi
630
			 */
631
			$cfgPathCount = 'mshop/cms/manager/count';
632
633
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
634
635
			while( ( $row = $results->fetch() ) !== null ) {
636
				$map[$row['cms.id']] = $row;
637
			}
638
639
			$dbm->release( $conn, $dbname );
640
		}
641
		catch( \Exception $e )
642
		{
643
			$dbm->release( $conn, $dbname );
644
			throw $e;
645
		}
646
647
		return $this->buildItems( $map, $ref, 'cms' );
648
	}
649
650
651
	/**
652
	 * Returns a new manager for cms extensions
653
	 *
654
	 * @param string $manager Name of the sub manager type in lower case
655
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
656
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g types, lists etc.
657
	 */
658
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
659
	{
660
		return $this->getSubManagerBase( 'cms', $manager, $name );
661
	}
662
663
664
	/**
665
	 * Creates a filter object.
666
	 *
667
	 * @param bool $default Add default criteria
668
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
669
	 * @return \Aimeos\MW\Criteria\Iface Returns the filter object
670
	 */
671
	public function filter( bool $default = false, bool $site = false ) : \Aimeos\MW\Criteria\Iface
672
	{
673
		if( $default === true ) {
674
			return $this->filterBase( 'cms' );
675
		}
676
677
		return parent::filter();
678
	}
679
680
681
	/**
682
	 * Creates a new cms item instance.
683
	 *
684
	 * @param array $values Associative list of key/value pairs
685
	 * @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems List of list items
686
	 * @param \Aimeos\MShop\Common\Item\Iface $refItems List of referenced items
687
	 * @return \Aimeos\MShop\Cms\Item\Iface New cms item
688
	 */
689
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [] ) : \Aimeos\MShop\Common\Item\Iface
690
	{
691
		return new \Aimeos\MShop\Cms\Item\Standard( $values, $listItems, $refItems );
692
	}
693
}
694