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