Passed
Push — 2019.01 ( adfca6...e67180 )
by Aimeos
02:17
created

Typo3::saveItem()   C

Complexity

Conditions 9
Paths 349

Size

Total Lines 182
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 182
rs 5.0514
c 0
b 0
f 0
cc 9
nc 349
nop 2

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 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' => 'float',
179
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT,
180
		),
181
		'customer.latitude' => array(
182
			'label' => 'Customer latitude',
183
			'code' => 'customer.latitude',
184
			'internalcode' => 't3feu."latitude"',
185
			'type' => 'float',
186
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT,
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 array $values Values the item should be initialized with
308
	 * @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...
309
	 */
310
	public function createItem( array $values = [] )
311
	{
312
		$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId();
313
		$values['typo3.pageid'] = $this->pid;
314
315
		return $this->createItemBase( $values );
316
	}
317
318
319
	/**
320
	 * Deletes a customer item object from the permanent storage.
321
	 *
322
	 * @param array $ids List of customer IDs
323
	 */
324
	public function deleteItems( array $ids )
325
	{
326
		$path = 'mshop/customer/manager/typo3/delete';
327
		$this->deleteItemsBase( $ids, $path, false, 'uid' );
328
329
		$manager = $this->getObject()->getSubManager( 'address' );
330
		$search = $manager->createSearch()->setSlice( 0, 0x7fffffff );
331
		$search->setConditions( $search->compare( '==', 'customer.address.parentid', $ids ) );
332
		$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) );
333
334
		$manager = $this->getObject()->getSubManager( 'lists' );
335
		$search = $manager->createSearch()->setSlice( 0, 0x7fffffff );
336
		$search->setConditions( $search->compare( '==', 'customer.lists.parentid', $ids ) );
337
		$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) );
338
339
		$manager = $this->getObject()->getSubManager( 'property' );
340
		$search = $manager->createSearch()->setSlice( 0, 0x7fffffff );
341
		$search->setConditions( $search->compare( '==', 'customer.property.parentid', $ids ) );
342
		$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) );
343
	}
344
345
346
	/**
347
	 * Saves a customer item object.
348
	 *
349
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
350
	 * @param boolean $fetch True if the new ID should be returned in the item
351
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
352
	 */
353
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
354
	{
355
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item );
356
357
		if( !$item->isModified() )
358
		{
359
			$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

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