Passed
Push — master ( f11a29...41b844 )
by Aimeos
01:35
created

FosUser::__construct()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 40
rs 8.4444
c 0
b 0
f 0
cc 8
nc 4
nop 1
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;
12
13
14
/**
15
 * Customer class implementation for Friends of Symfony user bundle.
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class FosUser
21
	extends \Aimeos\MShop\Customer\Manager\Standard
22
{
23
	private $searchConfig = array(
24
		// customer.siteid is only for informational purpuse, not for filtering
25
		'customer.id' => array(
26
			'label' => 'Customer ID',
27
			'code' => 'customer.id',
28
			'internalcode' => 'fos."id"',
29
			'type' => 'integer',
30
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
31
			'public' => false,
32
		),
33
		'customer.code' => array(
34
			'label' => 'Customer username',
35
			'code' => 'customer.code',
36
			'internalcode' => 'fos."username"',
37
			'type' => 'string',
38
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
39
		),
40
		'customer.label' => array(
41
			'label' => 'Customer label',
42
			'code' => 'customer.label',
43
			'internalcode' => 'fos."username_canonical"',
44
			'type' => 'string',
45
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
46
		),
47
		'customer.salutation' => array(
48
			'label' => 'Customer salutation',
49
			'code' => 'customer.salutation',
50
			'internalcode' => 'fos."salutation"',
51
			'type' => 'string',
52
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
53
		),
54
		'customer.company'=> array(
55
			'label' => 'Customer company',
56
			'code' => 'customer.company',
57
			'internalcode' => 'fos."company"',
58
			'type' => 'string',
59
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
60
		),
61
		'customer.vatid'=> array(
62
			'label' => 'Customer VAT ID',
63
			'code' => 'customer.vatid',
64
			'internalcode' => 'fos."vatid"',
65
			'type' => 'string',
66
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
67
		),
68
		'customer.title' => array(
69
			'label' => 'Customer title',
70
			'code' => 'customer.title',
71
			'internalcode' => 'fos."title"',
72
			'type' => 'string',
73
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
74
		),
75
		'customer.firstname' => array(
76
			'label' => 'Customer firstname',
77
			'code' => 'customer.firstname',
78
			'internalcode' => 'fos."firstname"',
79
			'type' => 'string',
80
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
81
		),
82
		'customer.lastname' => array(
83
			'label' => 'Customer lastname',
84
			'code' => 'customer.lastname',
85
			'internalcode' => 'fos."lastname"',
86
			'type' => 'string',
87
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
88
		),
89
		'customer.address1' => array(
90
			'label' => 'Customer address part one',
91
			'code' => 'customer.address1',
92
			'internalcode' => 'fos."address1"',
93
			'type' => 'string',
94
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
95
		),
96
		'customer.address2' => array(
97
			'label' => 'Customer address part two',
98
			'code' => 'customer.address2',
99
			'internalcode' => 'fos."address2"',
100
			'type' => 'string',
101
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
102
		),
103
		'customer.address3' => array(
104
			'label' => 'Customer address part three',
105
			'code' => 'customer.address3',
106
			'internalcode' => 'fos."address3"',
107
			'type' => 'string',
108
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
109
		),
110
		'customer.postal' => array(
111
			'label' => 'Customer postal',
112
			'code' => 'customer.postal',
113
			'internalcode' => 'fos."postal"',
114
			'type' => 'string',
115
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
116
		),
117
		'customer.city' => array(
118
			'label' => 'Customer city',
119
			'code' => 'customer.city',
120
			'internalcode' => 'fos."city"',
121
			'type' => 'string',
122
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
123
		),
124
		'customer.state' => array(
125
			'label' => 'Customer state',
126
			'code' => 'customer.state',
127
			'internalcode' => 'fos."state"',
128
			'type' => 'string',
129
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
130
		),
131
		'customer.languageid' => array(
132
			'label' => 'Customer language',
133
			'code' => 'customer.languageid',
134
			'internalcode' => 'fos."langid"',
135
			'type' => 'string',
136
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
137
		),
138
		'customer.countryid' => array(
139
			'label' => 'Customer country',
140
			'code' => 'customer.countryid',
141
			'internalcode' => 'fos."countryid"',
142
			'type' => 'string',
143
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
144
		),
145
		'customer.telephone' => array(
146
			'label' => 'Customer telephone',
147
			'code' => 'customer.telephone',
148
			'internalcode' => 'fos."telephone"',
149
			'type' => 'string',
150
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
151
		),
152
		'customer.email' => array(
153
			'label' => 'Customer email',
154
			'code' => 'customer.email',
155
			'internalcode' => 'fos."email"',
156
			'type' => 'string',
157
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
158
		),
159
		'customer.telefax' => array(
160
			'label' => 'Customer telefax',
161
			'code' => 'customer.telefax',
162
			'internalcode' => 'fos."telefax"',
163
			'type' => 'string',
164
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
165
		),
166
		'customer.website' => array(
167
			'label' => 'Customer website',
168
			'code' => 'customer.website',
169
			'internalcode' => 'fos."website"',
170
			'type' => 'string',
171
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
172
		),
173
		'customer.longitude' => array(
174
			'label' => 'Customer longitude',
175
			'code' => 'customer.longitude',
176
			'internalcode' => 'fos."longitude"',
177
			'type' => 'float',
178
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT,
179
		),
180
		'customer.latitude' => array(
181
			'label' => 'Customer latitude',
182
			'code' => 'customer.latitude',
183
			'internalcode' => 'fos."latitude"',
184
			'type' => 'float',
185
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT,
186
		),
187
		'customer.birthday' => array(
188
			'label' => 'Customer birthday',
189
			'code' => 'customer.birthday',
190
			'internalcode' => 'fos."birthday"',
191
			'type' => 'string',
192
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
193
		),
194
		'customer.password'=> array(
195
			'label' => 'Customer password',
196
			'code' => 'customer.password',
197
			'internalcode' => 'fos."password"',
198
			'type' => 'string',
199
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
200
		),
201
		'customer.status'=> array(
202
			'label' => 'Customer status',
203
			'code' => 'customer.status',
204
			'internalcode' => 'fos."enabled"',
205
			'type' => 'integer',
206
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_BOOL,
207
		),
208
		'customer.dateverified'=> array(
209
			'label' => 'Customer verification date',
210
			'code' => 'customer.dateverified',
211
			'internalcode' => 'fos."vdate"',
212
			'type' => 'date',
213
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
214
		),
215
		'customer.ctime'=> array(
216
			'label' => 'Customer creation time',
217
			'code' => 'customer.ctime',
218
			'internalcode' => 'fos."ctime"',
219
			'type' => 'datetime',
220
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
221
		),
222
		'customer.mtime'=> array(
223
			'label' => 'Customer modification time',
224
			'code' => 'customer.mtime',
225
			'internalcode' => 'fos."mtime"',
226
			'type' => 'datetime',
227
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
228
		),
229
		'customer.editor'=> array(
230
			'label'=>'Customer editor',
231
			'code'=>'customer.editor',
232
			'internalcode' => 'fos."editor"',
233
			'type'=> 'string',
234
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
235
		),
236
		'customer:has' => array(
237
			'code' => 'customer:has()',
238
			'internalcode' => '(
239
				SELECT fosli_has."id" FROM fos_user_list AS fosli_has
240
				WHERE fos."id" = fosli_has."parentid" AND :site AND fosli_has."domain" = $1 :type :refid
241
				LIMIT 1
242
			)',
243
			'label' => 'Customer has list item, parameter(<domain>[,<list type>[,<reference ID>)]]',
244
			'type' => 'null',
245
			'internaltype' => 'null',
246
			'public' => false,
247
		),
248
		'customer:prop' => array(
249
			'code' => 'customer:prop()',
250
			'internalcode' => '(
251
				SELECT fospr_prop."id" FROM fos_user_property AS fospr_prop
252
				WHERE fos."id" = fospr_prop."parentid" AND :site AND fospr_prop."type" = $1 :langid :value
253
				LIMIT 1
254
			)',
255
			'label' => 'Customer has property item, parameter(<property type>[,<language code>[,<property value>]])',
256
			'type' => 'null',
257
			'internaltype' => 'null',
258
			'public' => false,
259
		),
260
	);
261
262
263
	/**
264
	 * Initializes the object.
265
	 *
266
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
267
	 */
268
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
269
	{
270
		parent::__construct( $context );
271
272
		$locale = $context->getLocale();
273
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
274
		$level = $context->getConfig()->get( 'mshop/customer/manager/sitemode', $level );
275
276
		$siteIds = [$locale->getSiteId()];
277
278
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) {
279
			$siteIds = array_merge( $siteIds, $locale->getSitePath() );
280
		}
281
282
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) {
283
			$siteIds = array_merge( $siteIds, $locale->getSiteSubTree() );
284
		}
285
286
		$this->replaceSiteMarker( $this->searchConfig['customer:has'], 'fosli_has."siteid"', $siteIds, ':site' );
287
		$this->replaceSiteMarker( $this->searchConfig['customer:prop'], 'fospr_prop."siteid"', $siteIds, ':site' );
288
289
290
		$this->searchConfig['customer:has']['function'] = function( &$source, array $params ) {
291
292
			$source = str_replace( ':type', isset( $params[1] ) ? 'AND fosli_has."type" = $2' : '', $source );
293
			$source = str_replace( ':refid', isset( $params[2] ) ? 'AND fosli_has."refid" = $3' : '', $source );
294
295
			return $params;
296
		};
297
298
299
		$this->searchConfig['customer:prop']['function'] = function( &$source, array $params ) {
300
301
			$lang = 'AND fospr_prop."langid"';
302
			$lang = isset( $params[1] ) ? ( $params[1] !== 'null' ? $lang . ' = $2' : $lang . ' IS NULL' ) : '';
303
304
			$source = str_replace( ':langid', $lang, $source );
305
			$source = str_replace( ':value', isset( $params[2] ) ? 'AND fospr_prop."value" = $3' : '', $source );
306
307
			return $params;
308
		};
309
	}
310
311
312
	/**
313
	 * Removes old entries from the storage.
314
	 *
315
	 * @param array $siteids List of IDs for sites whose entries should be deleted
316
	 */
317
	public function cleanup( array $siteids )
318
	{
319
		$path = 'mshop/customer/manager/submanagers';
320
		$default = ['address', 'group', 'lists', 'property'];
321
322
		foreach( $this->getContext()->getConfig()->get( $path, $default ) as $domain ) {
323
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
324
		}
325
	}
326
327
328
	/**
329
	 * Removes multiple items specified by ids in the array.
330
	 *
331
	 * @param array $ids List of IDs
332
	 */
333
	public function deleteItems( array $ids )
334
	{
335
		$path = 'mshop/customer/manager/fosuser/delete';
336
		$this->deleteItemsBase( $ids, $path, false );
337
	}
338
339
340
	/**
341
	 * Returns the list attributes that can be used for searching.
342
	 *
343
	 * @param boolean $withsub Return also attributes of sub-managers if true
344
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
345
	 */
346
	public function getSearchAttributes( $withsub = true )
347
	{
348
		$path = 'mshop/customer/manager/submanagers';
349
		$default = ['address', 'group', 'lists', 'property'];
350
351
		return $this->getSearchAttributesBase( $this->searchConfig, $path, $default, $withsub );
352
	}
353
354
355
	/**
356
	 * Saves a customer item object.
357
	 *
358
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
359
	 * @param boolean $fetch True if the new ID should be returned in the item
360
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
361
	 */
362
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
363
	{
364
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\FosUser', $item );
365
366
		$item = $this->addGroups( $item );
367
368
		if( !$item->isModified() )
369
		{
370
			$item = $this->savePropertyItems( $item, 'customer' );
371
			$item = $this->saveAddressItems( $item, 'customer' );
372
			return $this->saveListItems( $item, 'customer' );
373
		}
374
375
		$context = $this->getContext();
376
		$dbm = $context->getDatabaseManager();
377
		$dbname = $this->getResourceName();
378
		$conn = $dbm->acquire( $dbname );
379
380
		try
381
		{
382
			$id = $item->getId();
383
			$date = date( 'Y-m-d H:i:s' );
384
			$billingAddress = $item->getPaymentAddress();
385
386
			if( $id === null )
387
			{
388
				/** mshop/customer/manager/fosuser/insert
389
				 * Inserts a new customer record into the database table
390
				 *
391
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
392
				 * the database and the newly created ID retrieved afterwards
393
				 * using the "newid" SQL statement.
394
				 *
395
				 * The SQL statement must be a string suitable for being used as
396
				 * prepared statement. It must include question marks for binding
397
				 * the values from the customer item to the statement before they are
398
				 * sent to the database server. The number of question marks must
399
				 * be the same as the number of columns listed in the INSERT
400
				 * statement. The order of the columns must correspond to the
401
				 * order in the saveItems() method, so the correct values are
402
				 * bound to the columns.
403
				 *
404
				 * The SQL statement should conform to the ANSI standard to be
405
				 * compatible with most relational database systems. This also
406
				 * includes using double quotes for table and column names.
407
				 *
408
				 * @param string SQL statement for inserting records
409
				 * @since 2015.01
410
				 * @category Developer
411
				 * @see mshop/customer/manager/fosuser/update
412
				 * @see mshop/customer/manager/fosuser/newid
413
				 * @see mshop/customer/manager/fosuser/delete
414
				 * @see mshop/customer/manager/fosuser/search
415
				 * @see mshop/customer/manager/fosuser/count
416
				 */
417
				$path = 'mshop/customer/manager/fosuser/insert';
418
			}
419
			else
420
			{
421
				/** mshop/customer/manager/fosuser/update
422
				 * Updates an existing customer record in the database
423
				 *
424
				 * Items which already have an ID (i.e. the ID is not NULL) will
425
				 * be updated in the database.
426
				 *
427
				 * The SQL statement must be a string suitable for being used as
428
				 * prepared statement. It must include question marks for binding
429
				 * the values from the customer item to the statement before they are
430
				 * sent to the database server. The order of the columns must
431
				 * correspond to the order in the saveItems() method, so the
432
				 * correct values are bound to the columns.
433
				 *
434
				 * The SQL statement should conform to the ANSI standard to be
435
				 * compatible with most relational database systems. This also
436
				 * includes using double quotes for table and column names.
437
				 *
438
				 * @param string SQL statement for updating records
439
				 * @since 2015.01
440
				 * @category Developer
441
				 * @see mshop/customer/manager/fosuser/insert
442
				 * @see mshop/customer/manager/fosuser/newid
443
				 * @see mshop/customer/manager/fosuser/delete
444
				 * @see mshop/customer/manager/fosuser/search
445
				 * @see mshop/customer/manager/fosuser/count
446
				 */
447
				$path = 'mshop/customer/manager/fosuser/update';
448
			}
449
450
			$stmt = $this->getCachedStatement( $conn, $path );
451
452
			$stmt->bind( 1, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
453
			$stmt->bind( 2, $item->getCode() ); // canonical username
454
			$stmt->bind( 3, $item->getCode() ); // username
455
			$stmt->bind( 4, $billingAddress->getCompany() );
456
			$stmt->bind( 5, $billingAddress->getVatID() );
457
			$stmt->bind( 6, $billingAddress->getSalutation() );
458
			$stmt->bind( 7, $billingAddress->getTitle() );
459
			$stmt->bind( 8, $billingAddress->getFirstname() );
460
			$stmt->bind( 9, $billingAddress->getLastname() );
461
			$stmt->bind( 10, $billingAddress->getAddress1() );
462
			$stmt->bind( 11, $billingAddress->getAddress2() );
463
			$stmt->bind( 12, $billingAddress->getAddress3() );
464
			$stmt->bind( 13, $billingAddress->getPostal() );
465
			$stmt->bind( 14, $billingAddress->getCity() );
466
			$stmt->bind( 15, $billingAddress->getState() );
467
			$stmt->bind( 16, $billingAddress->getCountryId() );
468
			$stmt->bind( 17, $billingAddress->getLanguageId() );
469
			$stmt->bind( 18, $billingAddress->getTelephone() );
470
			$stmt->bind( 19, $billingAddress->getEmail() );
471
			$stmt->bind( 20, $billingAddress->getEmail() );
472
			$stmt->bind( 21, $billingAddress->getTelefax() );
473
			$stmt->bind( 22, $billingAddress->getWebsite() );
474
			$stmt->bind( 23, $billingAddress->getLongitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT );
475
			$stmt->bind( 24, $billingAddress->getLatitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT );
476
			$stmt->bind( 25, $item->getBirthday() );
477
			$stmt->bind( 26, ( $item->getStatus() > 0 ? true : false ), \Aimeos\MW\DB\Statement\Base::PARAM_BOOL );
478
			$stmt->bind( 27, $item->getDateVerified() );
479
			$stmt->bind( 28, $item->getPassword() );
480
			$stmt->bind( 29, $date ); // Modification time
481
			$stmt->bind( 30, $context->getEditor() );
482
			$stmt->bind( 31, serialize( $item->getRoles() ) );
483
			$stmt->bind( 32, $item->getSalt() );
484
485
			if( $id !== null ) {
486
				$stmt->bind( 33, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
487
				$item->setId( $id );
488
			} else {
489
				$stmt->bind( 33, $date ); // Creation time
490
			}
491
492
			$stmt->execute()->finish();
493
494
			if( $id === null && $fetch === true )
495
			{
496
				/** mshop/customer/manager/fosuser/newid
497
				 * Retrieves the ID generated by the database when inserting a new record
498
				 *
499
				 * As soon as a new record is inserted into the database table,
500
				 * the database server generates a new and unique identifier for
501
				 * that record. This ID can be used for retrieving, updating and
502
				 * deleting that specific record from the table again.
503
				 *
504
				 * For MySQL:
505
				 *  SELECT LAST_INSERT_ID()
506
				 * For PostgreSQL:
507
				 *  SELECT currval('seq_mcus_id')
508
				 * For SQL Server:
509
				 *  SELECT SCOPE_IDENTITY()
510
				 * For Oracle:
511
				 *  SELECT "seq_mcus_id".CURRVAL FROM DUAL
512
				 *
513
				 * There's no way to retrive the new ID by a SQL statements that
514
				 * fits for most database servers as they implement their own
515
				 * specific way.
516
				 *
517
				 * @param string SQL statement for retrieving the last inserted record ID
518
				 * @since 2015.01
519
				 * @category Developer
520
				 * @see mshop/customer/manager/fosuser/insert
521
				 * @see mshop/customer/manager/fosuser/update
522
				 * @see mshop/customer/manager/fosuser/delete
523
				 * @see mshop/customer/manager/fosuser/search
524
				 * @see mshop/customer/manager/fosuser/count
525
				 */
526
				$path = 'mshop/customer/manager/fosuser/newid';
527
				$item->setId( $this->newId( $conn, $path ) );
528
			}
529
530
			$dbm->release( $conn, $dbname );
531
		}
532
		catch( \Exception $e )
533
		{
534
			$dbm->release( $conn, $dbname );
535
			throw $e;
536
		}
537
538
		$item = $this->savePropertyItems( $item, 'customer' );
539
		$item = $this->saveAddressItems( $item, 'customer' );
540
		return $this->saveListItems( $item, 'customer' );
541
	}
542
543
544
	/**
545
	 * Returns the item objects matched by the given search criteria.
546
	 *
547
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
548
	 * @param integer &$total Number of items that are available in total
549
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface
550
	 * @throws \Aimeos\MShop\Customer\Exception If creating items failed
551
	 */
552
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
553
	{
554
		$dbm = $this->getContext()->getDatabaseManager();
555
		$dbname = $this->getResourceName();
556
		$conn = $dbm->acquire( $dbname );
557
		$map = [];
558
559
		try
560
		{
561
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
562
			$cfgPathSearch = 'mshop/customer/manager/fosuser/search';
563
			$cfgPathCount = 'mshop/customer/manager/fosuser/count';
564
			$ref[] = 'customer/group';
565
			$required = ['customer'];
566
567
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
568
			while( ( $row = $results->fetch() ) !== false ) {
569
				$map[ $row['customer.id'] ] = $row;
570
			}
571
572
			$dbm->release( $conn, $dbname );
573
		}
574
		catch( \Exception $e )
575
		{
576
			$dbm->release( $conn, $dbname  );
577
			throw $e;
578
		}
579
580
		$addrItems = [];
581
		if( in_array( 'customer/address', $ref, true ) ) {
582
			$addrItems = $this->getAddressItems( array_keys( $map ), 'customer' );
583
		}
584
585
		$propItems = [];
586
		if( in_array( 'customer/property', $ref, true ) ) {
587
			$propItems = $this->getPropertyItems( array_keys( $map ), 'customer' );
588
		}
589
590
		return $this->buildItems( $map, $ref, 'customer', $addrItems, $propItems );
591
	}
592
593
594
	/**
595
	 * Returns a new manager for customer extensions
596
	 *
597
	 * @param string $manager Name of the sub manager type in lower case
598
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
599
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
600
	 */
601
	public function getSubManager( $manager, $name = null )
602
	{
603
		return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'FosUser' : $name ) );
604
	}
605
606
607
	/**
608
	 * Creates a new customer item.
609
	 *
610
	 * @param array $values List of attributes for customer item
611
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
612
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
613
	 * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of referenced address items
614
	 * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
615
	 * @return \Aimeos\MShop\Customer\Item\Iface New customer item
616
	 */
617
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [],
618
		array $addrItems = [], array $propItems = [] )
619
	{
620
		if( isset( $values['roles'] ) ) {
621
			$values['roles'] = unserialize( $values['roles'] );
622
		}
623
624
		$helper = $this->getPasswordHelper();
625
		$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values );
626
627
		return new \Aimeos\MShop\Customer\Item\FosUser(
628
			$address, $values, $listItems, $refItems, $addrItems, $propItems, $helper
629
		);
630
	}
631
}
632