Completed
Push — master ( 534c86...27e359 )
by Aimeos
02:38
created

Laravel::createItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2017
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 Laravel
21
	extends \Aimeos\MShop\Customer\Manager\Standard
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
22
{
23
	private $searchConfig = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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' => 'lvu."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' => 'lvu."name"',
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' => 'lvu."label"',
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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."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' => 'lvu."longitude"',
177
			'type' => 'string',
178
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
179
		),
180
		'customer.latitude' => array(
181
			'label' => 'Customer latitude',
182
			'code' => 'customer.latitude',
183
			'internalcode' => 'lvu."latitude"',
184
			'type' => 'string',
185
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
186
		),
187
		'customer.birthday' => array(
188
			'label' => 'Customer birthday',
189
			'code' => 'customer.birthday',
190
			'internalcode' => 'lvu."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' => 'lvu."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' => 'lvu."status"',
205
			'type' => 'integer',
206
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
207
		),
208
		'customer.dateverified'=> array(
209
			'label' => 'Customer verification date',
210
			'code' => 'customer.dateverified',
211
			'internalcode' => 'lvu."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' => 'lvu."created_at"',
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' => 'lvu."updated_at"',
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' => 'lvu."editor"',
233
			'type'=> 'string',
234
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
235
		),
236
	);
237
238
239
	/**
240
	 * Removes old entries from the storage.
241
	 *
242
	 * @param array $siteids List of IDs for sites whose entries should be deleted
243
	 */
244
	public function cleanup( array $siteids )
245
	{
246
		$path = 'mshop/customer/manager/submanagers';
247
		$default = ['address', 'group', 'lists', 'property'];
248
249
		foreach( $this->getContext()->getConfig()->get( $path, $default ) as $domain ) {
250
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
251
		}
252
	}
253
254
255
	/**
256
	 * Removes multiple items specified by ids in the array.
257
	 *
258
	 * @param array $ids List of IDs
259
	 */
260
	public function deleteItems( array $ids )
261
	{
262
		$path = 'mshop/customer/manager/laravel/delete';
263
		$this->deleteItemsBase( $ids, $path, false );
264
	}
265
266
267
	/**
268
	 * Returns the list attributes that can be used for searching.
269
	 *
270
	 * @param boolean $withsub Return also attributes of sub-managers if true
271
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
272
	 */
273
	public function getSearchAttributes( $withsub = true )
274
	{
275
		$path = 'mshop/customer/manager/submanagers';
276
		$default = ['address', 'group', 'lists', 'property'];
277
278
		return $this->getSearchAttributesBase( $this->searchConfig, $path, $default, $withsub );
279
	}
280
281
282
	/**
283
	 * Saves a customer item object.
284
	 *
285
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
286
	 * @param boolean $fetch True if the new ID should be returned in the item
287
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
288
	 */
289
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
290
	{
291
		$iface = '\\Aimeos\\MShop\\Customer\\Item\\Iface';
292
		if( !( $item instanceof $iface ) ) {
293
			throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) );
294
		}
295
296
		if( !$item->isModified() )
297
		{
298
			$item = $this->savePropertyItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method savePropertyItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
299
			$item = $this->saveAddressItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method saveAddressItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
300
			return $this->saveListItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method saveListItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
301
		}
302
303
		$context = $this->getContext();
304
		$dbm = $context->getDatabaseManager();
305
		$dbname = $this->getResourceName();
306
		$conn = $dbm->acquire( $dbname );
307
308
		try
309
		{
310
			$id = $item->getId();
311
			$date = date( 'Y-m-d H:i:s' );
312
			$billingAddress = $item->getPaymentAddress();
313
314
			if( $id === null )
315
			{
316
				/** mshop/customer/manager/laravel/insert
317
				 * Inserts a new customer record into the database table
318
				 *
319
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
320
				 * the database and the newly created ID retrieved afterwards
321
				 * using the "newid" SQL statement.
322
				 *
323
				 * The SQL statement must be a string suitable for being used as
324
				 * prepared statement. It must include question marks for binding
325
				 * the values from the customer item to the statement before they are
326
				 * sent to the database server. The number of question marks must
327
				 * be the same as the number of columns listed in the INSERT
328
				 * statement. The order of the columns must correspond to the
329
				 * order in the saveItems() method, so the correct values are
330
				 * bound to the columns.
331
				 *
332
				 * The SQL statement should conform to the ANSI standard to be
333
				 * compatible with most relational database systems. This also
334
				 * includes using double quotes for table and column names.
335
				 *
336
				 * @param string SQL statement for inserting records
337
				 * @since 2015.01
338
				 * @category Developer
339
				 * @see mshop/customer/manager/laravel/update
340
				 * @see mshop/customer/manager/laravel/newid
341
				 * @see mshop/customer/manager/laravel/delete
342
				 * @see mshop/customer/manager/laravel/search
343
				 * @see mshop/customer/manager/laravel/count
344
				 */
345
				$path = 'mshop/customer/manager/laravel/insert';
346
			}
347
			else
348
			{
349
				/** mshop/customer/manager/laravel/update
350
				 * Updates an existing customer record in the database
351
				 *
352
				 * Items which already have an ID (i.e. the ID is not NULL) will
353
				 * be updated in the database.
354
				 *
355
				 * The SQL statement must be a string suitable for being used as
356
				 * prepared statement. It must include question marks for binding
357
				 * the values from the customer item to the statement before they are
358
				 * sent to the database server. The order of the columns must
359
				 * correspond to the order in the saveItems() method, so the
360
				 * correct values are bound to the columns.
361
				 *
362
				 * The SQL statement should conform to the ANSI standard to be
363
				 * compatible with most relational database systems. This also
364
				 * includes using double quotes for table and column names.
365
				 *
366
				 * @param string SQL statement for updating records
367
				 * @since 2015.01
368
				 * @category Developer
369
				 * @see mshop/customer/manager/laravel/insert
370
				 * @see mshop/customer/manager/laravel/newid
371
				 * @see mshop/customer/manager/laravel/delete
372
				 * @see mshop/customer/manager/laravel/search
373
				 * @see mshop/customer/manager/laravel/count
374
				 */
375
				$path = 'mshop/customer/manager/laravel/update';
376
			}
377
378
			$stmt = $this->getCachedStatement( $conn, $path );
379
380
			$stmt->bind( 1, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
381
			$stmt->bind( 2, $item->getCode() );
382
			$stmt->bind( 3, $billingAddress->getCompany() );
383
			$stmt->bind( 4, $billingAddress->getVatID() );
384
			$stmt->bind( 5, $billingAddress->getSalutation() );
385
			$stmt->bind( 6, $billingAddress->getTitle() );
386
			$stmt->bind( 7, $billingAddress->getFirstname() );
387
			$stmt->bind( 8, $billingAddress->getLastname() );
388
			$stmt->bind( 9, $billingAddress->getAddress1() );
389
			$stmt->bind( 10, $billingAddress->getAddress2() );
390
			$stmt->bind( 11, $billingAddress->getAddress3() );
391
			$stmt->bind( 12, $billingAddress->getPostal() );
392
			$stmt->bind( 13, $billingAddress->getCity() );
393
			$stmt->bind( 14, $billingAddress->getState() );
394
			$stmt->bind( 15, $billingAddress->getCountryId() );
395
			$stmt->bind( 16, $billingAddress->getLanguageId() );
396
			$stmt->bind( 17, $billingAddress->getTelephone() );
397
			$stmt->bind( 18, $billingAddress->getTelefax() );
398
			$stmt->bind( 19, $billingAddress->getWebsite() );
399
			$stmt->bind( 20, $billingAddress->getEmail() );
400
			$stmt->bind( 21, $billingAddress->getLongitude() );
401
			$stmt->bind( 22, $billingAddress->getLatitude() );
402
			$stmt->bind( 23, $item->getLabel() );
403
			$stmt->bind( 24, $item->getBirthday() );
404
			$stmt->bind( 25, $item->getStatus(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
405
			$stmt->bind( 26, $item->getDateVerified() );
406
			$stmt->bind( 27, $item->getPassword() );
407
			$stmt->bind( 28, $date ); // Modification time
408
			$stmt->bind( 29, $context->getEditor() );
409
410
			if( $id !== null ) {
411
				$stmt->bind( 30, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
412
				$item->setId( $id );
413
			} else {
414
				$stmt->bind( 30, $date ); // Creation time
415
			}
416
417
			$stmt->execute()->finish();
418
419
			if( $id === null && $fetch === true )
420
			{
421
				/** mshop/customer/manager/laravel/newid
422
				 * Retrieves the ID generated by the database when inserting a new record
423
				 *
424
				 * As soon as a new record is inserted into the database table,
425
				 * the database server generates a new and unique identifier for
426
				 * that record. This ID can be used for retrieving, updating and
427
				 * deleting that specific record from the table again.
428
				 *
429
				 * For MySQL:
430
				 *  SELECT LAST_INSERT_ID()
431
				 * For PostgreSQL:
432
				 *  SELECT currval('seq_mcus_id')
433
				 * For SQL Server:
434
				 *  SELECT SCOPE_IDENTITY()
435
				 * For Oracle:
436
				 *  SELECT "seq_mcus_id".CURRVAL FROM DUAL
437
				 *
438
				 * There's no way to retrive the new ID by a SQL statements that
439
				 * fits for most database servers as they implement their own
440
				 * specific way.
441
				 *
442
				 * @param string SQL statement for retrieving the last inserted record ID
443
				 * @since 2015.01
444
				 * @category Developer
445
				 * @see mshop/customer/manager/laravel/insert
446
				 * @see mshop/customer/manager/laravel/update
447
				 * @see mshop/customer/manager/laravel/delete
448
				 * @see mshop/customer/manager/laravel/search
449
				 * @see mshop/customer/manager/laravel/count
450
				 */
451
				$path = 'mshop/customer/manager/laravel/newid';
452
				$item->setId( $this->newId( $conn, $path ) );
453
			}
454
455
			$dbm->release( $conn, $dbname );
456
		}
457
		catch( \Exception $e )
458
		{
459
			$dbm->release( $conn, $dbname );
460
			throw $e;
461
		}
462
463
		$this->addGroups( $item );
464
465
		$item = $this->savePropertyItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method savePropertyItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
466
		$item = $this->saveAddressItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method saveAddressItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
467
		return $this->saveListItems( $item, 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method saveListItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
468
	}
469
470
471
	/**
472
	 * Returns the item objects matched by the given search criteria.
473
	 *
474
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
475
	 * @param integer &$total Number of items that are available in total
476
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface
477
	 * @throws \Aimeos\MShop\Customer\Exception If creating items failed
478
	 */
479
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
480
	{
481
		$dbm = $this->getContext()->getDatabaseManager();
482
		$dbname = $this->getResourceName();
483
		$conn = $dbm->acquire( $dbname );
484
		$map = [];
485
486
		try
487
		{
488
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
489
			$cfgPathSearch = 'mshop/customer/manager/laravel/search';
490
			$cfgPathCount = 'mshop/customer/manager/laravel/count';
491
			$required = array( 'customer' );
492
493
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
494
			while( ( $row = $results->fetch() ) !== false ) {
495
				$map[ $row['customer.id'] ] = $row;
496
			}
497
498
			$dbm->release( $conn, $dbname );
499
		}
500
		catch( \Exception $e )
501
		{
502
			$dbm->release( $conn, $dbname  );
503
			throw $e;
504
		}
505
506
		$addrItems = [];
507
		if( in_array( 'customer/address', $ref, true ) ) {
508
			$addrItems = $this->getAddressItems( array_keys( $map ), 'customer' );
0 ignored issues
show
Unused Code introduced by
The call to Laravel::getAddressItems() has too many arguments starting with 'customer'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
509
		}
510
511
		$propItems = [];
512
		if( in_array( 'customer/property', $ref, true ) ) {
513
			$propItems = $this->getPropertyItems( array_keys( $map ), 'customer' );
0 ignored issues
show
Documentation Bug introduced by
The method getPropertyItems does not exist on object<Aimeos\MShop\Customer\Manager\Laravel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
514
		}
515
516
		return $this->buildItems( $map, $ref, 'customer', $addrItems, $propItems );
0 ignored issues
show
Unused Code introduced by
The call to Laravel::buildItems() has too many arguments starting with $propItems.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
517
	}
518
519
520
	/**
521
	 * Returns a new manager for customer extensions
522
	 *
523
	 * @param string $manager Name of the sub manager type in lower case
524
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
525
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
526
	 */
527
	public function getSubManager( $manager, $name = null )
528
	{
529
		return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Laravel' : $name ) );
530
	}
531
}
532