Passed
Push — master ( fa0ea1...d7cab9 )
by Aimeos
05:50
created

Standard::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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