Passed
Push — master ( 29d5f6...586595 )
by Aimeos
04:48
created

src/MShop/Customer/Manager/Group/Standard.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Manager\Group;
12
13
14
/**
15
 * Default implementation of the customer group manager
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Manager\Base
22
	implements \Aimeos\MShop\Customer\Manager\Group\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
23
{
24
	private $searchConfig = array(
25
		'customer.group.id' => array(
26
			'code' => 'customer.group.id',
27
			'internalcode' => 'mcusgr."id"',
28
			'label' => 'Group ID',
29
			'type' => 'integer',
30
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
31
			'public' => false,
32
		),
33
		'customer.group.siteid' => array(
34
			'code' => 'customer.group.siteid',
35
			'internalcode' => 'mcusgr."siteid"',
36
			'label' => 'Group site ID',
37
			'type' => 'integer',
38
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
39
			'public' => false,
40
		),
41
		'customer.group.code' => array(
42
			'code' => 'customer.group.code',
43
			'internalcode' => 'mcusgr."code"',
44
			'label' => 'Group code',
45
			'type' => 'string',
46
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
47
		),
48
		'customer.group.label' => array(
49
			'code' => 'customer.group.label',
50
			'internalcode' => 'mcusgr."label"',
51
			'label' => 'Group label',
52
			'type' => 'string',
53
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
54
		),
55
		'customer.group.ctime' => array(
56
			'code' => 'customer.group.ctime',
57
			'internalcode' => 'mcusgr."ctime"',
58
			'label' => 'Group create date/time',
59
			'type' => 'datetime',
60
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
61
			'public' => false,
62
		),
63
		'customer.group.mtime' => array(
64
			'code' => 'customer.group.mtime',
65
			'internalcode' => 'mcusgr."mtime"',
66
			'label' => 'Group modify date/time',
67
			'type' => 'datetime',
68
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
69
			'public' => false,
70
		),
71
		'customer.group.editor' => array(
72
			'code' => 'customer.group.editor',
73
			'internalcode' => 'mcusgr."editor"',
74
			'label' => 'Group editor',
75
			'type' => 'string',
76
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
77
			'public' => false,
78
		),
79
	);
80
81
82
	/**
83
	 * Initializes the object
84
	 *
85
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
86
	 */
87
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
88
	{
89
		parent::__construct( $context );
90
		$this->setResourceName( 'db-customer' );
91
	}
92
93
94
	/**
95
	 * Removes old entries from the database
96
	 *
97
	 * @param integer[] $siteids List of IDs for sites whose entries should be deleted
98
	 */
99
	public function cleanup( array $siteids )
100
	{
101
		$path = 'mshop/customer/manager/group/submanagers';
102
		foreach( $this->getContext()->getConfig()->get( $path, [] ) as $domain ) {
103
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
104
		}
105
106
		$this->cleanupBase( $siteids, 'mshop/customer/manager/group/standard/delete' );
107
	}
108
109
110
	/**
111
	 * Creates a new empty item instance
112
	 *
113
	 * @param string|null Type the item should be created with
114
	 * @param string|null Domain of the type the item should be created with
115
	 * @param array $values Values the item should be initialized with
116
	 * @return \Aimeos\MShop\Customer\Item\Group\Iface New customer group item object
117
	 */
118
	public function createItem( $type = null, $domain = null, array $values = [] )
119
	{
120
		$values['customer.group.siteid'] = $this->getContext()->getLocale()->getSiteId();
121
		return $this->createItemBase( $values );
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/group/submanagers';
134
135
		return $this->getResourceTypeBase( 'customer/group', $path, [], $withsub );
136
	}
137
138
139
	/**
140
	 * Returns the attributes that can be used for searching
141
	 *
142
	 * @param boolean $withsub Return attributes of sub-managers too 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/group/submanagers
148
		 * List of manager names that can be instantiated by the customer group 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 2015.08
162
		 * @category Developer
163
		 */
164
		$path = 'mshop/customer/manager/group/submanagers';
165
166
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
167
	}
168
169
170
	/**
171
	 * Removes multiple items specified by their IDs
172
	 *
173
	 * @param array $ids List of IDs
174
	 */
175
	public function deleteItems( array $ids )
176
	{
177
		/** mshop/customer/manager/group/standard/delete/mysql
178
		 * Deletes the items matched by the given IDs from the database
179
		 *
180
		 * @see mshop/customer/manager/group/standard/delete/ansi
181
		 */
182
183
		/** mshop/customer/manager/group/standard/delete/ansi
184
		 * Deletes the items matched by the given IDs from the database
185
		 *
186
		 * Removes the records specified by the given IDs from the customer group
187
		 * database. The records must be from the site that is configured via the
188
		 * context item.
189
		 *
190
		 * The ":cond" placeholder is replaced by the name of the ID column and
191
		 * the given ID or list of IDs while the site ID is bound to the question
192
		 * mark.
193
		 *
194
		 * The SQL statement should conform to the ANSI standard to be
195
		 * compatible with most relational database systems. This also
196
		 * includes using double quotes for table and column names.
197
		 *
198
		 * @param string SQL statement for deleting items
199
		 * @since 2015.08
200
		 * @category Developer
201
		 * @see mshop/customer/manager/group/standard/insert/ansi
202
		 * @see mshop/customer/manager/group/standard/update/ansi
203
		 * @see mshop/customer/manager/group/standard/newid/ansi
204
		 * @see mshop/customer/manager/group/standard/search/ansi
205
		 * @see mshop/customer/manager/group/standard/count/ansi
206
		 */
207
		$path = 'mshop/customer/manager/group/standard/delete';
208
		$this->deleteItemsBase( $ids, $path );
209
	}
210
211
212
	/**
213
	 * Returns the item specified by its code and domain/type if necessary
214
	 *
215
	 * @param string $code Code of the item
216
	 * @param string[] $ref List of domains to fetch list items and referenced items for
217
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
218
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
219
	 * @param boolean $default True to add default criteria
220
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
221
	 */
222
	public function findItem( $code, array $ref = [], $domain = null, $type = null, $default = false )
223
	{
224
		return $this->findItemBase( array( 'customer.group.code' => $code ), $ref, $default );
225
	}
226
227
228
	/**
229
	 * Returns the customer group item object specificed by its ID
230
	 *
231
	 * @param integer $id Unique customer ID referencing an existing customer group
232
	 * @param string[] $ref List of domains to fetch list items and referenced items for
233
	 * @param boolean $default Add default criteria
234
	 * @return \Aimeos\MShop\Customer\Item\Group\Iface Returns the customer group item for the given ID
235
	 * @throws \Aimeos\MShop\Exception If item couldn't be found
236
	 */
237
	public function getItem( $id, array $ref = [], $default = false )
238
	{
239
		return $this->getItemBase( 'customer.group.id', $id, $ref, $default );
240
	}
241
242
243
	/**
244
	 * Inserts a new or updates an existing customer group item
245
	 *
246
	 * @param \Aimeos\MShop\Customer\Item\Group\Iface $item Customer group item
247
	 * @param boolean $fetch True if the new ID should be returned in the item
248
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
249
	 */
250
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
251
	{
252
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Group\\Iface', $item );
253
254
		if( !$item->isModified() ) {
255
			return $item;
256
		}
257
258
		$context = $this->getContext();
259
260
		$dbm = $context->getDatabaseManager();
261
		$dbname = $this->getResourceName();
262
		$conn = $dbm->acquire( $dbname );
263
264
		try
265
		{
266
			$id = $item->getId();
267
			$date = date( 'Y-m-d H:i:s' );
268
269
			if( $id === null )
270
			{
271
				/** mshop/customer/manager/group/standard/insert/mysql
272
				 * Inserts a new customer group record into the database table
273
				 *
274
				 * @see mshop/customer/manager/group/standard/insert/ansi
275
				 */
276
277
				/** mshop/customer/manager/group/standard/insert/ansi
278
				 * Inserts a new customer group record into the database table
279
				 *
280
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
281
				 * the database and the newly created ID retrieved afterwards
282
				 * using the "newid" SQL statement.
283
				 *
284
				 * The SQL statement must be a string suitable for being used as
285
				 * prepared statement. It must include question marks for binding
286
				 * the values from the customer group item to the statement before
287
				 * they are sent to the database server. The number of question
288
				 * marks must be the same as the number of columns listed in the
289
				 * INSERT statement. The order of the columns must correspond to
290
				 * the order in the saveItems() method, so the correct values are
291
				 * bound to the columns.
292
				 *
293
				 * The SQL statement should conform to the ANSI standard to be
294
				 * compatible with most relational database systems. This also
295
				 * includes using double quotes for table and column names.
296
				 *
297
				 * @param string SQL statement for inserting records
298
				 * @since 2015.08
299
				 * @category Developer
300
				 * @see mshop/customer/manager/group/standard/update/ansi
301
				 * @see mshop/customer/manager/group/standard/newid/ansi
302
				 * @see mshop/customer/manager/group/standard/delete/ansi
303
				 * @see mshop/customer/manager/group/standard/search/ansi
304
				 * @see mshop/customer/manager/group/standard/count/ansi
305
				 */
306
				$path = 'mshop/customer/manager/group/standard/insert';
307
			}
308
			else
309
			{
310
				/** mshop/customer/manager/group/standard/update/mysql
311
				 * Updates an existing customer group record in the database
312
				 *
313
				 * @see mshop/customer/manager/group/standard/update/ansi
314
				 */
315
316
				/** mshop/customer/manager/group/standard/update/ansi
317
				 * Updates an existing customer group record in the database
318
				 *
319
				 * Items which already have an ID (i.e. the ID is not NULL) will
320
				 * be updated in the database.
321
				 *
322
				 * The SQL statement must be a string suitable for being used as
323
				 * prepared statement. It must include question marks for binding
324
				 * the values from the customer group item to the statement before
325
				 * they are sent to the database server. The order of the columns
326
				 * must correspond to the order in the saveItems() method, so the
327
				 * correct values are bound to the columns.
328
				 *
329
				 * The SQL statement should conform to the ANSI standard to be
330
				 * compatible with most relational database systems. This also
331
				 * includes using double quotes for table and column names.
332
				 *
333
				 * @param string SQL statement for updating records
334
				 * @since 2015.08
335
				 * @category Developer
336
				 * @see mshop/customer/manager/group/standard/insert/ansi
337
				 * @see mshop/customer/manager/group/standard/newid/ansi
338
				 * @see mshop/customer/manager/group/standard/delete/ansi
339
				 * @see mshop/customer/manager/group/standard/search/ansi
340
				 * @see mshop/customer/manager/group/standard/count/ansi
341
				 */
342
				$path = 'mshop/customer/manager/group/standard/update';
343
			}
344
345
			$stmt = $this->getCachedStatement( $conn, $path );
346
347
			$stmt->bind( 1, $item->getCode() );
348
			$stmt->bind( 2, $item->getLabel() );
1 ignored issue
show
The method getLabel() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Tag\Item\Standard or Aimeos\MShop\Customer\Item\Group\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MAdmin\Job\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Common\Item\ListRef\Base or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Tree\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Price\Item\Base. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

348
			$stmt->bind( 2, $item->/** @scrutinizer ignore-call */ getLabel() );
Loading history...
349
			$stmt->bind( 3, $date ); // mtime
350
			$stmt->bind( 4, $context->getEditor() );
351
			$stmt->bind( 5, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
352
353
			if( $id !== null ) {
354
				$stmt->bind( 6, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
355
				$item->setId( $id );
356
			} else {
357
				$stmt->bind( 6, $date ); // ctime
358
			}
359
360
			$stmt->execute()->finish();
361
362
			if( $id === null && $fetch === true )
363
			{
364
				/** mshop/customer/manager/group/standard/newid/mysql
365
				 * Retrieves the ID generated by the database when inserting a new record
366
				 *
367
				 * @see mshop/customer/manager/group/standard/newid/ansi
368
				 */
369
370
				/** mshop/customer/manager/group/standard/newid/ansi
371
				 * Retrieves the ID generated by the database when inserting a new record
372
				 *
373
				 * As soon as a new record is inserted into the database table,
374
				 * the database server generates a new and unique identifier for
375
				 * that record. This ID can be used for retrieving, updating and
376
				 * deleting that specific record from the table again.
377
				 *
378
				 * For MySQL:
379
				 *  SELECT LAST_INSERT_ID()
380
				 * For PostgreSQL:
381
				 *  SELECT currval('seq_mcus_id')
382
				 * For SQL Server:
383
				 *  SELECT SCOPE_IDENTITY()
384
				 * For Oracle:
385
				 *  SELECT "seq_mcus_id".CURRVAL FROM DUAL
386
				 *
387
				 * There's no way to retrive the new ID by a SQL statements that
388
				 * fits for most database servers as they implement their own
389
				 * specific way.
390
				 *
391
				 * @param string SQL statement for retrieving the last inserted record ID
392
				 * @since 2015.08
393
				 * @category Developer
394
				 * @see mshop/customer/manager/group/standard/insert/ansi
395
				 * @see mshop/customer/manager/group/standard/update/ansi
396
				 * @see mshop/customer/manager/group/standard/delete/ansi
397
				 * @see mshop/customer/manager/group/standard/search/ansi
398
				 * @see mshop/customer/manager/group/standard/count/ansi
399
				 */
400
				$path = 'mshop/customer/manager/group/standard/newid';
401
				$item->setId( $this->newId( $conn, $path ) );
402
			}
403
404
			$dbm->release( $conn, $dbname );
405
		}
406
		catch( \Exception $e )
407
		{
408
			$dbm->release( $conn, $dbname );
409
			throw $e;
410
		}
411
412
		return $item;
413
	}
414
415
416
	/**
417
	 * Returns the item objects matched by the given search criteria.
418
	 *
419
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
420
	 * @param string[] $ref List of domains to fetch list items and referenced items for
421
	 * @param integer|null &$total Number of items that are available in total
422
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Group\Iface
423
	 */
424
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
425
	{
426
		$map = [];
427
		$context = $this->getContext();
428
429
		$dbm = $context->getDatabaseManager();
430
		$dbname = $this->getResourceName();
431
		$conn = $dbm->acquire( $dbname );
432
433
		try
434
		{
435
			$required = array( 'customer.group' );
436
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
437
438
			/** mshop/customer/manager/group/standard/search/mysql
439
			 * Retrieves the records matched by the given criteria in the database
440
			 *
441
			 * @see mshop/customer/manager/group/standard/search/ansi
442
			 */
443
444
			/** mshop/customer/manager/group/standard/search/ansi
445
			 * Retrieves the records matched by the given criteria in the database
446
			 *
447
			 * Fetches the records matched by the given criteria from the customer
448
			 * database. The records must be from one of the sites that are
449
			 * configured via the context item. If the current site is part of
450
			 * a tree of sites, the SELECT statement can retrieve all records
451
			 * from the current site and the complete sub-tree of sites.
452
			 *
453
			 * As the records can normally be limited by criteria from sub-managers,
454
			 * their tables must be joined in the SQL context. This is done by
455
			 * using the "internaldeps" property from the definition of the ID
456
			 * column of the sub-managers. These internal dependencies specify
457
			 * the JOIN between the tables and the used columns for joining. The
458
			 * ":joins" placeholder is then replaced by the JOIN strings from
459
			 * the sub-managers.
460
			 *
461
			 * To limit the records matched, conditions can be added to the given
462
			 * criteria object. It can contain comparisons like column names that
463
			 * must match specific values which can be combined by AND, OR or NOT
464
			 * operators. The resulting string of SQL conditions replaces the
465
			 * ":cond" placeholder before the statement is sent to the database
466
			 * server.
467
			 *
468
			 * If the records that are retrieved should be ordered by one or more
469
			 * columns, the generated string of column / sort direction pairs
470
			 * replaces the ":order" placeholder. In case no ordering is required,
471
			 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
472
			 * markers is removed to speed up retrieving the records. Columns of
473
			 * sub-managers can also be used for ordering the result set but then
474
			 * no index can be used.
475
			 *
476
			 * The number of returned records can be limited and can start at any
477
			 * number between the begining and the end of the result set. For that
478
			 * the ":size" and ":start" placeholders are replaced by the
479
			 * corresponding values from the criteria object. The default values
480
			 * are 0 for the start and 100 for the size value.
481
			 *
482
			 * The SQL statement should conform to the ANSI standard to be
483
			 * compatible with most relational database systems. This also
484
			 * includes using double quotes for table and column names.
485
			 *
486
			 * @param string SQL statement for searching items
487
			 * @since 2015.08
488
			 * @category Developer
489
			 * @see mshop/customer/manager/group/standard/insert/ansi
490
			 * @see mshop/customer/manager/group/standard/update/ansi
491
			 * @see mshop/customer/manager/group/standard/newid/ansi
492
			 * @see mshop/customer/manager/group/standard/delete/ansi
493
			 * @see mshop/customer/manager/group/standard/count/ansi
494
			 */
495
			$cfgPathSearch = 'mshop/customer/manager/group/standard/search';
496
497
			/** mshop/customer/manager/group/standard/count/mysql
498
			 * Counts the number of records matched by the given criteria in the database
499
			 *
500
			 * @see mshop/customer/manager/group/standard/count/ansi
501
			 */
502
503
			/** mshop/customer/manager/group/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.08
541
			 * @category Developer
542
			 * @see mshop/customer/manager/group/standard/insert/ansi
543
			 * @see mshop/customer/manager/group/standard/update/ansi
544
			 * @see mshop/customer/manager/group/standard/newid/ansi
545
			 * @see mshop/customer/manager/group/standard/delete/ansi
546
			 * @see mshop/customer/manager/group/standard/search/ansi
547
			 */
548
			$cfgPathCount = 'mshop/customer/manager/group/standard/count';
549
550
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
551
552
			while( ( $row = $results->fetch() ) !== false ) {
553
				$map[$row['customer.group.id']] = $this->createItemBase( $row );
554
			}
555
556
			$dbm->release( $conn, $dbname );
557
		}
558
		catch( \Exception $e )
559
		{
560
			$dbm->release( $conn, $dbname );
561
			throw $e;
562
		}
563
564
		return $map;
565
	}
566
567
568
	/**
569
	 * Returns a new manager for customer group extensions
570
	 *
571
	 * @param string $manager Name of the sub manager type in lower case
572
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
573
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions
574
	 */
575
	public function getSubManager( $manager, $name = null )
576
	{
577
		/** mshop/customer/manager/group/name
578
		 * Class name of the used customer group manager implementation
579
		 *
580
		 * Each default customer group manager can be replaced by an alternative
581
		 * imlementation. To use this implementation, you have to set the last
582
		 * part of the class name as configuration value so the manager factory
583
		 * knows which class it has to instantiate.
584
		 *
585
		 * For example, if the name of the default class is
586
		 *
587
		 *  \Aimeos\MShop\Customer\Manager\Group\Standard
588
		 *
589
		 * and you want to replace it with your own version named
590
		 *
591
		 *  \Aimeos\MShop\Customer\Manager\Group\Mygroup
592
		 *
593
		 * then you have to set the this configuration option:
594
		 *
595
		 *  mshop/customer/manager/group/name = Mygroup
596
		 *
597
		 * The value is the last part of your own class name and it's case sensitive,
598
		 * so take care that the configuration value is exactly named like the last
599
		 * part of the class name.
600
		 *
601
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
602
		 * characters are possible! You should always start the last part of the class
603
		 * name with an upper case character and continue only with lower case characters
604
		 * or numbers. Avoid chamel case names like "MyGroup"!
605
		 *
606
		 * @param string Last part of the class name
607
		 * @since 2015.08
608
		 * @category Developer
609
		 */
610
611
		/** mshop/customer/manager/group/decorators/excludes
612
		 * Excludes decorators added by the "common" option from the customer group manager
613
		 *
614
		 * Decorators extend the functionality of a class by adding new aspects
615
		 * (e.g. log what is currently done), executing the methods of the underlying
616
		 * class only in certain conditions (e.g. only for logged in users) or
617
		 * modify what is returned to the caller.
618
		 *
619
		 * This option allows you to remove a decorator added via
620
		 * "mshop/common/manager/group/decorators/default" before they are wrapped
621
		 * around the customer group manager.
622
		 *
623
		 *  mshop/customer/manager/group/decorators/excludes = array( 'decorator1' )
624
		 *
625
		 * This would remove the decorator named "decorator1" from the list of
626
		 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
627
		 * "mshop/common/manager/decorators/default" for the customer group manager.
628
		 *
629
		 * @param array List of decorator names
630
		 * @since 2015.08
631
		 * @category Developer
632
		 * @see mshop/common/manager/decorators/default
633
		 * @see mshop/customer/manager/group/decorators/global
634
		 * @see mshop/customer/manager/group/decorators/local
635
		 */
636
637
		/** mshop/customer/manager/group/decorators/global
638
		 * Adds a list of globally available decorators only to the customer group manager
639
		 *
640
		 * Decorators extend the functionality of a class by adding new aspects
641
		 * (e.g. log what is currently done), executing the methods of the underlying
642
		 * class only in certain conditions (e.g. only for logged in users) or
643
		 * modify what is returned to the caller.
644
		 *
645
		 * This option allows you to wrap global decorators
646
		 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the customer manager.
647
		 *
648
		 *  mshop/customer/manager/group/decorators/global = array( 'decorator1' )
649
		 *
650
		 * This would add the decorator named "decorator1" defined by
651
		 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the customer
652
		 * group manager.
653
		 *
654
		 * @param array List of decorator names
655
		 * @since 2015.08
656
		 * @category Developer
657
		 * @see mshop/common/manager/decorators/default
658
		 * @see mshop/customer/manager/group/decorators/excludes
659
		 * @see mshop/customer/manager/group/decorators/local
660
		 */
661
662
		/** mshop/customer/manager/group/decorators/local
663
		 * Adds a list of local decorators only to the customer group manager
664
		 *
665
		 * Decorators extend the functionality of a class by adding new aspects
666
		 * (e.g. log what is currently done), executing the methods of the underlying
667
		 * class only in certain conditions (e.g. only for logged in users) or
668
		 * modify what is returned to the caller.
669
		 *
670
		 * This option allows you to wrap local decorators
671
		 * ("\Aimeos\MShop\Customer\Manager\Group\Decorator\*") around the customer
672
		 * group manager.
673
		 *
674
		 *  mshop/customer/manager/group/decorators/local = array( 'decorator2' )
675
		 *
676
		 * This would add the decorator named "decorator2" defined by
677
		 * "\Aimeos\MShop\Customer\Manager\Group\\Decorator\Decorator2" only to the
678
		 * customer group manager.
679
		 *
680
		 * @param array List of decorator names
681
		 * @since 2015.08
682
		 * @category Developer
683
		 * @see mshop/common/manager/decorators/default
684
		 * @see mshop/customer/manager/group/decorators/excludes
685
		 * @see mshop/customer/manager/group/decorators/global
686
		 */
687
688
		return $this->getSubManagerBase( 'customer/group', $manager, $name );
689
	}
690
691
692
	/**
693
	 * Creates a new customer group item
694
	 *
695
	 * @param array $values List of attributes for customer group item
696
	 * @return \Aimeos\MShop\Customer\Item\Group\Iface New customer group item
697
	 */
698
	protected function createItemBase( array $values = [] )
699
	{
700
		return new \Aimeos\MShop\Customer\Item\Group\Standard( $values );
701
	}
702
}
703