Passed
Push — master ( bfd2b7...b98f34 )
by Aimeos
04:16
created

Standard   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 37
c 0
b 0
f 0
dl 0
loc 103
rs 10

5 Methods

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