Passed
Push — master ( b98f34...b02400 )
by Aimeos
05:49 queued 01:38
created

Standard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 54
c 3
b 0
f 0
dl 0
loc 131
rs 10

5 Methods

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