Passed
Push — master ( 6aab01...0294bc )
by Aimeos
09:44
created

Standard::rebuild()   B

Complexity

Conditions 11
Paths 19

Size

Total Lines 88
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 88
rs 7.3166
c 0
b 0
f 0
cc 11
nc 19
nop 1

How to fix   Long Method    Complexity   

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
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2018-2022
5
 * @package MShop
6
 * @subpackage Index
7
 */
8
9
10
namespace Aimeos\MShop\Index\Manager\Supplier;
11
12
13
/**
14
 * Submanager for supplier.
15
 *
16
 * @package MShop
17
 * @subpackage Index
18
 */
19
class Standard
20
	extends \Aimeos\MShop\Index\Manager\DBBase
21
	implements \Aimeos\MShop\Index\Manager\Supplier\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
22
{
23
	private $searchConfig = array(
24
		'index.supplier.id' => array(
25
			'code' => 'index.supplier.id',
26
			'internalcode' => 'mindsu."supid"',
27
			'internaldeps'=>array( 'LEFT JOIN "mshop_index_supplier" AS mindsu ON mindsu."prodid" = mpro."id"' ),
28
			'label' => 'Product index supplier ID',
29
			'type' => 'string',
30
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
31
			'public' => false,
32
		),
33
		'index.supplier:radius' => array(
34
			'code' => 'index.supplier:radius()',
35
			'internalcode' => ':site AND
36
				mindsu."latitude" > $1 - $3 / 111.19493 AND
37
				mindsu."latitude" < $1 + $3 / 111.19493 AND
38
				mindsu."longitude" > $2 - $3 / 111.19493 / COS( RADIANS( $2 ) ) AND
39
				mindsu."longitude" < $2 + $3 / 111.19493 / COS( RADIANS( $2 ) ) AND
40
				ACOS(
41
					SIN( RADIANS( $1 ) ) * SIN( RADIANS( mindsu."latitude" ) ) +
42
					COS( RADIANS( $1 ) ) * COS( RADIANS( mindsu."latitude" ) ) *
43
					COS( RADIANS( mindsu."longitude" ) - RADIANS( $2 ) )
44
				) * 6371
45
			',
46
			'label' => 'Within distance to given coordinates, parameter(<latitude>,<longitude>,<distance in km>)',
47
			'type' => 'boolean',
48
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_BOOL,
49
			'public' => false,
50
		),
51
		'index.supplier:position' => array(
52
			'code' => 'index.supplier:position()',
53
			'internalcode' => ':site AND mindsu."supid" IN ( $2 ) AND mindsu."listtype" = $1 AND mindsu."pos"',
54
			'label' => 'Product position in supplier list, parameter(<list type code>,<supplier IDs>)',
55
			'type' => 'integer',
56
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
57
			'public' => false,
58
		),
59
		'sort:index.supplier:position' => array(
60
			'code' => 'sort:index.supplier:position()',
61
			'internalcode' => 'mindsu."pos"',
62
			'label' => 'Sort product position in supplier list, parameter(<list type code>,<supplier IDs>)',
63
			'type' => 'integer',
64
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
65
			'public' => false,
66
		)
67
	);
68
69
	private $subManagers;
70
71
72
	/**
73
	 * Initializes the manager instance.
74
	 *
75
	 * @param \Aimeos\MShop\ContextIface $context Context object
76
	 */
77
	public function __construct( \Aimeos\MShop\ContextIface $context )
78
	{
79
		parent::__construct( $context );
80
81
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
82
		$level = $context->config()->get( 'mshop/index/manager/sitemode', $level );
83
84
		$expr = $this->siteString( 'mindsu."siteid"', $level );
85
86
		$name = 'index.supplier:position';
87
		$this->searchConfig[$name]['internalcode'] = str_replace( ':site', $expr, $this->searchConfig[$name]['internalcode'] );
88
89
		$name = 'index.supplier:radius';
90
		$this->searchConfig[$name]['internalcode'] = str_replace( ':site', $expr, $this->searchConfig[$name]['internalcode'] );
91
	}
92
93
94
	/**
95
	 * Counts the number products that are available for the values of the given key.
96
	 *
97
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria
98
	 * @param string $key Search key (usually the ID) to aggregate products for
99
	 * @param string|null $value Search key for aggregating the value column
100
	 * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average)
101
	 * @return \Aimeos\Map List of ID values as key and the number of counted products as value
102
	 */
103
	public function aggregate( \Aimeos\Base\Criteria\Iface $search, $key, string $value = null, string $type = null ) : \Aimeos\Map
104
	{
105
		return $this->aggregateBase( $search, $key, 'mshop/index/manager/aggregate', [], $value, $type );
106
	}
107
108
109
	/**
110
	 * Removes old entries from the storage.
111
	 *
112
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
113
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
114
	 */
115
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
116
	{
117
		parent::clear( $siteids );
118
119
		return $this->clearBase( $siteids, 'mshop/index/manager/supplier/delete' );
120
	}
121
122
123
	/**
124
	 * Removes all entries not touched after the given timestamp in the index.
125
	 * This can be a long lasting operation.
126
	 *
127
	 * @param string $timestamp Timestamp in ISO format (YYYY-MM-DD HH:mm:ss)
128
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
129
	 */
130
	public function cleanup( string $timestamp ) : \Aimeos\MShop\Index\Manager\Iface
131
	{
132
		/** mshop/index/manager/supplier/cleanup/mysql
133
		 * Deletes the index supplier records that haven't been touched
134
		 *
135
		 * @see mshop/index/manager/supplier/cleanup/ansi
136
		 */
137
138
		/** mshop/index/manager/supplier/cleanup/ansi
139
		 * Deletes the index supplier records that haven't been touched
140
		 *
141
		 * During the rebuild process of the product index, the entries of all
142
		 * active products will be removed and readded. Thus, no stale data for
143
		 * these products will remain in the database.
144
		 *
145
		 * All products that have been disabled since the last rebuild will be
146
		 * still part of the index. The cleanup statement removes all records
147
		 * that belong to products that haven't been touched during the index
148
		 * rebuild because these are the disabled ones.
149
		 *
150
		 * The SQL statement should conform to the ANSI standard to be
151
		 * compatible with most relational database systems. This also
152
		 * includes using double quotes for table and column names.
153
		 *
154
		 * @param string SQL statement for deleting the outdated index records
155
		 * @since 2018.07
156
		 * @category Developer
157
		 * @see mshop/index/manager/supplier/count/ansi
158
		 * @see mshop/index/manager/supplier/delete/ansi
159
		 * @see mshop/index/manager/supplier/insert/ansi
160
		 * @see mshop/index/manager/supplier/search/ansi
161
		 */
162
		return $this->cleanupBase( $timestamp, 'mshop/index/manager/supplier/cleanup' );
163
	}
164
165
166
	/**
167
	 * Removes multiple items.
168
	 *
169
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
170
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
171
	 */
172
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
173
	{
174
		/** mshop/index/manager/supplier/delete/mysql
175
		 * Deletes the items matched by the given IDs from the database
176
		 *
177
		 * @see mshop/index/manager/supplier/delete/ansi
178
		 */
179
180
		/** mshop/index/manager/supplier/delete/ansi
181
		 * Deletes the items matched by the given IDs from the database
182
		 *
183
		 * Removes the records specified by the given IDs from the index database.
184
		 * The records must be from the site that is configured via the
185
		 * context item.
186
		 *
187
		 * The ":cond" placeholder is replaced by the name of the ID column and
188
		 * the given ID or list of IDs while the site ID is bound to the question
189
		 * mark.
190
		 *
191
		 * The SQL statement should conform to the ANSI standard to be
192
		 * compatible with most relational database systems. This also
193
		 * includes using double quotes for table and column names.
194
		 *
195
		 * @param string SQL statement for deleting index supplier records
196
		 * @since 2018.07
197
		 * @category Developer
198
		 * @see mshop/index/manager/supplier/count/ansi
199
		 * @see mshop/index/manager/supplier/cleanup/ansi
200
		 * @see mshop/index/manager/supplier/insert/ansi
201
		 * @see mshop/index/manager/supplier/search/ansi
202
		 */
203
		return $this->deleteItemsBase( $itemIds, 'mshop/index/manager/supplier/delete' );
204
	}
205
206
207
	/**
208
	 * Returns the available manager types
209
	 *
210
	 * @param bool $withsub Return also the resource type of sub-managers if true
211
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
212
	 */
213
	public function getResourceType( bool $withsub = true ) : array
214
	{
215
		$path = 'mshop/index/manager/supplier/submanagers';
216
217
		return $this->getResourceTypeBase( 'index/supplier', $path, [], $withsub );
218
	}
219
220
221
	/**
222
	 * Returns a list of objects describing the available criterias for searching.
223
	 *
224
	 * @param bool $withsub Return also attributes of sub-managers if true
225
	 * @return array List of items implementing \Aimeos\Base\Criteria\Attribute\Iface
226
	 */
227
	public function getSearchAttributes( bool $withsub = true ) : array
228
	{
229
		$list = parent::getSearchAttributes( $withsub );
230
231
		/** mshop/index/manager/supplier/submanagers
232
		 * List of manager names that can be instantiated by the index attribute manager
233
		 *
234
		 * Managers provide a generic interface to the underlying storage.
235
		 * Each manager has or can have sub-managers caring about particular
236
		 * aspects. Each of these sub-managers can be instantiated by its
237
		 * parent manager using the getSubManager() method.
238
		 *
239
		 * The search keys from sub-managers can be normally used in the
240
		 * manager as well. It allows you to search for items of the manager
241
		 * using the search keys of the sub-managers to further limit the
242
		 * retrieved list of items.
243
		 *
244
		 * @param array List of sub-manager names
245
		 * @since 2018.07
246
		 * @category Developer
247
		 */
248
		$path = 'mshop/index/manager/supplier/submanagers';
249
250
		return $list + $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
251
	}
252
253
254
	/**
255
	 * Returns a new manager for product extensions.
256
	 *
257
	 * @param string $manager Name of the sub manager type in lower case
258
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
259
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g stock, tags, locations, etc.
260
	 */
261
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
262
	{
263
		/** mshop/index/manager/supplier/name
264
		 * Class name of the used index supplier manager implementation
265
		 *
266
		 * Each default index supplier manager can be replaced by an alternative imlementation.
267
		 * To use this implementation, you have to set the last part of the class
268
		 * name as configuration value so the manager factory knows which class it
269
		 * has to instantiate.
270
		 *
271
		 * For example, if the name of the default class is
272
		 *
273
		 *  \Aimeos\MShop\Index\Manager\Supplier\Standard
274
		 *
275
		 * and you want to replace it with your own version named
276
		 *
277
		 *  \Aimeos\MShop\Index\Manager\Supplier\Mysupplier
278
		 *
279
		 * then you have to set the this configuration option:
280
		 *
281
		 *  mshop/index/manager/supplier/name = Mysupplier
282
		 *
283
		 * The value is the last part of your own class name and it's case sensitive,
284
		 * so take care that the configuration value is exactly named like the last
285
		 * part of the class name.
286
		 *
287
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
288
		 * characters are possible! You should always start the last part of the class
289
		 * name with an upper case character and continue only with lower case characters
290
		 * or numbers. Avoid chamel case names like "MySupplier"!
291
		 *
292
		 * @param string Last part of the class name
293
		 * @since 2018.07
294
		 * @category Developer
295
		 */
296
297
		/** mshop/index/manager/supplier/decorators/excludes
298
		 * Excludes decorators added by the "common" option from the index supplier manager
299
		 *
300
		 * Decorators extend the functionality of a class by adding new aspects
301
		 * (e.g. log what is currently done), executing the methods of the underlying
302
		 * class only in certain conditions (e.g. only for logged in users) or
303
		 * modify what is returned to the caller.
304
		 *
305
		 * This option allows you to remove a decorator added via
306
		 * "mshop/common/manager/decorators/default" before they are wrapped
307
		 * around the index supplier manager.
308
		 *
309
		 *  mshop/index/manager/supplier/decorators/excludes = array( 'decorator1' )
310
		 *
311
		 * This would remove the decorator named "decorator1" from the list of
312
		 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
313
		 * "mshop/common/manager/decorators/default" for the index supplier manager.
314
		 *
315
		 * @param array List of decorator names
316
		 * @since 2018.07
317
		 * @category Developer
318
		 * @see mshop/common/manager/decorators/default
319
		 * @see mshop/index/manager/supplier/decorators/global
320
		 * @see mshop/index/manager/supplier/decorators/local
321
		 */
322
323
		/** mshop/index/manager/supplier/decorators/global
324
		 * Adds a list of globally available decorators only to the index supplier manager
325
		 *
326
		 * Decorators extend the functionality of a class by adding new aspects
327
		 * (e.g. log what is currently done), executing the methods of the underlying
328
		 * class only in certain conditions (e.g. only for logged in users) or
329
		 * modify what is returned to the caller.
330
		 *
331
		 * This option allows you to wrap global decorators
332
		 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the index supplier
333
		 * manager.
334
		 *
335
		 *  mshop/index/manager/supplier/decorators/global = array( 'decorator1' )
336
		 *
337
		 * This would add the decorator named "decorator1" defined by
338
		 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the index
339
		 * supplier manager.
340
		 *
341
		 * @param array List of decorator names
342
		 * @since 2018.07
343
		 * @category Developer
344
		 * @see mshop/common/manager/decorators/default
345
		 * @see mshop/index/manager/supplier/decorators/excludes
346
		 * @see mshop/index/manager/supplier/decorators/local
347
		 */
348
349
		/** mshop/index/manager/supplier/decorators/local
350
		 * Adds a list of local decorators only to the index supplier manager
351
		 *
352
		 * Decorators extend the functionality of a class by adding new aspects
353
		 * (e.g. log what is currently done), executing the methods of the underlying
354
		 * class only in certain conditions (e.g. only for logged in users) or
355
		 * modify what is returned to the caller.
356
		 *
357
		 * This option allows you to wrap local decorators
358
		 * ("\Aimeos\MShop\Index\Manager\Supplier\Decorator\*") around the index
359
		 * supplier manager.
360
		 *
361
		 *  mshop/index/manager/supplier/decorators/local = array( 'decorator2' )
362
		 *
363
		 * This would add the decorator named "decorator2" defined by
364
		 * "\Aimeos\MShop\Index\Manager\Supplier\Decorator\Decorator2" only to the
365
		 * index supplier manager.
366
		 *
367
		 * @param array List of decorator names
368
		 * @since 2018.07
369
		 * @category Developer
370
		 * @see mshop/common/manager/decorators/default
371
		 * @see mshop/index/manager/supplier/decorators/excludes
372
		 * @see mshop/index/manager/supplier/decorators/global
373
		 */
374
375
		return $this->getSubManagerBase( 'index', 'supplier/' . $manager, $name );
376
	}
377
378
379
	/**
380
	 * Optimizes the index if necessary.
381
	 * Execution of this operation can take a very long time and shouldn't be
382
	 * called through a web server enviroment.
383
	 *
384
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
385
	 */
386
	public function optimize() : \Aimeos\MShop\Index\Manager\Iface
387
	{
388
		/** mshop/index/manager/supplier/optimize/mysql
389
		 * Optimizes the stored supplier data for retrieving the records faster
390
		 *
391
		 * @see mshop/index/manager/supplier/optimize/ansi
392
		 */
393
394
		/** mshop/index/manager/supplier/optimize/ansi
395
		 * Optimizes the stored supplier data for retrieving the records faster
396
		 *
397
		 * The SQL statement should reorganize the data in the DBMS storage to
398
		 * optimize access to the records of the table or tables. Some DBMS
399
		 * offer specialized statements to optimize indexes and records. This
400
		 * statement doesn't return any records.
401
		 *
402
		 * The SQL statement should conform to the ANSI standard to be
403
		 * compatible with most relational database systems. This also
404
		 * includes using double quotes for table and column names.
405
		 *
406
		 * @param string SQL statement for optimizing the stored supplier data
407
		 * @since 2018.07
408
		 * @category Developer
409
		 * @see mshop/index/manager/supplier/count/ansi
410
		 * @see mshop/index/manager/supplier/search/ansi
411
		 * @see mshop/index/manager/supplier/aggregate/ansi
412
		 */
413
		return $this->optimizeBase( 'mshop/index/manager/supplier/optimize' );
414
	}
415
416
417
	/**
418
	 * Rebuilds the index supplier for searching products or specified list of products.
419
	 * This can be a long lasting operation.
420
	 *
421
	 * @param \Aimeos\MShop\Product\Item\Iface[] $items Associative list of product IDs as keys and items as values
422
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
423
	 */
424
	public function rebuild( iterable $items = [] ) : \Aimeos\MShop\Index\Manager\Iface
425
	{
426
		if( ( $items = map( $items ) )->isEmpty() ) { return $this; }
427
428
		$items->implements( \Aimeos\MShop\Product\Item\Iface::class, true );
429
430
		$date = date( 'Y-m-d H:i:s' );
431
		$context = $this->context();
432
		$siteid = $context->locale()->getSiteId();
433
		$conn = $context->db( $this->getResourceName() );
434
435
			/** mshop/index/manager/supplier/insert/mysql
436
			 * Inserts a new supplier record into the product index database
437
			 *
438
			 * @see mshop/index/manager/supplier/insert/ansi
439
			 */
440
441
			/** mshop/index/manager/supplier/insert/ansi
442
			 * Inserts a new supplier record into the product index database
443
			 *
444
			 * During the product index rebuild, categories related to a
445
			 * product will be stored in the index for this product. All
446
			 * records are deleted before the new ones are inserted.
447
			 *
448
			 * The SQL statement must be a string suitable for being used as
449
			 * prepared statement. It must include question marks for binding
450
			 * the values from the order item to the statement before they are
451
			 * sent to the database server. The number of question marks must
452
			 * be the same as the number of columns listed in the INSERT
453
			 * statement. The order of the columns must correspond to the
454
			 * order in the rebuild() method, so the correct values are
455
			 * bound to the columns.
456
			 *
457
			 * The SQL statement should conform to the ANSI standard to be
458
			 * compatible with most relational database systems. This also
459
			 * includes using double quotes for table and column names.
460
			 *
461
			 * @param string SQL statement for inserting records
462
			 * @since 2018.07
463
			 * @category Developer
464
			 * @see mshop/index/manager/supplier/cleanup/ansi
465
			 * @see mshop/index/manager/supplier/delete/ansi
466
			 * @see mshop/index/manager/supplier/search/ansi
467
			 * @see mshop/index/manager/supplier/count/ansi
468
			 */
469
			$stmt = $this->getCachedStatement( $conn, 'mshop/index/manager/supplier/insert' );
470
471
			foreach( $items as $id => $item )
472
			{
473
				foreach( $item->getListItems( 'supplier' ) as $listItem )
474
				{
475
					if( ( $supplier = $listItem->getRefItem() ) === null ) {
476
						continue;
477
					}
478
479
					$pairs = $supplier->getAddressItems()->map( function( $addr ) {
480
						return $addr->getLatitude() !== null && $addr->getLongitude() !== null
481
							? ['lat' => $addr->getLatitude(), 'lon' => $addr->getLongitude()]
482
							: null;
483
					} )->filter();
484
485
					if( $pairs->isEmpty() ) {
486
						$pairs = [['lat' => null, 'lon' => null]];
487
					}
488
489
					foreach( $pairs as $pair )
490
					{
491
						$stmt->bind( 1, $listItem->getParentId(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
492
						$stmt->bind( 2, $listItem->getRefId(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
493
						$stmt->bind( 3, $listItem->getType() );
494
						$stmt->bind( 4, $listItem->getPosition(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
495
						$stmt->bind( 5, $pair['lat'] ?? null, \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT );
496
						$stmt->bind( 6, $pair['lon'] ?? null, \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT );
497
						$stmt->bind( 7, $date ); //mtime
498
						$stmt->bind( 8, $siteid );
499
500
						try {
501
							$stmt->execute()->finish();
502
						} catch( \Aimeos\Base\DB\Exception $e ) { ; } // Ignore duplicates
503
					}
504
				}
505
			}
506
507
		foreach( $this->getSubManagers() as $submanager ) {
508
			$submanager->rebuild( $items );
509
		}
510
511
		return $this;
512
	}
513
514
515
	/**
516
	 * Removes the products from the product index.
517
	 *
518
	 * @param array|string $ids Product ID or list of IDs
519
	 * @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls
520
	 */
521
	public function remove( $ids ) : \Aimeos\MShop\Index\Manager\Iface
522
	{
523
		parent::remove( $ids )->delete( $ids );
524
		return $this;
525
	}
526
527
528
	/**
529
	 * Searches for items matching the given criteria.
530
	 *
531
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria object
532
	 * @param string[] $ref List of domains to fetch list items and referenced items for
533
	 * @param int|null &$total Number of items that are available in total
534
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Product\Item\Iface with ids as keys
535
	 */
536
	public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
537
	{
538
		/** mshop/index/manager/supplier/search/mysql
539
		 * Retrieves the records matched by the given criteria in the database
540
		 *
541
		 * @see mshop/index/manager/supplier/search/ansi
542
		 */
543
544
		/** mshop/index/manager/supplier/search/ansi
545
		 * Retrieves the records matched by the given criteria in the database
546
		 *
547
		 * Fetches the records matched by the given criteria from the product index
548
		 * database. The records must be from one of the sites that are
549
		 * configured via the context item. If the current site is part of
550
		 * a tree of sites, the SELECT statement can retrieve all records
551
		 * from the current site and the complete sub-tree of sites.
552
		 *
553
		 * As the records can normally be limited by criteria from sub-managers,
554
		 * their tables must be joined in the SQL context. This is done by
555
		 * using the "internaldeps" property from the definition of the ID
556
		 * column of the sub-managers. These internal dependencies specify
557
		 * the JOIN between the tables and the used columns for joining. The
558
		 * ":joins" placeholder is then replaced by the JOIN strings from
559
		 * the sub-managers.
560
		 *
561
		 * To limit the records matched, conditions can be added to the given
562
		 * criteria object. It can contain comparisons like column names that
563
		 * must match specific values which can be combined by AND, OR or NOT
564
		 * operators. The resulting string of SQL conditions replaces the
565
		 * ":cond" placeholder before the statement is sent to the database
566
		 * server.
567
		 *
568
		 * If the records that are retrieved should be ordered by one or more
569
		 * columns, the generated string of column / sort direction pairs
570
		 * replaces the ":order" placeholder. In case no ordering is required,
571
		 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
572
		 * markers is removed to speed up retrieving the records. Columns of
573
		 * sub-managers can also be used for ordering the result set but then
574
		 * no index can be used.
575
		 *
576
		 * The number of returned records can be limited and can start at any
577
		 * number between the begining and the end of the result set. For that
578
		 * the ":size" and ":start" placeholders are replaced by the
579
		 * corresponding values from the criteria object. The default values
580
		 * are 0 for the start and 100 for the size value.
581
		 *
582
		 * The SQL statement should conform to the ANSI standard to be
583
		 * compatible with most relational database systems. This also
584
		 * includes using double quotes for table and column names.
585
		 *
586
		 * @param string SQL statement for searching items
587
		 * @since 2018.07
588
		 * @category Developer
589
		 * @see mshop/index/manager/supplier/count/ansi
590
		 * @see mshop/index/manager/supplier/optimize/ansi
591
		 * @see mshop/index/manager/supplier/aggregate/ansi
592
		 */
593
		$cfgPathSearch = 'mshop/index/manager/supplier/search';
594
595
		/** mshop/index/manager/supplier/count/mysql
596
		 * Counts the number of records matched by the given criteria in the database
597
		 *
598
		 * @see mshop/index/manager/supplier/count/ansi
599
		 */
600
601
		/** mshop/index/manager/supplier/count/ansi
602
		 * Counts the number of records matched by the given criteria in the database
603
		 *
604
		 * Counts all records matched by the given criteria from the product index
605
		 * database. The records must be from one of the sites that are
606
		 * configured via the context item. If the current site is part of
607
		 * a tree of sites, the statement can count all records from the
608
		 * current site and the complete sub-tree of sites.
609
		 *
610
		 * As the records can normally be limited by criteria from sub-managers,
611
		 * their tables must be joined in the SQL context. This is done by
612
		 * using the "internaldeps" property from the definition of the ID
613
		 * column of the sub-managers. These internal dependencies specify
614
		 * the JOIN between the tables and the used columns for joining. The
615
		 * ":joins" placeholder is then replaced by the JOIN strings from
616
		 * the sub-managers.
617
		 *
618
		 * To limit the records matched, conditions can be added to the given
619
		 * criteria object. It can contain comparisons like column names that
620
		 * must match specific values which can be combined by AND, OR or NOT
621
		 * operators. The resulting string of SQL conditions replaces the
622
		 * ":cond" placeholder before the statement is sent to the database
623
		 * server.
624
		 *
625
		 * Both, the strings for ":joins" and for ":cond" are the same as for
626
		 * the "search" SQL statement.
627
		 *
628
		 * Contrary to the "search" statement, it doesn't return any records
629
		 * but instead the number of records that have been found. As counting
630
		 * thousands of records can be a long running task, the maximum number
631
		 * of counted records is limited for performance reasons.
632
		 *
633
		 * The SQL statement should conform to the ANSI standard to be
634
		 * compatible with most relational database systems. This also
635
		 * includes using double quotes for table and column names.
636
		 *
637
		 * @param string SQL statement for counting items
638
		 * @since 2018.07
639
		 * @category Developer
640
		 * @see mshop/index/manager/supplier/search/ansi
641
		 * @see mshop/index/manager/supplier/optimize/ansi
642
		 * @see mshop/index/manager/supplier/aggregate/ansi
643
		 */
644
		$cfgPathCount = 'mshop/index/manager/supplier/count';
645
646
		return $this->searchItemsIndexBase( $search, $ref, $total, $cfgPathSearch, $cfgPathCount );
647
	}
648
649
650
	/**
651
	 * Returns the list of sub-managers available for the index supplier manager.
652
	 *
653
	 * @return \Aimeos\MShop\Index\Manager\Iface[] Associative list of the sub-domain as key and the manager object as value
654
	 */
655
	protected function getSubManagers() : array
656
	{
657
		if( $this->subManagers === null )
658
		{
659
			$this->subManagers = [];
660
			$config = $this->context()->config();
661
662
			/** mshop/index/manager/supplier/submanagers
663
			 * A list of sub-manager names used for indexing associated items to categories
664
			 *
665
			 * All items referenced by a product (e.g. texts, prices, media,
666
			 * etc.) are added to the product index via specialized index
667
			 * managers. You can add the name of new sub-managers to add more
668
			 * data to the index or remove existing ones if you don't want to
669
			 * index that data at all.
670
			 *
671
			 * This option configures the sub-managers that cares about
672
			 * indexing data associated to product categories.
673
			 *
674
			 * @param string List of index sub-manager names
675
			 * @since 2018.07
676
			 * @category User
677
			 * @category Developer
678
			 * @see mshop/index/manager/submanagers
679
			 */
680
			foreach( $config->get( 'mshop/index/manager/supplier/submanagers', [] ) as $domain )
681
			{
682
				$name = $config->get( 'mshop/index/manager/supplier/' . $domain . '/name' );
683
				$this->subManagers[$domain] = $this->object()->getSubManager( $domain, $name );
684
			}
685
686
			return $this->subManagers;
687
		}
688
689
		return $this->subManagers;
690
	}
691
}
692