Passed
Push — master ( c46287...9f1c00 )
by Aimeos
05:19
created

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