Completed
Push — master ( e4ad0a...d808c7 )
by Aimeos
10:17
created

Standard::getSubManager()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 113
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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