Passed
Push — master ( c663a5...2e9af5 )
by Aimeos
07:43
created

Standard::prefix()   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 0
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-2024
7
 * @package MShop
8
 * @subpackage Locale
9
 */
10
11
12
namespace Aimeos\MShop\Locale\Manager\Currency;
13
14
15
/**
16
 * Default implementation for managing currencies.
17
 *
18
 * @package MShop
19
 * @subpackage Locale
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Manager\Base
23
	implements \Aimeos\MShop\Locale\Manager\Currency\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
24
{
25
	private array $searchConfig = [
26
		'locale.currency.id' => [
27
			'label' => 'Currency ID',
28
			'internaldeps' => ['LEFT JOIN "mshop_locale_currency" AS mloccu ON (mloc."currencyid" = mloccu."id")'],
29
			'internalcode' => 'id',
30
			'public' => false,
31
		],
32
		'locale.currency.label' => [
33
			'label' => 'Currency label',
34
			'internalcode' => 'label',
35
		],
36
		'locale.currency.code' => [
37
			'label' => 'Currency code',
38
			'internalcode' => 'id',
39
		],
40
		'locale.currency.status' => [
41
			'label' => 'Currency status',
42
			'internalcode' => 'status',
43
			'type' => 'int',
44
		],
45
		'locale.currency.ctime' => [
46
			'label' => 'Currency create date/time',
47
			'internalcode' => 'ctime',
48
			'type' => 'datetime',
49
			'public' => false,
50
		],
51
		'locale.currency.mtime' => [
52
			'label' => 'Currency modify date/time',
53
			'internalcode' => 'mtime',
54
			'type' => 'datetime',
55
			'public' => false,
56
		],
57
		'locale.currency.editor' => [
58
			'label' => 'Currency editor',
59
			'internalcode' => 'editor',
60
			'public' => false,
61
		],
62
	];
63
64
65
	/**
66
	 * Removes old entries from the storage.
67
	 *
68
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
69
	 * @return \Aimeos\MShop\Locale\Manager\Iface Manager object for chaining method calls
70
	 */
71
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
72
	{
73
		return $this;
74
	}
75
76
77
	/**
78
	 * Creates a new empty item instance
79
	 *
80
	 * @param array $values Values the item should be initialized with
81
	 * @return \Aimeos\MShop\Locale\Item\Currency\Iface New locale currency item object
82
	 */
83
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
84
	{
85
		return new \Aimeos\MShop\Locale\Item\Currency\Standard( 'locale.currency.', $values );
86
	}
87
88
89
	/**
90
	 * Removes multiple items.
91
	 *
92
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
93
	 * @return \Aimeos\MShop\Locale\Manager\Currency\Iface Manager object for chaining method calls
94
	 */
95
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
96
	{
97
		/** mshop/locale/manager/currency/delete/mysql
98
		 * Deletes the items matched by the given IDs from the database
99
		 *
100
		 * @see mshop/locale/manager/currency/delete/ansi
101
		 */
102
103
		/** mshop/locale/manager/currency/delete/ansi
104
		 * Deletes the items matched by the given IDs from the database
105
		 *
106
		 * Removes the language records specified by the given IDs from the
107
		 * locale database. The records must be from the site that is configured
108
		 * via the context item.
109
		 *
110
		 * The ":cond" placeholder is replaced by the name of the ID column and
111
		 * the given ID or list of IDs while the site ID is bound to the question
112
		 * mark.
113
		 *
114
		 * The SQL statement should conform to the ANSI standard to be
115
		 * compatible with most relational database systems. This also
116
		 * includes using double quotes for table and column names.
117
		 *
118
		 * @param string SQL statement for deleting items
119
		 * @since 2015.10
120
		 * @see mshop/locale/manager/currency/insert/ansi
121
		 * @see mshop/locale/manager/currency/update/ansi
122
		 * @see mshop/locale/manager/currency/search/ansi
123
		 * @see mshop/locale/manager/currency/count/ansi
124
		 */
125
		$path = 'mshop/locale/manager/currency/delete';
126
127
		return $this->deleteItemsBase( $itemIds, $path, false );
128
	}
129
130
131
	/**
132
	 * Returns the item specified by its code and domain/type if necessary
133
	 *
134
	 * @param string $code Code of the item
135
	 * @param string[] $ref List of domains to fetch list items and referenced items for
136
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
137
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
138
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
139
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
140
	 */
141
	public function find( string $code, array $ref = [], string $domain = null, string $type = null,
142
		?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
143
	{
144
		return $this->findBase( array( 'locale.currency.id' => $code ), $ref, $default );
145
	}
146
147
148
	/**
149
	 * Creates a filter object.
150
	 *
151
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
152
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
153
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
154
	 */
155
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
156
	{
157
		return $this->filterBase( 'locale.currency', $default );
158
	}
159
160
161
	/**
162
	 * Returns the attributes that can be used for searching.
163
	 *
164
	 * @param bool $withsub Return also attributes of sub-managers if true
165
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
166
	 */
167
	public function getSearchAttributes( bool $withsub = true ) : array
168
	{
169
		/** mshop/locale/manager/currency/submanagers
170
		 * List of manager names that can be instantiated by the locale currency manager
171
		 *
172
		 * Managers provide a generic interface to the underlying storage.
173
		 * Each manager has or can have sub-managers caring about particular
174
		 * aspects. Each of these sub-managers can be instantiated by its
175
		 * parent manager using the getSubManager() method.
176
		 *
177
		 * The search keys from sub-managers can be normally used in the
178
		 * manager as well. It allows you to search for items of the manager
179
		 * using the search keys of the sub-managers to further limit the
180
		 * retrieved list of items.
181
		 *
182
		 * @param array List of sub-manager names
183
		 * @since 2015.10
184
		 */
185
		$path = 'mshop/locale/manager/currency/submanagers';
186
187
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
188
	}
189
190
191
	/**
192
	 * Returns the site coditions for the search request
193
	 *
194
	 * @param string[] $keys Sorted list of criteria keys
195
	 * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes Associative list of search keys and criteria attribute items as values
196
	 * @param int $sitelevel Site level constant from \Aimeos\MShop\Locale\Manager\Base
197
	 * @return \Aimeos\Base\Criteria\Expression\Iface[] List of search conditions
198
	 */
199
	protected function getSiteConditions( array $keys, array $attributes, int $sitelevel ) : array
200
	{
201
		return [];
202
	}
203
204
205
	/**
206
	 * Returns the prefix for the item properties and search keys.
207
	 *
208
	 * @return string Prefix for the item properties and search keys
209
	 */
210
	protected function prefix() : string
211
	{
212
		return 'locale.currency.';
213
	}
214
215
216
	/**
217
	 * Saves a currency item to the storage.
218
	 *
219
	 * @param \Aimeos\MShop\Locale\Item\Currency\Iface $item Currency item to save in the storage
220
	 * @param bool $fetch True if the new ID should be returned in the item
221
	 * @return \Aimeos\MShop\Locale\Item\Currency\Iface $item Updated item including the generated ID
222
	 */
223
	protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface
224
	{
225
		if( !$item->isModified() ) {
226
			return $item;
227
		}
228
229
		$context = $this->context();
230
		$conn = $context->db( $this->getResourceName() );
231
232
		$id = $item->getId();
233
		$columns = $this->object()->getSaveAttributes();
234
235
		if( $id === null )
236
		{
237
			/** mshop/locale/manager/currency/insert/mysql
238
			 * Inserts a new currency record into the database table
239
			 *
240
			 * @see mshop/locale/manager/currency/insert/ansi
241
			 */
242
243
			/** mshop/locale/manager/currency/insert/ansi
244
			 * Inserts a new currency record into the database table
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 currency item to the statement before they are
249
			 * sent to the database server. The number of question marks must
250
			 * be the same as the number of columns listed in the INSERT
251
			 * statement. The order of the columns must correspond to the
252
			 * order in the save() method, so the correct values are
253
			 * bound to the columns.
254
			 *
255
			 * The SQL statement should conform to the ANSI standard to be
256
			 * compatible with most relational database systems. This also
257
			 * includes using double quotes for table and column names.
258
			 *
259
			 * @param string SQL statement for inserting records
260
			 * @since 2015.10
261
			 * @see mshop/locale/manager/currency/update/ansi
262
			 * @see mshop/locale/manager/currency/delete/ansi
263
			 * @see mshop/locale/manager/currency/search/ansi
264
			 * @see mshop/locale/manager/currency/count/ansi
265
			 */
266
			$path = 'mshop/locale/manager/currency/insert';
267
			$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

267
			$sql = $this->addSqlColumns( array_keys( $columns ), /** @scrutinizer ignore-type */ $this->getSqlConfig( $path ) );
Loading history...
268
		}
269
		else
270
		{
271
			/** mshop/locale/manager/currency/update/mysql
272
			 * Updates an existing currency record in the database
273
			 *
274
			 * @see mshop/locale/manager/currency/update/ansi
275
			 */
276
277
			/** mshop/locale/manager/currency/update/ansi
278
			 * Updates an existing currency record in the database
279
			 *
280
			 * The SQL statement must be a string suitable for being used as
281
			 * prepared statement. It must include question marks for binding
282
			 * the values from the currency item to the statement before they are
283
			 * sent to the database server. The order of the columns must
284
			 * correspond to the order in the save() method, so the
285
			 * correct values are bound to the columns.
286
			 *
287
			 * The SQL statement should conform to the ANSI standard to be
288
			 * compatible with most relational database systems. This also
289
			 * includes using double quotes for table and column names.
290
			 *
291
			 * @param string SQL statement for updating records
292
			 * @since 2015.10
293
			 * @see mshop/locale/manager/currency/insert/ansi
294
			 * @see mshop/locale/manager/currency/delete/ansi
295
			 * @see mshop/locale/manager/currency/search/ansi
296
			 * @see mshop/locale/manager/currency/count/ansi
297
			 */
298
			$path = 'mshop/locale/manager/currency/update';
299
			$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false );
300
		}
301
302
		$idx = 1;
303
		$stmt = $this->getCachedStatement( $conn, $path, $sql );
304
305
		foreach( $columns as $name => $entry ) {
306
			$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
307
		}
308
309
		$stmt->bind( $idx++, $item->getLabel() );
310
		$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
311
		$stmt->bind( $idx++, $context->datetime() ); // mtime
312
		$stmt->bind( $idx++, $context->editor() );
313
		// bind ID but code and id are identical after saveing the stuff
314
		// id is the flag to detect updates or inserts!
315
		$stmt->bind( $idx++, $item->getCode() );
316
317
		if( $id === null ) {
318
			$stmt->bind( $idx++, $context->datetime() ); // ctime
319
		}
320
321
		$stmt->execute()->finish();
322
323
		$item->setId( $item->getCode() ); // set modified flag to false
324
325
		return $item;
326
	}
327
328
329
	/** mshop/locale/manager/currency/name
330
	 * Class name of the used locale currency manager implementation
331
	 *
332
	 * Each default locale currency manager can be replaced by an alternative imlementation.
333
	 * To use this implementation, you have to set the last part of the class
334
	 * name as configuration value so the manager factory knows which class it
335
	 * has to instantiate.
336
	 *
337
	 * For example, if the name of the default class is
338
	 *
339
	 *  \Aimeos\MShop\Locale\Manager\Currency\Standard
340
	 *
341
	 * and you want to replace it with your own version named
342
	 *
343
	 *  \Aimeos\MShop\Locale\Manager\Currency\Mycurrency
344
	 *
345
	 * then you have to set the this configuration option:
346
	 *
347
	 *  mshop/locale/manager/currency/name = Mycurrency
348
	 *
349
	 * The value is the last part of your own class name and it's case sensitive,
350
	 * so take care that the configuration value is exactly named like the last
351
	 * part of the class name.
352
	 *
353
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
354
	 * characters are possible! You should always start the last part of the class
355
	 * name with an upper case character and continue only with lower case characters
356
	 * or numbers. Avoid chamel case names like "MyCurrency"!
357
	 *
358
	 * @param string Last part of the class name
359
	 * @since 2015.10
360
	 */
361
362
	/** mshop/locale/manager/currency/decorators/excludes
363
	 * Excludes decorators added by the "common" option from the locale currency manager
364
	 *
365
	 * Decorators extend the functionality of a class by adding new aspects
366
	 * (e.g. log what is currently done), executing the methods of the underlying
367
	 * class only in certain conditions (e.g. only for logged in users) or
368
	 * modify what is returned to the caller.
369
	 *
370
	 * This option allows you to remove a decorator added via
371
	 * "mshop/common/manager/decorators/default" before they are wrapped
372
	 * around the locale currency manager.
373
	 *
374
	 *  mshop/locale/manager/currency/decorators/excludes = array( 'decorator1' )
375
	 *
376
	 * This would remove the decorator named "decorator1" from the list of
377
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
378
	 * "mshop/common/manager/decorators/default" for the locale currency manager.
379
	 *
380
	 * @param array List of decorator names
381
	 * @since 2015.10
382
	 * @see mshop/common/manager/decorators/default
383
	 * @see mshop/locale/manager/currency/decorators/global
384
	 * @see mshop/locale/manager/currency/decorators/local
385
	 */
386
387
	/** mshop/locale/manager/currency/decorators/global
388
	 * Adds a list of globally available decorators only to the locale currency manager
389
	 *
390
	 * Decorators extend the functionality of a class by adding new aspects
391
	 * (e.g. log what is currently done), executing the methods of the underlying
392
	 * class only in certain conditions (e.g. only for logged in users) or
393
	 * modify what is returned to the caller.
394
	 *
395
	 * This option allows you to wrap global decorators
396
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the locale currency
397
	 * manager.
398
	 *
399
	 *  mshop/locale/manager/currency/decorators/global = array( 'decorator1' )
400
	 *
401
	 * This would add the decorator named "decorator1" defined by
402
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the locale
403
	 * currency manager.
404
	 *
405
	 * @param array List of decorator names
406
	 * @since 2015.10
407
	 * @see mshop/common/manager/decorators/default
408
	 * @see mshop/locale/manager/currency/decorators/excludes
409
	 * @see mshop/locale/manager/currency/decorators/local
410
	 */
411
412
	/** mshop/locale/manager/currency/decorators/local
413
	 * Adds a list of local decorators only to the locale currency manager
414
	 *
415
	 * Decorators extend the functionality of a class by adding new aspects
416
	 * (e.g. log what is currently done), executing the methods of the underlying
417
	 * class only in certain conditions (e.g. only for logged in users) or
418
	 * modify what is returned to the caller.
419
	 *
420
	 * This option allows you to wrap local decorators
421
	 * ("\Aimeos\MShop\Locale\Manager\Currency\Decorator\*") around the locale
422
	 * currency manager.
423
	 *
424
	 *  mshop/locale/manager/currency/decorators/local = array( 'decorator2' )
425
	 *
426
	 * This would add the decorator named "decorator2" defined by
427
	 * "\Aimeos\MShop\Locale\Manager\Currency\Decorator\Decorator2" only to the
428
	 * locale currency manager.
429
	 *
430
	 * @param array List of decorator names
431
	 * @since 2015.10
432
	 * @see mshop/common/manager/decorators/default
433
	 * @see mshop/locale/manager/currency/decorators/excludes
434
	 * @see mshop/locale/manager/currency/decorators/global
435
	 */
436
437
	/** mshop/locale/manager/currency/search/mysql
438
	 * Retrieves the records matched by the given criteria in the database
439
	 *
440
	 * @see mshop/locale/manager/currency/search/ansi
441
	 */
442
443
	/** mshop/locale/manager/currency/search/ansi
444
	 * Retrieves the records matched by the given criteria in the database
445
	 *
446
	 * Fetches the records matched by the given criteria from the attribute
447
	 * database. The records must be from one of the sites that are
448
	 * configured via the context item. If the current site is part of
449
	 * a tree of sites, the SELECT statement can retrieve all records
450
	 * from the current site and the complete sub-tree of sites.
451
	 *
452
	 * As the records can normally be limited by criteria from sub-managers,
453
	 * their tables must be joined in the SQL context. This is done by
454
	 * using the "internaldeps" property from the definition of the ID
455
	 * column of the sub-managers. These internal dependencies specify
456
	 * the JOIN between the tables and the used columns for joining. The
457
	 * ":joins" placeholder is then replaced by the JOIN strings from
458
	 * the sub-managers.
459
	 *
460
	 * To limit the records matched, conditions can be added to the given
461
	 * criteria object. It can contain comparisons like column names that
462
	 * must match specific values which can be combined by AND, OR or NOT
463
	 * operators. The resulting string of SQL conditions replaces the
464
	 * ":cond" placeholder before the statement is sent to the database
465
	 * server.
466
	 *
467
	 * If the records that are retrieved should be ordered by one or more
468
	 * columns, the generated string of column / sort direction pairs
469
	 * replaces the ":order" placeholder. Columns of
470
	 * sub-managers can also be used for ordering the result set but then
471
	 * no index can be used.
472
	 *
473
	 * The number of returned records can be limited and can start at any
474
	 * number between the begining and the end of the result set. For that
475
	 * the ":size" and ":start" placeholders are replaced by the
476
	 * corresponding values from the criteria object. The default values
477
	 * are 0 for the start and 100 for the size value.
478
	 *
479
	 * The SQL statement should conform to the ANSI standard to be
480
	 * compatible with most relational database systems. This also
481
	 * includes using double quotes for table and column names.
482
	 *
483
	 * @param string SQL statement for searching items
484
	 * @since 2015.10
485
	 * @see mshop/locale/manager/currency/insert/ansi
486
	 * @see mshop/locale/manager/currency/update/ansi
487
	 * @see mshop/locale/manager/currency/delete/ansi
488
	 * @see mshop/locale/manager/currency/count/ansi
489
	 */
490
491
	/** mshop/locale/manager/currency/count/mysql
492
	 * Counts the number of records matched by the given criteria in the database
493
	 *
494
	 * @see mshop/locale/manager/currency/count/ansi
495
	 */
496
497
	/** mshop/locale/manager/currency/count/ansi
498
	 * Counts the number of records matched by the given criteria in the database
499
	 *
500
	 * Counts all records matched by the given criteria from the attribute
501
	 * database. The records must be from one of the sites that are
502
	 * configured via the context item. If the current site is part of
503
	 * a tree of sites, the statement can count all records from the
504
	 * current site and the complete sub-tree of sites.
505
	 *
506
	 * As the records can normally be limited by criteria from sub-managers,
507
	 * their tables must be joined in the SQL context. This is done by
508
	 * using the "internaldeps" property from the definition of the ID
509
	 * column of the sub-managers. These internal dependencies specify
510
	 * the JOIN between the tables and the used columns for joining. The
511
	 * ":joins" placeholder is then replaced by the JOIN strings from
512
	 * the sub-managers.
513
	 *
514
	 * To limit the records matched, conditions can be added to the given
515
	 * criteria object. It can contain comparisons like column names that
516
	 * must match specific values which can be combined by AND, OR or NOT
517
	 * operators. The resulting string of SQL conditions replaces the
518
	 * ":cond" placeholder before the statement is sent to the database
519
	 * server.
520
	 *
521
	 * Both, the strings for ":joins" and for ":cond" are the same as for
522
	 * the "search" SQL statement.
523
	 *
524
	 * Contrary to the "search" statement, it doesn't return any records
525
	 * but instead the number of records that have been found. As counting
526
	 * thousands of records can be a long running task, the maximum number
527
	 * of counted records is limited for performance reasons.
528
	 *
529
	 * The SQL statement should conform to the ANSI standard to be
530
	 * compatible with most relational database systems. This also
531
	 * includes using double quotes for table and column names.
532
	 *
533
	 * @param string SQL statement for counting items
534
	 * @since 2015.10
535
	 * @see mshop/locale/manager/currency/insert/ansi
536
	 * @see mshop/locale/manager/currency/update/ansi
537
	 * @see mshop/locale/manager/currency/delete/ansi
538
	 * @see mshop/locale/manager/currency/search/ansi
539
	 */
540
}
541