Passed
Push — master ( 8c3433...5fb848 )
by Aimeos
16:39
created

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