Passed
Push — 2018.10 ( 27b425...540ebf )
by Aimeos
02:32
created

Typo3   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 657
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 35
eloc 332
dl 0
loc 657
rs 9.6
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A cleanup() 0 7 2
A __construct() 0 18 1
A getSearchAttributes() 0 6 1
A createItem() 0 6 1
A getSubManager() 0 3 2
A searchItems() 0 38 5
A getPasswordHelper() 0 22 4
C saveItem() 0 182 9
B createItemBase() 0 34 7
A deleteItems() 0 4 1
A getAddressManager() 0 7 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2014-2018
7
 * @package MShop
8
 * @subpackage Customer
9
 */
10
11
12
namespace Aimeos\MShop\Customer\Manager;
13
14
15
/**
16
 * Typo3 implementation of the customer class.
17
 *
18
 * @package MShop
19
 * @subpackage Customer
20
 */
21
class Typo3
22
	extends \Aimeos\MShop\Customer\Manager\Standard
23
{
24
	private $searchConfig = array(
25
		// customer.siteid is only for informational purpuse, not for filtering
26
		'customer.id' => array(
27
			'label' => 'Customer ID',
28
			'code' => 'customer.id',
29
			'internalcode' => 't3feu."uid"',
30
			'type' => 'integer',
31
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
32
			'public' => false,
33
		),
34
		'customer.code' => array(
35
			'label' => 'Customer username',
36
			'code' => 'customer.code',
37
			'internalcode' => 't3feu."username"',
38
			'type' => 'string',
39
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
40
		),
41
		'customer.label' => array(
42
			'label' => 'Customer name',
43
			'code' => 'customer.label',
44
			'internalcode' => 't3feu."name"',
45
			'type' => 'string',
46
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
47
		),
48
		'customer.salutation' => array(
49
			'label' => 'Customer salutation',
50
			'code' => 'customer.salutation',
51
			'internalcode' => 't3feu."gender"',
52
			'type' => 'string',
53
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
54
		),
55
		'customer.company'=> array(
56
			'label' => 'Customer company',
57
			'code' => 'customer.company',
58
			'internalcode' => 't3feu."company"',
59
			'type' => 'string',
60
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
61
		),
62
		'customer.vatid'=> array(
63
			'label' => 'Customer VAT ID',
64
			'code' => 'customer.vatid',
65
			'internalcode' => 't3feu."vatid"',
66
			'type' => 'string',
67
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
68
		),
69
		'customer.title' => array(
70
			'label' => 'Customer title',
71
			'code' => 'customer.title',
72
			'internalcode' => 't3feu."title"',
73
			'type' => 'string',
74
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
75
		),
76
		'customer.firstname' => array(
77
			'label' => 'Customer firstname',
78
			'code' => 'customer.firstname',
79
			'internalcode' => 't3feu."first_name"',
80
			'type' => 'string',
81
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
82
		),
83
		'customer.lastname' => array(
84
			'label' => 'Customer lastname',
85
			'code' => 'customer.lastname',
86
			'internalcode' => 't3feu."last_name"',
87
			'type' => 'string',
88
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
89
		),
90
		'customer.address1' => array(
91
			'label' => 'Customer address part one',
92
			'code' => 'customer.address1',
93
			'internalcode' => 't3feu."address"',
94
			'type' => 'string',
95
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
96
		),
97
		'customer.address2' => array(
98
			'label' => 'Customer address part two',
99
			'code' => 'customer.address2',
100
			'internalcode' => 't3feu."address"',
101
			'type' => 'string',
102
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
103
		),
104
		'customer.address3' => array(
105
			'label' => 'Customer address part three',
106
			'code' => 'customer.address3',
107
			'internalcode' => 't3feu."address"',
108
			'type' => 'string',
109
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
110
		),
111
		'customer.postal' => array(
112
			'label' => 'Customer postal',
113
			'code' => 'customer.postal',
114
			'internalcode' => 't3feu."zip"',
115
			'type' => 'string',
116
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
117
		),
118
		'customer.city' => array(
119
			'label' => 'Customer city',
120
			'code' => 'customer.city',
121
			'internalcode' => 't3feu."city"',
122
			'type' => 'string',
123
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
124
		),
125
		'customer.state' => array(
126
			'label' => 'Customer state',
127
			'code' => 'customer.state',
128
			'internalcode' => 't3feu."zone"',
129
			'type' => 'string',
130
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
131
		),
132
		'customer.languageid' => array(
133
			'label' => 'Customer language',
134
			'code' => 'customer.languageid',
135
			'internalcode' => 't3feu."language"',
136
			'type' => 'string',
137
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
138
		),
139
		'customer.countryid' => array(
140
			'label' => 'Customer country',
141
			'code' => 'customer.countryid',
142
			'internalcode' => 'tsc."cn_iso_2"',
143
			'type' => 'string',
144
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
145
		),
146
		'customer.telephone' => array(
147
			'label' => 'Customer telephone',
148
			'code' => 'customer.telephone',
149
			'internalcode' => 't3feu."telephone"',
150
			'type' => 'string',
151
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
152
		),
153
		'customer.email' => array(
154
			'label' => 'Customer email',
155
			'code' => 'customer.email',
156
			'internalcode' => 't3feu."email"',
157
			'type' => 'string',
158
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
159
		),
160
		'customer.telefax' => array(
161
			'label' => 'Customer telefax',
162
			'code' => 'customer.telefax',
163
			'internalcode' => 't3feu."fax"',
164
			'type' => 'string',
165
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
166
		),
167
		'customer.website' => array(
168
			'label' => 'Customer website',
169
			'code' => 'customer.website',
170
			'internalcode' => 't3feu."www"',
171
			'type' => 'string',
172
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
173
		),
174
		'customer.longitude' => array(
175
			'label' => 'Customer longitude',
176
			'code' => 'customer.longitude',
177
			'internalcode' => 't3feu."longitude"',
178
			'type' => 'string',
179
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
180
		),
181
		'customer.latitude' => array(
182
			'label' => 'Customer latitude',
183
			'code' => 'customer.latitude',
184
			'internalcode' => 't3feu."latitude"',
185
			'type' => 'string',
186
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
187
		),
188
		'customer.birthday' => array(
189
			'label' => 'Customer birthday',
190
			'code' => 'customer.birthday',
191
			'internalcode' => 't3feu."date_of_birth"',
192
			'type' => 'string',
193
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
194
		),
195
		'customer.password'=> array(
196
			'label' => 'Customer password',
197
			'code' => 'customer.password',
198
			'internalcode' => 't3feu."password"',
199
			'type' => 'string',
200
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
201
		),
202
		'customer.status'=> array(
203
			'label' => 'Customer status',
204
			'code' => 'customer.status',
205
			'internalcode' => 't3feu."disable"',
206
			'type' => 'integer',
207
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
208
		),
209
		'customer.dateverified'=> array(
210
			'label' => 'Customer verification date',
211
			'code' => 'customer.dateverified',
212
			'internalcode' => 't3feu."vdate"',
213
			'type' => 'date',
214
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
215
		),
216
		'customer.ctime'=> array(
217
			'label' => 'Customer creation time',
218
			'code' => 'customer.ctime',
219
			'internalcode' => 't3feu."crdate"',
220
			'type' => 'datetime',
221
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
222
		),
223
		'customer.mtime'=> array(
224
			'label' => 'Customer modification time',
225
			'code' => 'customer.mtime',
226
			'internalcode' => 't3feu."tstamp"',
227
			'type' => 'datetime',
228
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
229
		),
230
		// not available
231
		'customer.editor'=> array(
232
			'label'=>'Customer editor',
233
			'code'=>'customer.editor',
234
			'internalcode'=>'1',
235
			'type'=> 'string',
236
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
237
		),
238
	);
239
240
	private $plugins = [];
241
	private $reverse = [];
242
	private $helper;
243
	private $pid;
244
245
246
247
	/**
248
	 * Initializes a new customer manager object using the given context object.
249
	 *
250
	 * @param \Aimeos\MShop\Context\Iface $context Context object with required objects
0 ignored issues
show
Bug introduced by
The type Aimeos\MShop\Context\Iface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
251
	 */
252
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
253
	{
254
		parent::__construct( $context );
255
256
		$plugin = new \Aimeos\MW\Criteria\Plugin\T3Salutation();
257
		$this->plugins['customer.salutation'] = $this->reverse['gender'] = $plugin;
258
259
		$plugin = new \Aimeos\MW\Criteria\Plugin\T3Status();
260
		$this->plugins['customer.status'] = $this->reverse['disable'] = $plugin;
261
262
		$plugin = new \Aimeos\MW\Criteria\Plugin\T3Date();
263
		$this->plugins['customer.birthday'] = $this->reverse['date_of_birth'] = $plugin;
264
265
		$plugin = new \Aimeos\MW\Criteria\Plugin\T3Datetime();
266
		$this->plugins['customer.ctime'] = $this->reverse['crdate'] = $plugin;
267
		$this->plugins['customer.mtime'] = $this->reverse['tstamp'] = $plugin;
268
269
		$this->pid = $context->getConfig()->get( 'mshop/customer/manager/typo3/pid-default', 0 );
270
	}
271
272
273
	/**
274
	 * Returns the list attributes that can be used for searching.
275
	 *
276
	 * @param boolean $withsub Return also attributes of sub-managers if true
277
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
278
	 */
279
	public function getSearchAttributes( $withsub = true )
280
	{
281
		$path = 'mshop/customer/manager/submanagers';
282
		$default = ['address', 'group', 'lists', 'property'];
283
284
		return $this->getSearchAttributesBase( $this->searchConfig, $path, $default, $withsub );
285
	}
286
287
288
	/**
289
	 * Removes old entries from the storage.
290
	 *
291
	 * @param array $siteids List of IDs for sites whose entries should be deleted
292
	 */
293
	public function cleanup( array $siteids )
294
	{
295
		$path = 'mshop/customer/manager/submanagers';
296
		$default = ['address', 'group', 'lists', 'property'];
297
298
		foreach( $this->getContext()->getConfig()->get( $path, $default ) as $domain ) {
299
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
300
		}
301
	}
302
303
304
	/**
305
	 * Creates a new empty item instance
306
	 *
307
	 * @param string|null Type the item should be created with
308
	 * @param string|null Domain of the type the item should be created with
0 ignored issues
show
Bug introduced by
The type Aimeos\MShop\Customer\Manager\Domain was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
309
	 * @param array $values Values the item should be initialized with
310
	 * @return \Aimeos\MShop\Common\Item\Site\Iface New site item object
0 ignored issues
show
Bug introduced by
The type Aimeos\MShop\Common\Item\Site\Iface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
311
	 */
312
	public function createItem( $type = null, $domain = null, array $values = [] )
313
	{
314
		$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId();
315
		$values['typo3.pageid'] = $this->pid;
316
317
		return $this->createItemBase( $values );
318
	}
319
320
321
	/**
322
	 * Deletes a customer item object from the permanent storage.
323
	 *
324
	 * @param array $ids List of customer IDs
325
	 */
326
	public function deleteItems( array $ids )
327
	{
328
		$path = 'mshop/customer/manager/typo3/delete';
329
		$this->deleteItemsBase( $ids, $path, false, 'uid' );
330
	}
331
332
333
	/**
334
	 * Saves a customer item object.
335
	 *
336
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
337
	 * @param boolean $fetch True if the new ID should be returned in the item
338
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
339
	 */
340
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
341
	{
342
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item );
343
344
		if( !$item->isModified() )
345
		{
346
			$item = $this->savePropertyItems( $item, 'customer' );
0 ignored issues
show
Bug introduced by
$item of type Aimeos\MShop\Common\Item\Iface is incompatible with the type Aimeos\MShop\Common\Item\PropertyRef\Iface expected by parameter $item of Aimeos\MShop\Customer\Ma...rd::savePropertyItems(). ( Ignorable by Annotation )

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

346
			$item = $this->savePropertyItems( /** @scrutinizer ignore-type */ $item, 'customer' );
Loading history...
347
			$item = $this->saveAddressItems( $item, 'customer' );
348
			return $this->saveListItems( $item, 'customer' );
349
		}
350
351
		$context = $this->getContext();
352
		$dbm = $context->getDatabaseManager();
353
		$dbname = $this->getResourceName();
354
		$conn = $dbm->acquire( $dbname );
355
356
		try
357
		{
358
			$id = $item->getId();
359
			$billingAddress = $item->getPaymentAddress();
360
361
			if( $id === null )
0 ignored issues
show
introduced by
The condition $id === null is always false.
Loading history...
362
			{
363
				/** mshop/customer/manager/typo3/insert
364
				 * Inserts a new customer record into the database table
365
				 *
366
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
367
				 * the database and the newly created ID retrieved afterwards
368
				 * using the "newid" SQL statement.
369
				 *
370
				 * The SQL statement must be a string suitable for being used as
371
				 * prepared statement. It must include question marks for binding
372
				 * the values from the customer item to the statement before they are
373
				 * sent to the database server. The number of question marks must
374
				 * be the same as the number of columns listed in the INSERT
375
				 * statement. The order of the columns must correspond to the
376
				 * order in the saveItems() method, so the correct values are
377
				 * bound to the columns.
378
				 *
379
				 * The SQL statement should conform to the ANSI standard to be
380
				 * compatible with most relational database systems. This also
381
				 * includes using double quotes for table and column names.
382
				 *
383
				 * @param string SQL statement for inserting records
384
				 * @since 2014.03
385
				 * @category Developer
386
				 * @see mshop/customer/manager/typo3/update
387
				 * @see mshop/customer/manager/typo3/newid
388
				 * @see mshop/customer/manager/typo3/delete
389
				 * @see mshop/customer/manager/typo3/search
390
				 * @see mshop/customer/manager/typo3/count
391
				 */
392
				$path = 'mshop/customer/manager/typo3/insert';
393
			}
394
			else
395
			{
396
				/** mshop/customer/manager/typo3/update
397
				 * Updates an existing customer record in the database
398
				 *
399
				 * Items which already have an ID (i.e. the ID is not NULL) will
400
				 * be updated in the database.
401
				 *
402
				 * The SQL statement must be a string suitable for being used as
403
				 * prepared statement. It must include question marks for binding
404
				 * the values from the customer item to the statement before they are
405
				 * sent to the database server. The order of the columns must
406
				 * correspond to the order in the saveItems() method, so the
407
				 * correct values are bound to the columns.
408
				 *
409
				 * The SQL statement should conform to the ANSI standard to be
410
				 * compatible with most relational database systems. This also
411
				 * includes using double quotes for table and column names.
412
				 *
413
				 * @param string SQL statement for updating records
414
				 * @since 2014.03
415
				 * @category Developer
416
				 * @see mshop/customer/manager/typo3/insert
417
				 * @see mshop/customer/manager/typo3/newid
418
				 * @see mshop/customer/manager/typo3/delete
419
				 * @see mshop/customer/manager/typo3/search
420
				 * @see mshop/customer/manager/typo3/count
421
				 */
422
				$path = 'mshop/customer/manager/typo3/update';
423
			}
424
425
			$stmt = $this->getCachedStatement( $conn, $path );
426
427
			$address = $billingAddress->getAddress1();
428
429
			if( ( $part = $billingAddress->getAddress2() ) != '' ) {
430
				$address .= ' ' . $part;
431
			}
432
433
			if( ( $part = $billingAddress->getAddress3() ) != '' ) {
434
				$address .= ' ' . $part;
435
			}
436
437
			// TYPO3 fe_users.static_info_country is a three letter ISO code instead a two letter one
438
			$stmt->bind( 1, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
439
			$stmt->bind( 2, $item->getLabel() );
440
			$stmt->bind( 3, $item->getCode() );
441
			$stmt->bind( 4, $this->plugins['customer.salutation']->translate( $billingAddress->getSalutation() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
442
			$stmt->bind( 5, $billingAddress->getCompany() );
443
			$stmt->bind( 6, $billingAddress->getVatID() );
444
			$stmt->bind( 7, $billingAddress->getTitle() );
445
			$stmt->bind( 8, $billingAddress->getFirstname() );
446
			$stmt->bind( 9, $billingAddress->getLastname() );
447
			$stmt->bind( 10, $address );
448
			$stmt->bind( 11, $billingAddress->getPostal() );
449
			$stmt->bind( 12, $billingAddress->getCity() );
450
			$stmt->bind( 13, $billingAddress->getState() );
451
			$stmt->bind( 14, $billingAddress->getLanguageId() );
452
			$stmt->bind( 15, $billingAddress->getTelephone() );
453
			$stmt->bind( 16, $billingAddress->getEmail() );
454
			$stmt->bind( 17, $billingAddress->getTelefax() );
455
			$stmt->bind( 18, $billingAddress->getWebsite() );
456
			$stmt->bind( 19, $billingAddress->getLongitude() );
457
			$stmt->bind( 20, $billingAddress->getLatitude() );
458
			$stmt->bind( 21, $this->plugins['customer.birthday']->translate( $item->getBirthday() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
459
			$stmt->bind( 22, $this->plugins['customer.status']->translate( $item->getStatus() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
460
			$stmt->bind( 23, $item->getPassword() );
461
			$stmt->bind( 24, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Modification time
462
			$stmt->bind( 25, $billingAddress->getCountryId() );
463
			$stmt->bind( 26, implode( ',', $item->getGroups() ) );
464
			$stmt->bind( 27, $item->getPageId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // TYPO3 PID value
465
466
			if( $id !== null ) {
0 ignored issues
show
introduced by
The condition $id !== null is always true.
Loading history...
467
				$stmt->bind( 28, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
468
				$item->setId( $id );
469
			} else {
470
				$stmt->bind( 28, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Creation time
471
			}
472
473
			$stmt->execute()->finish();
474
475
			if( $id === null && $fetch === true )
0 ignored issues
show
introduced by
The condition $id === null is always false.
Loading history...
476
			{
477
				/** mshop/customer/manager/typo3/newid
478
				 * Retrieves the ID generated by the database when inserting a new record
479
				 *
480
				 * As soon as a new record is inserted into the database table,
481
				 * the database server generates a new and unique identifier for
482
				 * that record. This ID can be used for retrieving, updating and
483
				 * deleting that specific record from the table again.
484
				 *
485
				 * For MySQL:
486
				 *  SELECT LAST_INSERT_ID()
487
				 * For PostgreSQL:
488
				 *  SELECT currval('seq_mcus_id')
489
				 * For SQL Server:
490
				 *  SELECT SCOPE_IDENTITY()
491
				 * For Oracle:
492
				 *  SELECT "seq_mcus_id".CURRVAL FROM DUAL
493
				 *
494
				 * There's no way to retrive the new ID by a SQL statements that
495
				 * fits for most database servers as they implement their own
496
				 * specific way.
497
				 *
498
				 * @param string SQL statement for retrieving the last inserted record ID
499
				 * @since 2014.03
500
				 * @category Developer
501
				 * @see mshop/customer/manager/typo3/insert
502
				 * @see mshop/customer/manager/typo3/update
503
				 * @see mshop/customer/manager/typo3/delete
504
				 * @see mshop/customer/manager/typo3/search
505
				 * @see mshop/customer/manager/typo3/count
506
				 */
507
				$path = 'mshop/customer/manager/typo3/newid';
508
				$item->setId( $this->newId( $conn, $path ) );
509
			}
510
511
			$dbm->release( $conn, $dbname );
512
		}
513
		catch( \Exception $e )
514
		{
515
			$dbm->release( $conn, $dbname );
516
			throw $e;
517
		}
518
519
		$item = $this->savePropertyItems( $item, 'customer' );
520
		$item = $this->saveAddressItems( $item, 'customer' );
521
		return $this->saveListItems( $item, 'customer' );
522
	}
523
524
525
	/**
526
	 * Returns the item objects matched by the given search criteria.
527
	 *
528
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
529
	 * @param integer &$total Number of items that are available in total
530
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface
531
	 * @throws \Aimeos\MShop\Customer\Exception If creating items failed
532
	 */
533
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
534
	{
535
		$dbm = $this->getContext()->getDatabaseManager();
536
		$dbname = $this->getResourceName();
537
		$conn = $dbm->acquire( $dbname );
538
		$map = [];
539
540
		try
541
		{
542
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
543
			$cfgPathSearch = 'mshop/customer/manager/typo3/search';
544
			$cfgPathCount = 'mshop/customer/manager/typo3/count';
545
			$required = array( 'customer' );
546
547
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level, $this->plugins );
548
			while( ( $row = $results->fetch() ) !== false ) {
549
				$map[ $row['customer.id'] ] = $row;
550
			}
551
552
			$dbm->release( $conn, $dbname );
553
		}
554
		catch( \Exception $e )
555
		{
556
			$dbm->release( $conn, $dbname  );
557
			throw $e;
558
		}
559
560
		$addrItems = [];
561
		if( in_array( 'customer/address', $ref, true ) ) {
562
			$addrItems = $this->getAddressItems( array_keys( $map ), 'customer' );
563
		}
564
565
		$propItems = [];
566
		if( in_array( 'customer/property', $ref, true ) ) {
567
			$propItems = $this->getPropertyItems( array_keys( $map ), 'customer' );
568
		}
569
570
		return $this->buildItems( $map, $ref, 'customer', $addrItems, $propItems );
571
	}
572
573
574
	/**
575
	 * Returns a new manager for customer extensions
576
	 *
577
	 * @param string $manager Name of the sub manager type in lower case
578
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
579
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
580
	 */
581
	public function getSubManager( $manager, $name = null )
582
	{
583
		return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Typo3' : $name ) );
584
	}
585
586
587
	/**
588
	 * Creates a new customer item.
589
	 *
590
	 * @param array $values List of attributes for customer item
591
	 * @param array $listItems List items associated to the customer item
592
	 * @param array $refItems Items referenced by the customer item via the list items
593
	 * @param array $addresses List of address items of the customer item
594
	 * @param array $propItems List of property items of the customer item
595
	 * @return \Aimeos\MShop\Customer\Item\Iface New customer item
596
	 */
597
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [],
598
		array $addresses = [], array $propItems = [] )
599
	{
600
		$helper = $this->getPasswordHelper();
601
		$address = $this->getAddressManager()->createItem();
602
		$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId();
603
604
		if( array_key_exists( 'date_of_birth', $values ) ) {
605
			$values['customer.birthday'] = $this->reverse['date_of_birth']->reverse( $values['date_of_birth'] );
606
		}
607
608
		if( array_key_exists( 'gender', $values ) ) {
609
			$values['customer.salutation'] = $this->reverse['gender']->reverse( $values['gender'] );
610
		}
611
612
		if( array_key_exists( 'disable', $values ) ) {
613
			$values['customer.status'] = $this->reverse['disable']->reverse( $values['disable'] );
614
		}
615
616
		if( array_key_exists( 'tstamp', $values ) ) {
617
			$values['customer.mtime'] = $this->reverse['tstamp']->reverse( $values['tstamp'] );
618
		}
619
620
		if( array_key_exists( 'crdate', $values ) ) {
621
			$values['customer.ctime'] = $this->reverse['crdate']->reverse( $values['crdate'] );
622
		}
623
624
		if( array_key_exists( 'groups', $values ) ) {
625
			$values['groups'] = explode( ',', $values['groups'] );
626
		}
627
628
		return new \Aimeos\MShop\Customer\Item\Typo3(
629
			$address, $values, $listItems, $refItems,
0 ignored issues
show
Bug introduced by
$address of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Common\Item\Address\Iface expected by parameter $address of Aimeos\MShop\Customer\Item\Typo3::__construct(). ( Ignorable by Annotation )

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

629
			/** @scrutinizer ignore-type */ $address, $values, $listItems, $refItems,
Loading history...
630
			null, $helper, $addresses, $propItems
631
		);
632
	}
633
634
635
	/**
636
	 * Returns the address sub-manager.
637
	 *
638
	 * @return \Aimeos\MShop\Common\Manager\Iface Customer address manager
639
	 */
640
	protected function getAddressManager()
641
	{
642
		if( !isset( $this->addressManager ) ) {
0 ignored issues
show
Bug introduced by
The property addressManager is declared private in Aimeos\MShop\Customer\Manager\Base and cannot be accessed from this context.
Loading history...
643
			$this->addressManager = $this->getObject()->getSubManager( 'address' );
644
		}
645
646
		return $this->addressManager;
647
	}
648
649
650
	/**
651
	 * Returns a password helper object based on the configuration.
652
	 *
653
	 * @return \Aimeos\MShop\Common\Item\Helper\Password\Iface Password helper object
654
	 * @throws \Aimeos\MShop\Exception If the name is invalid or the class isn't found
655
	 */
656
	protected function getPasswordHelper()
657
	{
658
		if( $this->helper ) {
659
			return $this->helper;
660
		}
661
662
		$classname = '\\Aimeos\\MShop\\Common\\Item\\Helper\\Password\\Typo3';
663
664
		if( class_exists( $classname ) === false ) {
665
			throw new \Aimeos\MShop\Exception( sprintf( 'Class "%1$s" not available', $classname ) );
666
		}
667
668
		$context = $this->getContext();
669
		$object = ( method_exists( $context, 'getHasherTypo3' ) ? $context->getHasherTypo3() : null );
670
671
		$helper = new $classname( array( 'object' => $object ) );
672
673
		self::checkClass( '\\Aimeos\\MShop\\Common\\Item\\Helper\\Password\\Iface', $helper );
674
675
		$this->helper = $helper;
676
677
		return $helper;
678
	}
679
}
680