Passed
Push — master ( b98f34...b02400 )
by Aimeos
05:49 queued 01:38
created

Standard::getSearchAttributes()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 27
rs 9.3222
cc 5
nc 1
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Supplier
8
 */
9
10
11
namespace Aimeos\MShop\Supplier\Manager;
12
13
14
/**
15
 * Class \Aimeos\MShop\Supplier\Manager\Standard.
16
 *
17
 * @package MShop
18
 * @subpackage Supplier
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Manager\Base
22
	implements \Aimeos\MShop\Supplier\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
23
{
24
	private array $cacheTags = [];
25
26
27
	/**
28
	 * Commits the running database transaction on the connection identified by the given name
29
	 *
30
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
31
	 */
32
	public function commit() : \Aimeos\MShop\Common\Manager\Iface
33
	{
34
		parent::commit();
35
36
		$this->context()->cache()->deleteByTags( $this->cacheTags );
37
		$this->cacheTags = [];
38
39
		return $this;
40
	}
41
42
43
	/**
44
	 * Creates a new empty item instance
45
	 *
46
	 * @param array $values Values the item should be initialized with
47
	 * @return \Aimeos\MShop\Supplier\Item\Iface New supplier item object
48
	 */
49
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
50
	{
51
		$values['supplier.siteid'] = $values['supplier.siteid'] ?? $this->context()->locale()->getSiteId();
52
53
		return new \Aimeos\MShop\Supplier\Item\Standard( 'supplier.', $values );
54
	}
55
56
57
	/**
58
	 * Removes multiple items.
59
	 *
60
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $items List of item objects or IDs of the items
61
	 * @return \Aimeos\MShop\Supplier\Manager\Iface Manager object for chaining method calls
62
	 */
63
	public function delete( $items ) : \Aimeos\MShop\Common\Manager\Iface
64
	{
65
		parent::delete( $items );
66
67
		$this->cacheTags = array_merge( $this->cacheTags, map( $items )->cast()->prefix( 'supplier-' )->all() );
68
69
		return $this;
70
	}
71
72
73
	/**
74
	 * Creates a filter object.
75
	 *
76
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
77
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
78
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
79
	 */
80
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
81
	{
82
		return $this->filterBase( 'supplier', $default );
83
	}
84
85
86
	/**
87
	 * Returns the item specified by its code and domain/type if necessary
88
	 *
89
	 * @param string $code Code of the item
90
	 * @param string[] $ref List of domains to fetch list items and referenced items for
91
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
92
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
93
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
94
	 * @return \Aimeos\MShop\Supplier\Item\Iface Item object
95
	 */
96
	public function find( string $code, array $ref = [], string $domain = null, string $type = null,
97
		?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
98
	{
99
		return $this->findBase( array( 'supplier.code' => $code ), $ref, $default );
100
	}
101
102
103
	/**
104
	 * Adds or updates an item object or a list of them.
105
	 *
106
	 * @param \Aimeos\Map|\Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface $items Item or list of items whose data should be saved
107
	 * @param bool $fetch True if the new ID should be returned in the item
108
	 * @return \Aimeos\Map|\Aimeos\MShop\Common\Item\Iface Saved item or items
109
	 */
110
	public function save( $items, bool $fetch = true )
111
	{
112
		$items = parent::save( $items, $fetch );
113
114
		if( ( $ids = map( $items )->getId()->filter() )->count() === map( $items )->count() ) {
115
			$this->cacheTags = array_merge( $this->cacheTags, map( $ids )->prefix( 'supplier-' )->all() );
116
		} else {
117
			$this->cacheTags[] = 'supplier';
118
		}
119
120
		return $items;
121
	}
122
123
124
	/**
125
	 * Returns the additional column/search definitions
126
	 *
127
	 * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
128
	 */
129
	public function getSaveAttributes() : array
130
	{
131
		return $this->createAttributes( [
132
			'supplier.label' => [
133
				'code' => 'supplier.label',
134
				'internalcode' => 'label',
135
				'label' => 'Label',
136
			],
137
			'supplier.code' => [
138
				'code' => 'supplier.code',
139
				'internalcode' => 'code',
140
				'label' => 'Code',
141
			],
142
			'supplier.position' => [
143
				'code' => 'supplier.position',
144
				'internalcode' => 'pos',
145
				'label' => 'Position',
146
				'type' => 'int',
147
			],
148
			'supplier.status' => [
149
				'code' => 'supplier.status',
150
				'internalcode' => 'status',
151
				'label' => 'Status',
152
				'type' => 'int',
153
			],
154
		] );
155
	}
156
157
158
	/**
159
	 * Returns the prefix for the item properties and search keys.
160
	 *
161
	 * @return string Prefix for the item properties and search keys
162
	 */
163
	protected function prefix() : string
164
	{
165
		return 'supplier.';
166
	}
167
168
169
	/** mshop/supplier/manager/resource
170
	 * Name of the database connection resource to use
171
	 *
172
	 * You can configure a different database connection for each data domain
173
	 * and if no such connection name exists, the "db" connection will be used.
174
	 * It's also possible to use the same database connection for different
175
	 * data domains by configuring the same connection name using this setting.
176
	 *
177
	 * @param string Database connection name
178
	 * @since 2023.04
179
	 */
180
181
	/** mshop/supplier/manager/name
182
	 * Class name of the used supplier manager implementation
183
	 *
184
	 * Each default manager can be replace by an alternative imlementation.
185
	 * To use this implementation, you have to set the last part of the class
186
	 * name as configuration value so the manager factory knows which class it
187
	 * has to instantiate.
188
	 *
189
	 * For example, if the name of the default class is
190
	 *
191
	 *  \Aimeos\MShop\Supplier\Manager\Standard
192
	 *
193
	 * and you want to replace it with your own version named
194
	 *
195
	 *  \Aimeos\MShop\Supplier\Manager\Mymanager
196
	 *
197
	 * then you have to set the this configuration option:
198
	 *
199
	 *  mshop/supplier/manager/name = Mymanager
200
	 *
201
	 * The value is the last part of your own class name and it's case sensitive,
202
	 * so take care that the configuration value is exactly named like the last
203
	 * part of the class name.
204
	 *
205
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
206
	 * characters are possible! You should always start the last part of the class
207
	 * name with an upper case character and continue only with lower case characters
208
	 * or numbers. Avoid chamel case names like "MyManager"!
209
	 *
210
	 * @param string Last part of the class name
211
	 * @since 2015.10
212
	 */
213
214
	/** mshop/supplier/manager/decorators/excludes
215
	 * Excludes decorators added by the "common" option from the supplier manager
216
	 *
217
	 * Decorators extend the functionality of a class by adding new aspects
218
	 * (e.g. log what is currently done), executing the methods of the underlying
219
	 * class only in certain conditions (e.g. only for logged in users) or
220
	 * modify what is returned to the caller.
221
	 *
222
	 * This option allows you to remove a decorator added via
223
	 * "mshop/common/manager/decorators/default" before they are wrapped
224
	 * around the supplier manager.
225
	 *
226
	 *  mshop/supplier/manager/decorators/excludes = array( 'decorator1' )
227
	 *
228
	 * This would remove the decorator named "decorator1" from the list of
229
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
230
	 * "mshop/common/manager/decorators/default" for the supplier manager.
231
	 *
232
	 * @param array List of decorator names
233
	 * @since 2015.10
234
	 * @see mshop/common/manager/decorators/default
235
	 * @see mshop/supplier/manager/decorators/global
236
	 * @see mshop/supplier/manager/decorators/local
237
	 */
238
239
	/** mshop/supplier/manager/decorators/global
240
	 * Adds a list of globally available decorators only to the supplier manager
241
	 *
242
	 * Decorators extend the functionality of a class by adding new aspects
243
	 * (e.g. log what is currently done), executing the methods of the underlying
244
	 * class only in certain conditions (e.g. only for logged in users) or
245
	 * modify what is returned to the caller.
246
	 *
247
	 * This option allows you to wrap global decorators
248
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the supplier manager.
249
	 *
250
	 *  mshop/supplier/manager/decorators/global = array( 'decorator1' )
251
	 *
252
	 * This would add the decorator named "decorator1" defined by
253
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the supplier
254
	 * manager.
255
	 *
256
	 * @param array List of decorator names
257
	 * @since 2015.10
258
	 * @see mshop/common/manager/decorators/default
259
	 * @see mshop/supplier/manager/decorators/excludes
260
	 * @see mshop/supplier/manager/decorators/local
261
	 */
262
263
	/** mshop/supplier/manager/decorators/local
264
	 * Adds a list of local decorators only to the supplier manager
265
	 *
266
	 * Decorators extend the functionality of a class by adding new aspects
267
	 * (e.g. log what is currently done), executing the methods of the underlying
268
	 * class only in certain conditions (e.g. only for logged in users) or
269
	 * modify what is returned to the caller.
270
	 *
271
	 * This option allows you to wrap local decorators
272
	 * ("\Aimeos\MShop\Supplier\Manager\Decorator\*") around the supplier manager.
273
	 *
274
	 *  mshop/supplier/manager/decorators/local = array( 'decorator2' )
275
	 *
276
	 * This would add the decorator named "decorator2" defined by
277
	 * "\Aimeos\MShop\Supplier\Manager\Decorator\Decorator2" only to the supplier
278
	 * manager.
279
	 *
280
	 * @param array List of decorator names
281
	 * @since 2015.10
282
	 * @see mshop/common/manager/decorators/default
283
	 * @see mshop/supplier/manager/decorators/excludes
284
	 * @see mshop/supplier/manager/decorators/global
285
	 */
286
287
	/** mshop/supplier/manager/submanagers
288
	 * List of manager names that can be instantiated by the supplier manager
289
	 *
290
	 * Managers provide a generic interface to the underlying storage.
291
	 * Each manager has or can have sub-managers caring about particular
292
	 * aspects. Each of these sub-managers can be instantiated by its
293
	 * parent manager using the getSubManager() method.
294
	 *
295
	 * The search keys from sub-managers can be normally used in the
296
	 * manager as well. It allows you to search for items of the manager
297
	 * using the search keys of the sub-managers to further limit the
298
	 * retrieved list of items.
299
	 *
300
	 * @param array List of sub-manager names
301
	 * @since 2015.10
302
	 */
303
304
	/** mshop/supplier/manager/delete/mysql
305
	 * Deletes the items matched by the given IDs from the database
306
	 *
307
	 * @see mshop/supplier/manager/delete/ansi
308
	 */
309
310
	/** mshop/supplier/manager/delete/ansi
311
	 * Deletes the items matched by the given IDs from the database
312
	 *
313
	 * Removes the records specified by the given IDs from the supplier database.
314
	 * The records must be from the site that is configured via the
315
	 * context item.
316
	 *
317
	 * The ":cond" placeholder is replaced by the name of the ID column and
318
	 * the given ID or list of IDs while the site ID is bound to the question
319
	 * mark.
320
	 *
321
	 * The SQL statement should conform to the ANSI standard to be
322
	 * compatible with most relational database systems. This also
323
	 * includes using double quotes for table and column names.
324
	 *
325
	 * @param string SQL statement for deleting items
326
	 * @since 2015.10
327
	 * @see mshop/supplier/manager/insert/ansi
328
	 * @see mshop/supplier/manager/update/ansi
329
	 * @see mshop/supplier/manager/newid/ansi
330
	 * @see mshop/supplier/manager/search/ansi
331
	 * @see mshop/supplier/manager/count/ansi
332
	 */
333
334
	/** mshop/supplier/manager/insert/mysql
335
	 * Inserts a new supplier record into the database table
336
	 *
337
	 * @see mshop/supplier/manager/insert/ansi
338
	 */
339
340
	/** mshop/supplier/manager/insert/ansi
341
	 * Inserts a new supplier record into the database table
342
	 *
343
	 * Items with no ID yet (i.e. the ID is NULL) will be created in
344
	 * the database and the newly created ID retrieved afterwards
345
	 * using the "newid" SQL statement.
346
	 *
347
	 * The SQL statement must be a string suitable for being used as
348
	 * prepared statement. It must include question marks for binding
349
	 * the values from the supplier item to the statement before they are
350
	 * sent to the database server. The number of question marks must
351
	 * be the same as the number of columns listed in the INSERT
352
	 * statement. The order of the columns must correspond to the
353
	 * order in the save() method, so the correct values are
354
	 * bound to the columns.
355
	 *
356
	 * The SQL statement should conform to the ANSI standard to be
357
	 * compatible with most relational database systems. This also
358
	 * includes using double quotes for table and column names.
359
	 *
360
	 * @param string SQL statement for inserting records
361
	 * @since 2015.10
362
	 * @see mshop/supplier/manager/update/ansi
363
	 * @see mshop/supplier/manager/newid/ansi
364
	 * @see mshop/supplier/manager/delete/ansi
365
	 * @see mshop/supplier/manager/search/ansi
366
	 * @see mshop/supplier/manager/count/ansi
367
	 */
368
369
	/** mshop/supplier/manager/update/mysql
370
	 * Updates an existing supplier record in the database
371
	 *
372
	 * @see mshop/supplier/manager/update/ansi
373
	 */
374
375
	/** mshop/supplier/manager/update/ansi
376
	 * Updates an existing supplier record in the database
377
	 *
378
	 * Items which already have an ID (i.e. the ID is not NULL) will
379
	 * be updated in the database.
380
	 *
381
	 * The SQL statement must be a string suitable for being used as
382
	 * prepared statement. It must include question marks for binding
383
	 * the values from the supplier item to the statement before they are
384
	 * sent to the database server. The order of the columns must
385
	 * correspond to the order in the save() method, so the
386
	 * correct values are bound to the columns.
387
	 *
388
	 * The SQL statement should conform to the ANSI standard to be
389
	 * compatible with most relational database systems. This also
390
	 * includes using double quotes for table and column names.
391
	 *
392
	 * @param string SQL statement for updating records
393
	 * @since 2015.10
394
	 * @see mshop/supplier/manager/insert/ansi
395
	 * @see mshop/supplier/manager/newid/ansi
396
	 * @see mshop/supplier/manager/delete/ansi
397
	 * @see mshop/supplier/manager/search/ansi
398
	 * @see mshop/supplier/manager/count/ansi
399
	 */
400
401
	/** mshop/supplier/manager/newid/mysql
402
	 * Retrieves the ID generated by the database when inserting a new record
403
	 *
404
	 * @see mshop/supplier/manager/newid/ansi
405
	 */
406
407
	/** mshop/supplier/manager/newid/ansi
408
	 * Retrieves the ID generated by the database when inserting a new record
409
	 *
410
	 * As soon as a new record is inserted into the database table,
411
	 * the database server generates a new and unique identifier for
412
	 * that record. This ID can be used for retrieving, updating and
413
	 * deleting that specific record from the table again.
414
	 *
415
	 * For MySQL:
416
	 *  SELECT LAST_INSERT_ID()
417
	 * For PostgreSQL:
418
	 *  SELECT currval('seq_msup_id')
419
	 * For SQL Server:
420
	 *  SELECT SCOPE_IDENTITY()
421
	 * For Oracle:
422
	 *  SELECT "seq_msup_id".CURRVAL FROM DUAL
423
	 *
424
	 * There's no way to retrive the new ID by a SQL statements that
425
	 * fits for most database servers as they implement their own
426
	 * specific way.
427
	 *
428
	 * @param string SQL statement for retrieving the last inserted record ID
429
	 * @since 2015.10
430
	 * @see mshop/supplier/manager/insert/ansi
431
	 * @see mshop/supplier/manager/update/ansi
432
	 * @see mshop/supplier/manager/delete/ansi
433
	 * @see mshop/supplier/manager/search/ansi
434
	 * @see mshop/supplier/manager/count/ansi
435
	 */
436
437
	/** mshop/supplier/manager/sitemode
438
	 * Mode how items from levels below or above in the site tree are handled
439
	 *
440
	 * By default, only items from the current site are fetched from the
441
	 * storage. If the ai-sites extension is installed, you can create a
442
	 * tree of sites. Then, this setting allows you to define for the
443
	 * whole supplier domain if items from parent sites are inherited,
444
	 * sites from child sites are aggregated or both.
445
	 *
446
	 * Available constants for the site mode are:
447
	 * * 0 = only items from the current site
448
	 * * 1 = inherit items from parent sites
449
	 * * 2 = aggregate items from child sites
450
	 * * 3 = inherit and aggregate items at the same time
451
	 *
452
	 * You also need to set the mode in the locale manager
453
	 * (mshop/locale/manager/sitelevel) to one of the constants.
454
	 * If you set it to the same value, it will work as described but you
455
	 * can also use different modes. For example, if inheritance and
456
	 * aggregation is configured the locale manager but only inheritance
457
	 * in the domain manager because aggregating items makes no sense in
458
	 * this domain, then items wil be only inherited. Thus, you have full
459
	 * control over inheritance and aggregation in each domain.
460
	 *
461
	 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
462
	 * @since 2018.01
463
	 * @see mshop/locale/manager/sitelevel
464
	 */
465
466
	/** mshop/supplier/manager/search/mysql
467
	 * Retrieves the records matched by the given criteria in the database
468
	 *
469
	 * @see mshop/supplier/manager/search/ansi
470
	 */
471
472
	/** mshop/supplier/manager/search/ansi
473
	 * Retrieves the records matched by the given criteria in the database
474
	 *
475
	 * Fetches the records matched by the given criteria from the supplier
476
	 * database. The records must be from one of the sites that are
477
	 * configured via the context item. If the current site is part of
478
	 * a tree of sites, the SELECT statement can retrieve all records
479
	 * from the current site and the complete sub-tree of sites.
480
	 *
481
	 * As the records can normally be limited by criteria from sub-managers,
482
	 * their tables must be joined in the SQL context. This is done by
483
	 * using the "internaldeps" property from the definition of the ID
484
	 * column of the sub-managers. These internal dependencies specify
485
	 * the JOIN between the tables and the used columns for joining. The
486
	 * ":joins" placeholder is then replaced by the JOIN strings from
487
	 * the sub-managers.
488
	 *
489
	 * To limit the records matched, conditions can be added to the given
490
	 * criteria object. It can contain comparisons like column names that
491
	 * must match specific values which can be combined by AND, OR or NOT
492
	 * operators. The resulting string of SQL conditions replaces the
493
	 * ":cond" placeholder before the statement is sent to the database
494
	 * server.
495
	 *
496
	 * If the records that are retrieved should be ordered by one or more
497
	 * columns, the generated string of column / sort direction pairs
498
	 * replaces the ":order" placeholder. Columns of
499
	 * sub-managers can also be used for ordering the result set but then
500
	 * no index can be used.
501
	 *
502
	 * The number of returned records can be limited and can start at any
503
	 * number between the begining and the end of the result set. For that
504
	 * the ":size" and ":start" placeholders are replaced by the
505
	 * corresponding values from the criteria object. The default values
506
	 * are 0 for the start and 100 for the size value.
507
	 *
508
	 * The SQL statement should conform to the ANSI standard to be
509
	 * compatible with most relational database systems. This also
510
	 * includes using double quotes for table and column names.
511
	 *
512
	 * @param string SQL statement for searching items
513
	 * @since 2015.10
514
	 * @see mshop/supplier/manager/insert/ansi
515
	 * @see mshop/supplier/manager/update/ansi
516
	 * @see mshop/supplier/manager/newid/ansi
517
	 * @see mshop/supplier/manager/delete/ansi
518
	 * @see mshop/supplier/manager/count/ansi
519
	 */
520
521
	/** mshop/supplier/manager/count/mysql
522
	 * Counts the number of records matched by the given criteria in the database
523
	 *
524
	 * @see mshop/supplier/manager/count/ansi
525
	 */
526
527
	/** mshop/supplier/manager/count/ansi
528
	 * Counts the number of records matched by the given criteria in the database
529
	 *
530
	 * Counts all records matched by the given criteria from the supplier
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 statement can count all records from the
534
	 * 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
	 * Both, the strings for ":joins" and for ":cond" are the same as for
552
	 * the "search" SQL statement.
553
	 *
554
	 * Contrary to the "search" statement, it doesn't return any records
555
	 * but instead the number of records that have been found. As counting
556
	 * thousands of records can be a long running task, the maximum number
557
	 * of counted records is limited for performance reasons.
558
	 *
559
	 * The SQL statement should conform to the ANSI standard to be
560
	 * compatible with most relational database systems. This also
561
	 * includes using double quotes for table and column names.
562
	 *
563
	 * @param string SQL statement for counting items
564
	 * @since 2015.10
565
	 * @see mshop/supplier/manager/insert/ansi
566
	 * @see mshop/supplier/manager/update/ansi
567
	 * @see mshop/supplier/manager/newid/ansi
568
	 * @see mshop/supplier/manager/delete/ansi
569
	 * @see mshop/supplier/manager/search/ansi
570
	 */
571
}
572