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

Standard::getSubManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 111
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 111
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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