Passed
Push — master ( 44c1d8...6b9f69 )
by Aimeos
16:18
created

Standard::getSiteConditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2023
7
 * @package MShop
8
 * @subpackage Locale
9
 */
10
11
12
namespace Aimeos\MShop\Locale\Manager\Language;
13
14
15
/**
16
 * Default implementation for managing languages.
17
 *
18
 * @package MShop
19
 * @subpackage Locale
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Manager\Base
23
	implements \Aimeos\MShop\Locale\Manager\Language\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
24
{
25
	private array $searchConfig = array(
26
		'locale.language.id' => array(
27
			'code' => 'locale.language.id',
28
			'internalcode' => 'mlocla."id"',
29
			'internaldeps' => array( 'LEFT JOIN "mshop_locale_language" AS mlocla ON (mloc."langid" = mlocla."id")' ),
30
			'label' => 'Language ID',
31
			'public' => false,
32
		),
33
		'locale.language.label' => array(
34
			'code' => 'locale.language.label',
35
			'internalcode' => 'mlocla."label"',
36
			'label' => 'Language label',
37
		),
38
		'locale.language.code' => array(
39
			'code' => 'locale.language.code',
40
			'internalcode' => 'mlocla."id"',
41
			'label' => 'Language code',
42
		),
43
		'locale.language.status' => array(
44
			'code' => 'locale.language.status',
45
			'internalcode' => 'mlocla."status"',
46
			'label' => 'Language status',
47
			'type' => 'int',
48
		),
49
		'locale.language.ctime' => array(
50
			'code' => 'locale.language.ctime',
51
			'internalcode' => 'mlocla."ctime"',
52
			'label' => 'Language create date/time',
53
			'type' => 'datetime',
54
			'public' => false,
55
		),
56
		'locale.language.mtime' => array(
57
			'code' => 'locale.language.mtime',
58
			'internalcode' => 'mlocla."mtime"',
59
			'label' => 'Language modify date/time',
60
			'type' => 'datetime',
61
			'public' => false,
62
		),
63
		'locale.language.editor' => array(
64
			'code' => 'locale.language.editor',
65
			'internalcode' => 'mlocla."editor"',
66
			'label' => 'Language editor',
67
			'public' => false,
68
		),
69
	);
70
71
72
	/**
73
	 * Initializes the object.
74
	 *
75
	 * @param \Aimeos\MShop\ContextIface $context Context object
76
	 */
77
	public function __construct( \Aimeos\MShop\ContextIface $context )
78
	{
79
		parent::__construct( $context );
80
81
		/** mshop/locale/manager/resource
82
		 * Name of the database connection resource to use
83
		 *
84
		 * You can configure a different database connection for each data domain
85
		 * and if no such connection name exists, the "db" connection will be used.
86
		 * It's also possible to use the same database connection for different
87
		 * data domains by configuring the same connection name using this setting.
88
		 *
89
		 * @param string Database connection name
90
		 * @since 2023.04
91
		 */
92
		$this->setResourceName( $context->config()->get( 'mshop/locale/manager/resource', 'db-locale' ) );
93
	}
94
95
96
	/**
97
	 * Removes old entries from the storage.
98
	 *
99
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
100
	 * @return \Aimeos\MShop\Locale\Manager\Language\Iface Manager object for chaining method calls
101
	 */
102
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
103
	{
104
		return $this;
105
	}
106
107
108
	/**
109
	 * Creates a new empty item instance
110
	 *
111
	 * @param array $values Values the item should be initialized with
112
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface New locale language item object
113
	 */
114
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
115
	{
116
		try {
117
			$values['locale.language.siteid'] = $values['locale.language.siteid'] ?? $this->context()->locale()->getSiteId();
118
		} catch( \Exception $e ) {} // if no locale item is available
119
120
		return $this->createItemBase( $values );
121
	}
122
123
124
	/**
125
	 * Saves the language object to the storage.
126
	 *
127
	 * @param \Aimeos\MShop\Locale\Item\Language\Iface $item Language object
128
	 * @param bool $fetch True if the new ID should be returned in the item
129
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface $item Updated item including the generated ID
130
	 */
131
	protected function saveItem( \Aimeos\MShop\Locale\Item\Language\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Locale\Item\Language\Iface
132
	{
133
		if( !$item->isModified() ) {
134
			return $item;
135
		}
136
137
		$context = $this->context();
138
		$conn = $context->db( $this->getResourceName() );
139
140
		$id = $item->getId();
141
		$date = date( 'Y-m-d H:i:s' );
142
		$columns = $this->object()->getSaveAttributes();
143
144
		if( $id === null )
145
		{
146
			/** mshop/locale/manager/language/insert/mysql
147
			 * Inserts a new language record into the database table
148
			 *
149
			 * @see mshop/locale/manager/language/insert/ansi
150
			 */
151
152
			/** mshop/locale/manager/language/insert/ansi
153
			 * Inserts a new language record into the database table
154
			 *
155
			 * The SQL statement must be a string suitable for being used as
156
			 * prepared statement. It must include question marks for binding
157
			 * the values from the language item to the statement before they are
158
			 * sent to the database server. The number of question marks must
159
			 * be the same as the number of columns listed in the INSERT
160
			 * statement. The order of the columns must correspond to the
161
			 * order in the save() method, so the correct values are
162
			 * bound to the columns.
163
			 *
164
			 * The SQL statement should conform to the ANSI standard to be
165
			 * compatible with most relational database systems. This also
166
			 * includes using double quotes for table and column names.
167
			 *
168
			 * @param string SQL statement for inserting records
169
			 * @since 2014.03
170
			 * @category Developer
171
			 * @see mshop/locale/manager/language/update/ansi
172
			 * @see mshop/locale/manager/language/delete/ansi
173
			 * @see mshop/locale/manager/language/search/ansi
174
			 * @see mshop/locale/manager/language/count/ansi
175
			 */
176
			$path = 'mshop/locale/manager/language/insert';
177
			$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

177
			$sql = $this->addSqlColumns( array_keys( $columns ), /** @scrutinizer ignore-type */ $this->getSqlConfig( $path ) );
Loading history...
178
		}
179
		else
180
		{
181
			/** mshop/locale/manager/language/update/mysql
182
			 * Updates an existing language record in the database
183
			 *
184
			 * @see mshop/locale/manager/language/update/ansi
185
			 */
186
187
			/** mshop/locale/manager/language/update/ansi
188
			 * Updates an existing language record in the database
189
			 *
190
			 * The SQL statement must be a string suitable for being used as
191
			 * prepared statement. It must include question marks for binding
192
			 * the values from the language item to the statement before they are
193
			 * sent to the database server. The order of the columns must
194
			 * correspond to the order in the save() method, so the
195
			 * correct values are bound to the columns.
196
			 *
197
			 * The SQL statement should conform to the ANSI standard to be
198
			 * compatible with most relational database systems. This also
199
			 * includes using double quotes for table and column names.
200
			 *
201
			 * @param string SQL statement for updating records
202
			 * @since 2014.03
203
			 * @category Developer
204
			 * @see mshop/locale/manager/language/insert/ansi
205
			 * @see mshop/locale/manager/language/delete/ansi
206
			 * @see mshop/locale/manager/language/search/ansi
207
			 * @see mshop/locale/manager/language/count/ansi
208
			 */
209
			$path = 'mshop/locale/manager/language/update';
210
			$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false );
211
		}
212
213
		$idx = 1;
214
		$stmt = $this->getCachedStatement( $conn, $path, $sql );
215
216
		foreach( $columns as $name => $entry ) {
217
			$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
218
		}
219
220
		$stmt->bind( $idx++, $item->getLabel() );
221
		$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
222
		$stmt->bind( $idx++, $date ); // mtime
223
		$stmt->bind( $idx++, $context->editor() );
224
		// code and ID are identical after saving and ID is the flag to detect updates or inserts
225
		$stmt->bind( $idx++, $item->getCode() );
226
227
		if( $id === null ) {
228
			$stmt->bind( $idx++, $date ); // ctime
229
		}
230
231
		$stmt->execute()->finish();
232
233
		$item->setId( $item->getCode() ); // set modified flag to false
234
235
		return $item;
236
	}
237
238
239
	/**
240
	 * Removes multiple items.
241
	 *
242
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
243
	 * @return \Aimeos\MShop\Locale\Manager\Language\Iface Manager object for chaining method calls
244
	 */
245
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
246
	{
247
		/** mshop/locale/manager/language/delete/mysql
248
		 * Deletes the items matched by the given IDs from the database
249
		 *
250
		 * @see mshop/locale/manager/language/delete/ansi
251
		 */
252
253
		/** mshop/locale/manager/language/delete/ansi
254
		 * Deletes the items matched by the given IDs from the database
255
		 *
256
		 * Removes the language records specified by the given IDs from the
257
		 * locale database. The records must be from the site that is configured
258
		 * via the context item.
259
		 *
260
		 * The ":cond" placeholder is replaced by the name of the ID column and
261
		 * the given ID or list of IDs while the site ID is bound to the question
262
		 * mark.
263
		 *
264
		 * The SQL statement should conform to the ANSI standard to be
265
		 * compatible with most relational database systems. This also
266
		 * includes using double quotes for table and column names.
267
		 *
268
		 * @param string SQL statement for deleting items
269
		 * @since 2014.03
270
		 * @category Developer
271
		 * @see mshop/locale/manager/language/insert/ansi
272
		 * @see mshop/locale/manager/language/update/ansi
273
		 * @see mshop/locale/manager/language/search/ansi
274
		 * @see mshop/locale/manager/language/count/ansi
275
		 */
276
		$path = 'mshop/locale/manager/language/delete';
277
278
		return $this->deleteItemsBase( $itemIds, $path, false );
279
	}
280
281
282
	/**
283
	 * Create a Language object from a given Language ID/Key.
284
	 *
285
	 * @param string $id Language id to create the Language object
286
	 * @param string[] $ref List of domains to fetch list items and referenced items for
287
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Returns the language item of the given id
288
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
289
	 * @throws \Aimeos\Base\DB\Exception If language object couldn't be fetched
290
	 * @throws \Aimeos\MShop\Exception If item couldn't be found
291
	 */
292
	public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
293
	{
294
		return $this->getItemBase( 'locale.language.id', $id, $ref, $default );
295
	}
296
297
298
	/**
299
	 * Returns the available manager types
300
	 *
301
	 * @param bool $withsub Return also the resource type of sub-managers if true
302
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
303
	 */
304
	public function getResourceType( bool $withsub = true ) : array
305
	{
306
		$path = 'mshop/locale/manager/language/submanagers';
307
		return $this->getResourceTypeBase( 'locale/language', $path, [], $withsub );
308
	}
309
310
311
	/**
312
	 * Returns the attributes that can be used for searching.
313
	 *
314
	 * @param bool $withsub Return also attributes of sub-managers if true
315
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
316
	 */
317
	public function getSearchAttributes( bool $withsub = true ) : array
318
	{
319
		/** mshop/locale/manager/language/submanagers
320
		 * List of manager names that can be instantiated by the locale language manager
321
		 *
322
		 * Managers provide a generic interface to the underlying storage.
323
		 * Each manager has or can have sub-managers caring about particular
324
		 * aspects. Each of these sub-managers can be instantiated by its
325
		 * parent manager using the getSubManager() method.
326
		 *
327
		 * The search keys from sub-managers can be normally used in the
328
		 * manager as well. It allows you to search for items of the manager
329
		 * using the search keys of the sub-managers to further limit the
330
		 * retrieved list of items.
331
		 *
332
		 * @param array List of sub-manager names
333
		 * @since 2014.03
334
		 * @category Developer
335
		 */
336
		$path = 'mshop/locale/manager/language/submanagers';
337
338
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
339
	}
340
341
342
	/**
343
	 * Returns a new sub manager of the given type and name.
344
	 *
345
	 * @param string $manager Name of the sub manager type in lower case
346
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
347
	 * @return \Aimeos\MShop\Common\Manager\Iface manager
348
	 */
349
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
350
	{
351
		/** mshop/locale/manager/language/name
352
		 * Class name of the used locale language manager implementation
353
		 *
354
		 * Each default locale language manager can be replaced by an alternative imlementation.
355
		 * To use this implementation, you have to set the last part of the class
356
		 * name as configuration value so the manager factory knows which class it
357
		 * has to instantiate.
358
		 *
359
		 * For example, if the name of the default class is
360
		 *
361
		 *  \Aimeos\MShop\Locale\Manager\Language\Standard
362
		 *
363
		 * and you want to replace it with your own version named
364
		 *
365
		 *  \Aimeos\MShop\Locale\Manager\Language\Mylanguage
366
		 *
367
		 * then you have to set the this configuration option:
368
		 *
369
		 *  mshop/locale/manager/language/name = Mylanguage
370
		 *
371
		 * The value is the last part of your own class name and it's case sensitive,
372
		 * so take care that the configuration value is exactly named like the last
373
		 * part of the class name.
374
		 *
375
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
376
		 * characters are possible! You should always start the last part of the class
377
		 * name with an upper case character and continue only with lower case characters
378
		 * or numbers. Avoid chamel case names like "MyLanguage"!
379
		 *
380
		 * @param string Last part of the class name
381
		 * @since 2014.03
382
		 * @category Developer
383
		 */
384
385
		/** mshop/locale/manager/language/decorators/excludes
386
		 * Excludes decorators added by the "common" option from the locale language manager
387
		 *
388
		 * Decorators extend the functionality of a class by adding new aspects
389
		 * (e.g. log what is currently done), executing the methods of the underlying
390
		 * class only in certain conditions (e.g. only for logged in users) or
391
		 * modify what is returned to the caller.
392
		 *
393
		 * This option allows you to remove a decorator added via
394
		 * "mshop/common/manager/decorators/default" before they are wrapped
395
		 * around the locale language manager.
396
		 *
397
		 *  mshop/locale/manager/language/decorators/excludes = array( 'decorator1' )
398
		 *
399
		 * This would remove the decorator named "decorator1" from the list of
400
		 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
401
		 * "mshop/common/manager/decorators/default" for the locale language manager.
402
		 *
403
		 * @param array List of decorator names
404
		 * @since 2014.03
405
		 * @category Developer
406
		 * @see mshop/common/manager/decorators/default
407
		 * @see mshop/locale/manager/language/decorators/global
408
		 * @see mshop/locale/manager/language/decorators/local
409
		 */
410
411
		/** mshop/locale/manager/language/decorators/global
412
		 * Adds a list of globally available decorators only to the locale language manager
413
		 *
414
		 * Decorators extend the functionality of a class by adding new aspects
415
		 * (e.g. log what is currently done), executing the methods of the underlying
416
		 * class only in certain conditions (e.g. only for logged in users) or
417
		 * modify what is returned to the caller.
418
		 *
419
		 * This option allows you to wrap global decorators
420
		 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the locale language
421
		 * manager.
422
		 *
423
		 *  mshop/locale/manager/language/decorators/global = array( 'decorator1' )
424
		 *
425
		 * This would add the decorator named "decorator1" defined by
426
		 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the locale
427
		 * language manager.
428
		 *
429
		 * @param array List of decorator names
430
		 * @since 2014.03
431
		 * @category Developer
432
		 * @see mshop/common/manager/decorators/default
433
		 * @see mshop/locale/manager/language/decorators/excludes
434
		 * @see mshop/locale/manager/language/decorators/local
435
		 */
436
437
		/** mshop/locale/manager/language/decorators/local
438
		 * Adds a list of local decorators only to the locale language manager
439
		 *
440
		 * Decorators extend the functionality of a class by adding new aspects
441
		 * (e.g. log what is currently done), executing the methods of the underlying
442
		 * class only in certain conditions (e.g. only for logged in users) or
443
		 * modify what is returned to the caller.
444
		 *
445
		 * This option allows you to wrap local decorators
446
		 * ("\Aimeos\MShop\Locale\Manager\Language\Decorator\*") around the locale
447
		 * language manager.
448
		 *
449
		 *  mshop/locale/manager/language/decorators/local = array( 'decorator2' )
450
		 *
451
		 * This would add the decorator named "decorator2" defined by
452
		 * "\Aimeos\MShop\Locale\Manager\Language\Decorator\Decorator2" only to the
453
		 * locale language manager.
454
		 *
455
		 * @param array List of decorator names
456
		 * @since 2014.03
457
		 * @category Developer
458
		 * @see mshop/common/manager/decorators/default
459
		 * @see mshop/locale/manager/language/decorators/excludes
460
		 * @see mshop/locale/manager/language/decorators/global
461
		 */
462
463
		return $this->getSubManagerBase( 'locale', 'language/' . $manager, $name );
464
	}
465
466
467
	/**
468
	 * Returns the item specified by its code and domain/type if necessary
469
	 *
470
	 * @param string $code Code of the item
471
	 * @param string[] $ref List of domains to fetch list items and referenced items for
472
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
473
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
474
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
475
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
476
	 */
477
	public function find( string $code, array $ref = [], string $domain = null, string $type = null,
478
		?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
479
	{
480
		return $this->findBase( array( 'locale.language.id' => $code ), $ref, $default );
481
	}
482
483
484
	/**
485
	 * Searches for language items matching the given criteria.
486
	 *
487
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria object
488
	 * @param string[] $ref List of domains to fetch list items and referenced items for
489
	 * @param int|null &$total Number of items that are available in total
490
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Locale\Item\Language\Iface with ids as keys
491
	 */
492
	public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
493
	{
494
		$items = [];
495
		$context = $this->context();
496
		$conn = $context->db( $this->getResourceName() );
497
498
		$required = ['locale.language'];
499
500
		/** mshop/locale/manager/language/search/mysql
501
		 * Retrieves the records matched by the given criteria in the database
502
		 *
503
		 * @see mshop/locale/manager/language/search/ansi
504
		 */
505
506
		/** mshop/locale/manager/language/search/ansi
507
		 * Retrieves the records matched by the given criteria in the database
508
		 *
509
		 * Fetches the records matched by the given criteria from the attribute
510
		 * database. The records must be from one of the sites that are
511
		 * configured via the context item. If the current site is part of
512
		 * a tree of sites, the SELECT statement can retrieve all records
513
		 * from the current site and the complete sub-tree of sites.
514
		 *
515
		 * As the records can normally be limited by criteria from sub-managers,
516
		 * their tables must be joined in the SQL context. This is done by
517
		 * using the "internaldeps" property from the definition of the ID
518
		 * column of the sub-managers. These internal dependencies specify
519
		 * the JOIN between the tables and the used columns for joining. The
520
		 * ":joins" placeholder is then replaced by the JOIN strings from
521
		 * the sub-managers.
522
		 *
523
		 * To limit the records matched, conditions can be added to the given
524
		 * criteria object. It can contain comparisons like column names that
525
		 * must match specific values which can be combined by AND, OR or NOT
526
		 * operators. The resulting string of SQL conditions replaces the
527
		 * ":cond" placeholder before the statement is sent to the database
528
		 * server.
529
		 *
530
		 * If the records that are retrieved should be ordered by one or more
531
		 * columns, the generated string of column / sort direction pairs
532
		 * replaces the ":order" placeholder. In case no ordering is required,
533
		 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
534
		 * markers is removed to speed up retrieving the records. Columns of
535
		 * sub-managers can also be used for ordering the result set but then
536
		 * no index can be used.
537
		 *
538
		 * The number of returned records can be limited and can start at any
539
		 * number between the begining and the end of the result set. For that
540
		 * the ":size" and ":start" placeholders are replaced by the
541
		 * corresponding values from the criteria object. The default values
542
		 * are 0 for the start and 100 for the size value.
543
		 *
544
		 * The SQL statement should conform to the ANSI standard to be
545
		 * compatible with most relational database systems. This also
546
		 * includes using double quotes for table and column names.
547
		 *
548
		 * @param string SQL statement for searching items
549
		 * @since 2014.03
550
		 * @category Developer
551
		 * @see mshop/locale/manager/language/insert/ansi
552
		 * @see mshop/locale/manager/language/update/ansi
553
		 * @see mshop/locale/manager/language/delete/ansi
554
		 * @see mshop/locale/manager/language/count/ansi
555
		 */
556
		$cfgPathSearch = 'mshop/locale/manager/language/search';
557
558
				/** mshop/locale/manager/language/count/mysql
559
		 * Counts the number of records matched by the given criteria in the database
560
		 *
561
		 * @see mshop/locale/manager/language/count/ansi
562
		 */
563
564
		/** mshop/locale/manager/language/count/ansi
565
		 * Counts the number of records matched by the given criteria in the database
566
		 *
567
		 * Counts all records matched by the given criteria from the attribute
568
		 * database. The records must be from one of the sites that are
569
		 * configured via the context item. If the current site is part of
570
		 * a tree of sites, the statement can count all records from the
571
		 * current site and the complete sub-tree of sites.
572
		 *
573
		 * As the records can normally be limited by criteria from sub-managers,
574
		 * their tables must be joined in the SQL context. This is done by
575
		 * using the "internaldeps" property from the definition of the ID
576
		 * column of the sub-managers. These internal dependencies specify
577
		 * the JOIN between the tables and the used columns for joining. The
578
		 * ":joins" placeholder is then replaced by the JOIN strings from
579
		 * the sub-managers.
580
		 *
581
		 * To limit the records matched, conditions can be added to the given
582
		 * criteria object. It can contain comparisons like column names that
583
		 * must match specific values which can be combined by AND, OR or NOT
584
		 * operators. The resulting string of SQL conditions replaces the
585
		 * ":cond" placeholder before the statement is sent to the database
586
		 * server.
587
		 *
588
		 * Both, the strings for ":joins" and for ":cond" are the same as for
589
		 * the "search" SQL statement.
590
		 *
591
		 * Contrary to the "search" statement, it doesn't return any records
592
		 * but instead the number of records that have been found. As counting
593
		 * thousands of records can be a long running task, the maximum number
594
		 * of counted records is limited for performance reasons.
595
		 *
596
		 * The SQL statement should conform to the ANSI standard to be
597
		 * compatible with most relational database systems. This also
598
		 * includes using double quotes for table and column names.
599
		 *
600
		 * @param string SQL statement for counting items
601
		 * @since 2014.03
602
		 * @category Developer
603
		 * @see mshop/locale/manager/language/insert/ansi
604
		 * @see mshop/locale/manager/language/update/ansi
605
		 * @see mshop/locale/manager/language/delete/ansi
606
		 * @see mshop/locale/manager/language/search/ansi
607
		 */
608
		$cfgPathCount = 'mshop/locale/manager/language/count';
609
610
		$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total );
611
612
		while( ( $row = $results->fetch() ) !== null )
613
		{
614
			if( $item = $this->applyFilter( $this->createItemBase( $row ) ) ) {
615
				$items[$row['locale.language.id']] = $item;
616
			}
617
		}
618
619
		return map( $items );
620
	}
621
622
623
	/**
624
	 * Creates a filter object.
625
	 *
626
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
627
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
628
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
629
	 */
630
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
631
	{
632
		return $this->filterBase( 'locale.language', $default );
633
	}
634
635
636
	/**
637
	 * Create new item object initialized with given parameters.
638
	 *
639
	 * @param array $data Associative list of item key/value pairs
640
	 * @return \Aimeos\MShop\Locale\Item\Language\Iface Language item
641
	 */
642
	protected function createItemBase( array $data = [] ) : \Aimeos\MShop\Locale\Item\Language\Iface
643
	{
644
		return new \Aimeos\MShop\Locale\Item\Language\Standard( $data );
645
	}
646
647
648
	/**
649
	 * Returns the site coditions for the search request
650
	 *
651
	 * @param string[] $keys Sorted list of criteria keys
652
	 * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes Associative list of search keys and criteria attribute items as values
653
	 * @param int $sitelevel Site level constant from \Aimeos\MShop\Locale\Manager\Base
654
	 * @return \Aimeos\Base\Criteria\Expression\Iface[] List of search conditions
655
	 */
656
	protected function getSiteConditions( array $keys, array $attributes, int $sitelevel ) : array
657
	{
658
		return [];
659
	}
660
}
661