Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

Standard::getAddressItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
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), 2015-2017
7
 * @package MShop
8
 * @subpackage Supplier
9
 */
10
11
12
namespace Aimeos\MShop\Supplier\Manager;
13
14
15
/**
16
 * Class \Aimeos\MShop\Supplier\Manager\Standard.
17
 *
18
 * @package MShop
19
 * @subpackage Supplier
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Manager\ListRef\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
23
	implements \Aimeos\MShop\Supplier\Manager\Iface
24
{
25
	use \Aimeos\MShop\Common\Manager\AddressRef\Traits;
26
27
28
	private $searchConfig = array(
29
		'supplier.id' => array(
30
			'code' => 'supplier.id',
31
			'internalcode' => 'msup."id"',
32
			'label' => 'ID',
33
			'type' => 'integer',
34
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
35
			'public' => false,
36
		),
37
		'supplier.siteid' => array(
38
			'code' => 'supplier.siteid',
39
			'internalcode' => 'msup."siteid"',
40
			'label' => 'Site ID',
41
			'type' => 'integer',
42
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
43
			'public' => false,
44
		),
45
		'supplier.label' => array(
46
			'code' => 'supplier.label',
47
			'internalcode' => 'msup."label"',
48
			'label' => 'Label',
49
			'type' => 'string',
50
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
51
		),
52
		'supplier.code' => array(
53
			'code' => 'supplier.code',
54
			'internalcode' => 'msup."code"',
55
			'label' => 'Code',
56
			'type' => 'string',
57
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
58
		),
59
		'supplier.status' => array(
60
			'code' => 'supplier.status',
61
			'internalcode' => 'msup."status"',
62
			'label' => 'Status',
63
			'type' => 'integer',
64
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
65
		),
66
		'supplier.ctime' => array(
67
			'code' => 'supplier.ctime',
68
			'internalcode' => 'msup."ctime"',
69
			'label' => 'Create date/time',
70
			'type' => 'datetime',
71
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
72
			'public' => false,
73
		),
74
		'supplier.mtime' => array(
75
			'code' => 'supplier.mtime',
76
			'internalcode' => 'msup."mtime"',
77
			'label' => 'Modify date/time',
78
			'type' => 'datetime',
79
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
80
			'public' => false,
81
		),
82
		'supplier.editor' => array(
83
			'code' => 'supplier.editor',
84
			'internalcode' => 'msup."editor"',
85
			'label' => 'Editor',
86
			'type' => 'string',
87
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
88
			'public' => false,
89
		),
90
	);
91
92
93
	/**
94
	 * Initializes the object.
95
	 *
96
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
97
	 */
98
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
99
	{
100
		parent::__construct( $context );
101
		$this->setResourceName( 'db-supplier' );
102
	}
103
104
105
	/**
106
	 * Removes old entries from the storage.
107
	 *
108
	 * @param integer[] $siteids List of IDs for sites whose entries should be deleted
109
	 */
110
	public function cleanup( array $siteids )
111
	{
112
		$path = 'mshop/supplier/manager/submanagers';
113
		foreach( $this->getContext()->getConfig()->get( $path, array( 'address' ) ) as $domain ) {
114
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
115
		}
116
117
		$this->cleanupBase( $siteids, 'mshop/supplier/manager/standard/delete' );
118
	}
119
120
121
	/**
122
	 * Returns the available manager types
123
	 *
124
	 * @param boolean $withsub Return also the resource type of sub-managers if true
125
	 * @return array Type of the manager and submanagers, subtypes are separated by slashes
126
	 */
127
	public function getResourceType( $withsub = true )
128
	{
129
		$path = 'mshop/supplier/manager/submanagers';
130
131
		return $this->getResourceTypeBase( 'supplier', $path, array( 'address', 'lists' ), $withsub );
132
	}
133
134
135
	/**
136
	 * Returns the attributes that can be used for searching.
137
	 *
138
	 * @param boolean $withsub Return also attributes of sub-managers if true
139
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
140
	 */
141
	public function getSearchAttributes( $withsub = true )
142
	{
143
		/** mshop/supplier/manager/submanagers
144
		 * List of manager names that can be instantiated by the supplier manager
145
		 *
146
		 * Managers provide a generic interface to the underlying storage.
147
		 * Each manager has or can have sub-managers caring about particular
148
		 * aspects. Each of these sub-managers can be instantiated by its
149
		 * parent manager using the getSubManager() method.
150
		 *
151
		 * The search keys from sub-managers can be normally used in the
152
		 * manager as well. It allows you to search for items of the manager
153
		 * using the search keys of the sub-managers to further limit the
154
		 * retrieved list of items.
155
		 *
156
		 * @param array List of sub-manager names
157
		 * @since 2014.03
158
		 * @category Developer
159
		 */
160
		$path = 'mshop/supplier/manager/submanagers';
161
162
		return $this->getSearchAttributesBase( $this->searchConfig, $path, array( 'address', 'lists' ), $withsub );
163
	}
164
165
166
	/**
167
	 * Instantiates a new supplier item object.
168
	 *
169
	 * @return \Aimeos\MShop\Supplier\Item\Iface
170
	 */
171
	public function createItem()
172
	{
173
		$values = array('supplier.siteid' => $this->getContext()->getLocale()->getSiteId());
174
		return $this->createItemBase($values);
175
	}
176
177
178
	/**
179
	 * Removes multiple items specified by ids in the array.
180
	 *
181
	 * @param array $ids List of IDs
182
	 */
183
	public function deleteItems( array $ids )
184
	{
185
		/** mshop/supplier/manager/standard/delete/mysql
186
		 * Deletes the items matched by the given IDs from the database
187
		 *
188
		 * @see mshop/supplier/manager/standard/delete/ansi
189
		 */
190
191
		/** mshop/supplier/manager/standard/delete/ansi
192
		 * Deletes the items matched by the given IDs from the database
193
		 *
194
		 * Removes the records specified by the given IDs from the supplier database.
195
		 * The records must be from the site that is configured via the
196
		 * context item.
197
		 *
198
		 * The ":cond" placeholder is replaced by the name of the ID column and
199
		 * the given ID or list of IDs while the site ID is bound to the question
200
		 * mark.
201
		 *
202
		 * The SQL statement should conform to the ANSI standard to be
203
		 * compatible with most relational database systems. This also
204
		 * includes using double quotes for table and column names.
205
		 *
206
		 * @param string SQL statement for deleting items
207
		 * @since 2014.03
208
		 * @category Developer
209
		 * @see mshop/supplier/manager/standard/insert/ansi
210
		 * @see mshop/supplier/manager/standard/update/ansi
211
		 * @see mshop/supplier/manager/standard/newid/ansi
212
		 * @see mshop/supplier/manager/standard/search/ansi
213
		 * @see mshop/supplier/manager/standard/count/ansi
214
		 */
215
		$path = 'mshop/supplier/manager/standard/delete';
216
		$this->deleteItemsBase( $ids, $path );
217
	}
218
219
220
	/**
221
	 * Returns the item specified by its code and domain/type if necessary
222
	 *
223
	 * @param string $code Code of the item
224
	 * @param string[] $ref List of domains to fetch list items and referenced items for
225
	 * @param string|null $domain Domain of the item if necessary to identify the item uniquely
226
	 * @param string|null $type Type code of the item if necessary to identify the item uniquely
227
	 * @param boolean $default True to add default criteria
228
	 * @return \Aimeos\MShop\Common\Item\Iface Item object
229
	 */
230
	public function findItem( $code, array $ref = [], $domain = null, $type = null, $default = false )
231
	{
232
		return $this->findItemBase( array( 'supplier.code' => $code ), $ref, $default );
233
	}
234
235
236
	/**
237
	 * Returns the supplier item object specificed by its ID.
238
	 *
239
	 * @param integer $id Unique supplier ID referencing an existing supplier
240
	 * @param string[] $ref List of domains to fetch list items and referenced items for
241
	 * @param boolean $default Add default criteria
242
	 * @return \Aimeos\MShop\Supplier\Item\Iface Returns the supplier item of the given id
243
	 * @throws \Aimeos\MShop\Exception If item couldn't be found
244
	 */
245
	public function getItem( $id, array $ref = [], $default = false )
246
	{
247
		return $this->getItemBase( 'supplier.id', $id, $ref, $default );
248
	}
249
250
251
	/**
252
	 * Saves a supplier item object.
253
	 *
254
	 * @param \Aimeos\MShop\Supplier\Item\Iface $item Supplier item object
255
	 * @param boolean $fetch True if the new ID should be returned in the item
256
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
0 ignored issues
show
Documentation introduced by
Should the return type not be \Aimeos\MShop\Common\Item\ListRef\Iface?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
257
	 */
258
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
259
	{
260
		$iface = '\\Aimeos\\MShop\\Supplier\\Item\\Iface';
261
		if( !( $item instanceof $iface ) ) {
262
			throw new \Aimeos\MShop\Supplier\Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) );
263
		}
264
265
		if( !$item->isModified() )
266
		{
267
			$item = $this->saveAddressItems( $item, 'supplier' );
0 ignored issues
show
Documentation introduced by
$item is of type object<Aimeos\MShop\Common\Item\Iface>, but the function expects a object<Aimeos\MShop\Common\Item\AddressRef\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
			return $this->saveRefItems( $item, 'supplier' );
0 ignored issues
show
Documentation introduced by
$item is of type object<Aimeos\MShop\Common\Item\AddressRef\Iface>, but the function expects a object<Aimeos\MShop\Common\Item\ListRef\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
269
		}
270
271
		$context = $this->getContext();
272
273
		$dbm = $context->getDatabaseManager();
274
		$dbname = $this->getResourceName();
275
		$conn = $dbm->acquire( $dbname );
276
277
		try
278
		{
279
			$id = $item->getId();
280
			$date = date( 'Y-m-d H:i:s' );
281
282
			if( $id === null )
283
			{
284
				/** mshop/supplier/manager/standard/insert/mysql
285
				 * Inserts a new supplier record into the database table
286
				 *
287
				 * @see mshop/supplier/manager/standard/insert/ansi
288
				 */
289
290
				/** mshop/supplier/manager/standard/insert/ansi
291
				 * Inserts a new supplier record into the database table
292
				 *
293
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
294
				 * the database and the newly created ID retrieved afterwards
295
				 * using the "newid" SQL statement.
296
				 *
297
				 * The SQL statement must be a string suitable for being used as
298
				 * prepared statement. It must include question marks for binding
299
				 * the values from the supplier item to the statement before they are
300
				 * sent to the database server. The number of question marks must
301
				 * be the same as the number of columns listed in the INSERT
302
				 * statement. The order of the columns must correspond to the
303
				 * order in the saveItems() method, so the correct values are
304
				 * bound to the columns.
305
				 *
306
				 * The SQL statement should conform to the ANSI standard to be
307
				 * compatible with most relational database systems. This also
308
				 * includes using double quotes for table and column names.
309
				 *
310
				 * @param string SQL statement for inserting records
311
				 * @since 2014.03
312
				 * @category Developer
313
				 * @see mshop/supplier/manager/standard/update/ansi
314
				 * @see mshop/supplier/manager/standard/newid/ansi
315
				 * @see mshop/supplier/manager/standard/delete/ansi
316
				 * @see mshop/supplier/manager/standard/search/ansi
317
				 * @see mshop/supplier/manager/standard/count/ansi
318
				 */
319
				$path = 'mshop/supplier/manager/standard/insert';
320
			}
321
			else
322
			{
323
				/** mshop/supplier/manager/standard/update/mysql
324
				 * Updates an existing supplier record in the database
325
				 *
326
				 * @see mshop/supplier/manager/standard/update/ansi
327
				 */
328
329
				/** mshop/supplier/manager/standard/update/ansi
330
				 * Updates an existing supplier record in the database
331
				 *
332
				 * Items which already have an ID (i.e. the ID is not NULL) will
333
				 * be updated in the database.
334
				 *
335
				 * The SQL statement must be a string suitable for being used as
336
				 * prepared statement. It must include question marks for binding
337
				 * the values from the supplier item to the statement before they are
338
				 * sent to the database server. The order of the columns must
339
				 * correspond to the order in the saveItems() method, so the
340
				 * correct values are bound to the columns.
341
				 *
342
				 * The SQL statement should conform to the ANSI standard to be
343
				 * compatible with most relational database systems. This also
344
				 * includes using double quotes for table and column names.
345
				 *
346
				 * @param string SQL statement for updating records
347
				 * @since 2014.03
348
				 * @category Developer
349
				 * @see mshop/supplier/manager/standard/insert/ansi
350
				 * @see mshop/supplier/manager/standard/newid/ansi
351
				 * @see mshop/supplier/manager/standard/delete/ansi
352
				 * @see mshop/supplier/manager/standard/search/ansi
353
				 * @see mshop/supplier/manager/standard/count/ansi
354
				 */
355
				$path = 'mshop/supplier/manager/standard/update';
356
			}
357
358
			$stmt = $this->getCachedStatement( $conn, $path );
359
360
			$stmt->bind( 1, $item->getCode() );
361
			$stmt->bind( 2, $item->getLabel() );
362
			$stmt->bind( 3, $item->getStatus(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
363
			$stmt->bind( 4, $date ); // mtime
364
			$stmt->bind( 5, $context->getEditor() );
365
			$stmt->bind( 6, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
366
367
			if( $id !== null ) {
368
				$stmt->bind( 7, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
369
				$item->setId( $id );
370
			} else {
371
				$stmt->bind( 7, $date ); // ctime
372
			}
373
374
			$stmt->execute()->finish();
375
376
			if( $id === null && $fetch === true )
377
			{
378
				/** mshop/supplier/manager/standard/newid/mysql
379
				 * Retrieves the ID generated by the database when inserting a new record
380
				 *
381
				 * @see mshop/supplier/manager/standard/newid/ansi
382
				 */
383
384
				/** mshop/supplier/manager/standard/newid/ansi
385
				 * Retrieves the ID generated by the database when inserting a new record
386
				 *
387
				 * As soon as a new record is inserted into the database table,
388
				 * the database server generates a new and unique identifier for
389
				 * that record. This ID can be used for retrieving, updating and
390
				 * deleting that specific record from the table again.
391
				 *
392
				 * For MySQL:
393
				 *  SELECT LAST_INSERT_ID()
394
				 * For PostgreSQL:
395
				 *  SELECT currval('seq_msup_id')
396
				 * For SQL Server:
397
				 *  SELECT SCOPE_IDENTITY()
398
				 * For Oracle:
399
				 *  SELECT "seq_msup_id".CURRVAL FROM DUAL
400
				 *
401
				 * There's no way to retrive the new ID by a SQL statements that
402
				 * fits for most database servers as they implement their own
403
				 * specific way.
404
				 *
405
				 * @param string SQL statement for retrieving the last inserted record ID
406
				 * @since 2014.03
407
				 * @category Developer
408
				 * @see mshop/supplier/manager/standard/insert/ansi
409
				 * @see mshop/supplier/manager/standard/update/ansi
410
				 * @see mshop/supplier/manager/standard/delete/ansi
411
				 * @see mshop/supplier/manager/standard/search/ansi
412
				 * @see mshop/supplier/manager/standard/count/ansi
413
				 */
414
				$path = 'mshop/supplier/manager/standard/newid';
415
				$item->setId( $this->newId( $conn, $path ) );
416
			}
417
418
			$dbm->release( $conn, $dbname );
419
		}
420
		catch( \Exception $e )
421
		{
422
			$dbm->release( $conn, $dbname );
423
			throw $e;
424
		}
425
426
		$item = $this->saveAddressItems( $item, 'supplier' );
0 ignored issues
show
Documentation introduced by
$item is of type object<Aimeos\MShop\Common\Item\Iface>, but the function expects a object<Aimeos\MShop\Common\Item\AddressRef\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
427
		return $this->saveRefItems( $item, 'supplier' );
0 ignored issues
show
Documentation introduced by
$item is of type object<Aimeos\MShop\Common\Item\AddressRef\Iface>, but the function expects a object<Aimeos\MShop\Common\Item\ListRef\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
428
	}
429
430
431
	/**
432
	 * Returns the item objects matched by the given search criteria.
433
	 *
434
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
435
	 * @param string[] $ref List of domains to fetch list items and referenced items for
436
	 * @param integer|null &$total Number of items that are available in total
437
	 * @return array List of supplier items implementing \Aimeos\MShop\Supplier\Item\Iface
438
	 */
439
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
440
	{
441
		$map = [];
442
		$context = $this->getContext();
443
444
		$dbm = $context->getDatabaseManager();
445
		$dbname = $this->getResourceName();
446
		$conn = $dbm->acquire( $dbname );
447
448
		try
449
		{
450
			$required = array( 'supplier' );
451
452
			/** mshop/supplier/manager/sitemode
453
			 * Mode how items from levels below or above in the site tree are handled
454
			 *
455
			 * By default, only items from the current site are fetched from the
456
			 * storage. If the ai-sites extension is installed, you can create a
457
			 * tree of sites. Then, this setting allows you to define for the
458
			 * whole supplier domain if items from parent sites are inherited,
459
			 * sites from child sites are aggregated or both.
460
			 *
461
			 * Available constants for the site mode are:
462
			 * * 0 = only items from the current site
463
			 * * 1 = inherit items from parent sites
464
			 * * 2 = aggregate items from child sites
465
			 * * 3 = inherit and aggregate items at the same time
466
			 *
467
			 * You also need to set the mode in the locale manager
468
			 * (mshop/locale/manager/standard/sitelevel) to one of the constants.
469
			 * If you set it to the same value, it will work as described but you
470
			 * can also use different modes. For example, if inheritance and
471
			 * aggregation is configured the locale manager but only inheritance
472
			 * in the domain manager because aggregating items makes no sense in
473
			 * this domain, then items wil be only inherited. Thus, you have full
474
			 * control over inheritance and aggregation in each domain.
475
			 *
476
			 * @param integer Constant from Aimeos\MShop\Locale\Manager\Base class
477
			 * @category Developer
478
			 * @since 2018.01
479
			 * @see mshop/locale/manager/standard/sitelevel
480
			 */
481
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
482
			$level = $context->getConfig()->get( 'mshop/supplier/manager/sitemode', $level );
483
484
			/** mshop/supplier/manager/standard/search/mysql
485
			 * Retrieves the records matched by the given criteria in the database
486
			 *
487
			 * @see mshop/supplier/manager/standard/search/ansi
488
			 */
489
490
			/** mshop/supplier/manager/standard/search/ansi
491
			 * Retrieves the records matched by the given criteria in the database
492
			 *
493
			 * Fetches the records matched by the given criteria from the supplier
494
			 * database. The records must be from one of the sites that are
495
			 * configured via the context item. If the current site is part of
496
			 * a tree of sites, the SELECT statement can retrieve all records
497
			 * from the current site and the complete sub-tree of sites.
498
			 *
499
			 * As the records can normally be limited by criteria from sub-managers,
500
			 * their tables must be joined in the SQL context. This is done by
501
			 * using the "internaldeps" property from the definition of the ID
502
			 * column of the sub-managers. These internal dependencies specify
503
			 * the JOIN between the tables and the used columns for joining. The
504
			 * ":joins" placeholder is then replaced by the JOIN strings from
505
			 * the sub-managers.
506
			 *
507
			 * To limit the records matched, conditions can be added to the given
508
			 * criteria object. It can contain comparisons like column names that
509
			 * must match specific values which can be combined by AND, OR or NOT
510
			 * operators. The resulting string of SQL conditions replaces the
511
			 * ":cond" placeholder before the statement is sent to the database
512
			 * server.
513
			 *
514
			 * If the records that are retrieved should be ordered by one or more
515
			 * columns, the generated string of column / sort direction pairs
516
			 * replaces the ":order" placeholder. In case no ordering is required,
517
			 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
518
			 * markers is removed to speed up retrieving the records. Columns of
519
			 * sub-managers can also be used for ordering the result set but then
520
			 * no index can be used.
521
			 *
522
			 * The number of returned records can be limited and can start at any
523
			 * number between the begining and the end of the result set. For that
524
			 * the ":size" and ":start" placeholders are replaced by the
525
			 * corresponding values from the criteria object. The default values
526
			 * are 0 for the start and 100 for the size value.
527
			 *
528
			 * The SQL statement should conform to the ANSI standard to be
529
			 * compatible with most relational database systems. This also
530
			 * includes using double quotes for table and column names.
531
			 *
532
			 * @param string SQL statement for searching items
533
			 * @since 2014.03
534
			 * @category Developer
535
			 * @see mshop/supplier/manager/standard/insert/ansi
536
			 * @see mshop/supplier/manager/standard/update/ansi
537
			 * @see mshop/supplier/manager/standard/newid/ansi
538
			 * @see mshop/supplier/manager/standard/delete/ansi
539
			 * @see mshop/supplier/manager/standard/count/ansi
540
			 */
541
			$cfgPathSearch = 'mshop/supplier/manager/standard/search';
542
543
			/** mshop/supplier/manager/standard/count/mysql
544
			 * Counts the number of records matched by the given criteria in the database
545
			 *
546
			 * @see mshop/supplier/manager/standard/count/ansi
547
			 */
548
549
			/** mshop/supplier/manager/standard/count/ansi
550
			 * Counts the number of records matched by the given criteria in the database
551
			 *
552
			 * Counts all records matched by the given criteria from the supplier
553
			 * database. The records must be from one of the sites that are
554
			 * configured via the context item. If the current site is part of
555
			 * a tree of sites, the statement can count all records from the
556
			 * current site and the complete sub-tree of sites.
557
			 *
558
			 * As the records can normally be limited by criteria from sub-managers,
559
			 * their tables must be joined in the SQL context. This is done by
560
			 * using the "internaldeps" property from the definition of the ID
561
			 * column of the sub-managers. These internal dependencies specify
562
			 * the JOIN between the tables and the used columns for joining. The
563
			 * ":joins" placeholder is then replaced by the JOIN strings from
564
			 * the sub-managers.
565
			 *
566
			 * To limit the records matched, conditions can be added to the given
567
			 * criteria object. It can contain comparisons like column names that
568
			 * must match specific values which can be combined by AND, OR or NOT
569
			 * operators. The resulting string of SQL conditions replaces the
570
			 * ":cond" placeholder before the statement is sent to the database
571
			 * server.
572
			 *
573
			 * Both, the strings for ":joins" and for ":cond" are the same as for
574
			 * the "search" SQL statement.
575
			 *
576
			 * Contrary to the "search" statement, it doesn't return any records
577
			 * but instead the number of records that have been found. As counting
578
			 * thousands of records can be a long running task, the maximum number
579
			 * of counted records is limited for performance reasons.
580
			 *
581
			 * The SQL statement should conform to the ANSI standard to be
582
			 * compatible with most relational database systems. This also
583
			 * includes using double quotes for table and column names.
584
			 *
585
			 * @param string SQL statement for counting items
586
			 * @since 2014.03
587
			 * @category Developer
588
			 * @see mshop/supplier/manager/standard/insert/ansi
589
			 * @see mshop/supplier/manager/standard/update/ansi
590
			 * @see mshop/supplier/manager/standard/newid/ansi
591
			 * @see mshop/supplier/manager/standard/delete/ansi
592
			 * @see mshop/supplier/manager/standard/search/ansi
593
			 */
594
			$cfgPathCount =  'mshop/supplier/manager/standard/count';
595
596
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
597
			while( ( $row = $results->fetch() ) !== false ) {
598
				$map[$row['supplier.id']] = $row;
599
			}
600
601
			$dbm->release( $conn, $dbname );
602
		}
603
		catch( \Exception $e )
604
		{
605
			$dbm->release( $conn, $dbname );
606
			throw $e;
607
		}
608
609
		$addrItems = [];
610
		if( in_array( 'supplier/address', $ref, true ) ) {
611
			$addrItems = $this->getAddressItems( array_keys( $map ), 'supplier' );
612
		}
613
614
		return $this->buildItems( $map, $ref, 'supplier', $addrItems );
615
	}
616
617
618
	/**
619
	 * Creates a new manager for supplier
620
	 *
621
	 * @param string $manager Name of the sub manager type in lower case
622
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
623
	 * @return \Aimeos\MShop\Common\Manager\Address\Iface Returns a address manager
624
	 * @throws \Aimeos\MShop\Supplier\Exception If creating manager failed
625
	 */
626
	public function getSubManager( $manager, $name = null )
627
	{
628
		return $this->getSubManagerBase( 'supplier', $manager, $name );
629
	}
630
631
632
	/**
633
	 * creates a search object and sets base criteria
634
	 *
635
	 * @param boolean $default
636
	 * @return \Aimeos\MW\Criteria\Iface
637
	 */
638
	public function createSearch($default = false)
639
	{
640
		if ($default) {
641
			return $this->createSearchBase('supplier');
642
		}
643
644
		return parent::createSearch();
645
	}
646
647
648
	/**
649
	 * Creates a new supplier item.
650
	 *
651
	 * @param array $values List of attributes for supplier item
652
	 * @param array $listitems Associative list of list item IDs as keys and \Aimeos\MShop\Common\Item\List\Iface as values
653
	 * @param array $refItems Associative list of item IDs as keys and \Aimeos\MShop\Common\Item\Iface as values
654
	 * @param array $addresses List of address items of the supplier item
655
	 * @return \Aimeos\MShop\Supplier\Item\Iface New supplier item
656
	 */
657
	protected function createItemBase( array $values = [], array $listitems = [], array $refItems = [], array $addresses = [] )
658
	{
659
		return new \Aimeos\MShop\Supplier\Item\Standard( $values, $listitems, $refItems, $addresses );
660
	}
661
}
662