Passed
Push — master ( c46287...9f1c00 )
by Aimeos
05:19
created

Standard::prefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020-2024
6
 * @package MShop
7
 * @subpackage Review
8
 */
9
10
11
namespace Aimeos\MShop\Review\Manager;
12
13
14
/**
15
 * Default review manager implementation
16
 *
17
 * @package MShop
18
 * @subpackage Review
19
 */
20
class Standard
21
	extends \Aimeos\MShop\Common\Manager\Base
22
	implements \Aimeos\MShop\Review\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
23
{
24
	private array $searchConfig = array(
25
		'review.customerid' => array(
26
			'label' => 'Customer ID',
27
			'internalcode' => 'customerid',
28
			'public' => false,
29
		),
30
		'review.orderproductid' => array(
31
			'label' => 'Order product ID',
32
			'internalcode' => 'ordprodid',
33
			'public' => false,
34
		),
35
		'review.domain' => array(
36
			'label' => 'Domain',
37
			'internalcode' => 'domain',
38
		),
39
		'review.refid' => array(
40
			'label' => 'ID from the referenced domain',
41
			'internalcode' => 'refid',
42
		),
43
		'review.name' => array(
44
			'label' => 'Name',
45
			'internalcode' => 'name',
46
		),
47
		'review.comment' => array(
48
			'label' => 'Comment',
49
			'internalcode' => 'comment',
50
		),
51
		'review.response' => array(
52
			'label' => 'Response',
53
			'internalcode' => 'response',
54
		),
55
		'review.rating' => array(
56
			'label' => 'Rating',
57
			'internalcode' => 'rating',
58
			'type' => 'int',
59
		),
60
		'review.status' => array(
61
			'label' => 'Review status',
62
			'internalcode' => 'status',
63
			'type' => 'int',
64
		),
65
	);
66
67
68
	/**
69
	 * Counts the number items that are available for the values of the given key.
70
	 *
71
	 * @param \Aimeos\Base\Criteria\Iface $search Search criteria
72
	 * @param array|string $key Search key or list of keys to aggregate items for
73
	 * @param string|null $value Search key for aggregating the value column
74
	 * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average)
75
	 * @return \Aimeos\Map List of the search keys as key and the number of counted items as value
76
	 */
77
	public function aggregate( \Aimeos\Base\Criteria\Iface $search, $key, string $value = null, string $type = null ) : \Aimeos\Map
78
	{
79
		/** mshop/review/manager/aggregate/mysql
80
		 * Counts the number of records grouped by the values in the key column and matched by the given criteria
81
		 *
82
		 * @see mshop/review/manager/aggregate/ansi
83
		 */
84
85
		/** mshop/review/manager/aggregate/ansi
86
		 * Counts the number of records grouped by the values in the key column and matched by the given criteria
87
		 *
88
		 * Groups all records by the values in the key column and counts their
89
		 * occurence. The matched records can be limited by the given criteria
90
		 * from the review database. The records must be from one of the sites
91
		 * that are configured via the context item. If the current site is part
92
		 * of a tree of sites, the statement can count all records from the
93
		 * current site and the complete sub-tree of sites.
94
		 *
95
		 * As the records can normally be limited by criteria from sub-managers,
96
		 * their tables must be joined in the SQL context. This is done by
97
		 * using the "internaldeps" property from the definition of the ID
98
		 * column of the sub-managers. These internal dependencies specify
99
		 * the JOIN between the tables and the used columns for joining. The
100
		 * ":joins" placeholder is then replaced by the JOIN strings from
101
		 * the sub-managers.
102
		 *
103
		 * To limit the records matched, conditions can be added to the given
104
		 * criteria object. It can contain comparisons like column names that
105
		 * must match specific values which can be combined by AND, OR or NOT
106
		 * operators. The resulting string of SQL conditions replaces the
107
		 * ":cond" placeholder before the statement is sent to the database
108
		 * server.
109
		 *
110
		 * This statement doesn't return any records. Instead, it returns pairs
111
		 * of the different values found in the key column together with the
112
		 * number of records that have been found for that key values.
113
		 *
114
		 * The SQL statement should conform to the ANSI standard to be
115
		 * compatible with most relational database systems. This also
116
		 * includes using double quotes for table and column names.
117
		 *
118
		 * @param string SQL statement for aggregating review items
119
		 * @since 2020.10
120
		 * @see mshop/review/manager/insert/ansi
121
		 * @see mshop/review/manager/update/ansi
122
		 * @see mshop/review/manager/newid/ansi
123
		 * @see mshop/review/manager/delete/ansi
124
		 * @see mshop/review/manager/search/ansi
125
		 * @see mshop/review/manager/count/ansi
126
		 */
127
		$cfgkey = 'mshop/review/manager/aggregate';
128
		$cfgkey .= ( $type === 'rate' ? 'rate' : '' );
129
130
		return $this->aggregateBase( $search, $key, $cfgkey, [], $value, $type );
131
	}
132
133
134
	/**
135
	 * Creates a new empty item instance
136
	 *
137
	 * @param array $values Values the item should be initialized with
138
	 * @return \Aimeos\MShop\Review\Item\Iface New review item object
139
	 */
140
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
141
	{
142
		$values['review.siteid'] = $values['review.siteid'] ?? $this->context()->locale()->getSiteId();
143
		return new \Aimeos\MShop\Review\Item\Standard( 'review.', $values );
144
	}
145
146
147
	/**
148
	 * Creates a filter object.
149
	 *
150
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
151
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
152
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
153
	 */
154
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
155
	{
156
		return $this->filterBase( 'review', $default );
157
	}
158
159
160
	/**
161
	 * Returns the additional column/search definitions
162
	 *
163
	 * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
164
	 */
165
	public function getSaveAttributes() : array
166
	{
167
		return $this->createAttributes( $this->searchConfig );
168
	}
169
170
171
	/**
172
	 * Returns the prefix for the item properties and search keys.
173
	 *
174
	 * @return string Prefix for the item properties and search keys
175
	 */
176
	protected function prefix() : string
177
	{
178
		return 'review.';
179
	}
180
181
182
	/** mshop/review/manager/name
183
	 * Class name of the used review manager implementation
184
	 *
185
	 * Each default manager can be replace by an alternative imlementation.
186
	 * To use this implementation, you have to set the last part of the class
187
	 * name as configuration value so the manager factory knows which class it
188
	 * has to instantiate.
189
	 *
190
	 * For example, if the name of the default class is
191
	 *
192
	 *  \Aimeos\MShop\Review\Manager\Standard
193
	 *
194
	 * and you want to replace it with your own version named
195
	 *
196
	 *  \Aimeos\MShop\Review\Manager\Mymanager
197
	 *
198
	 * then you have to set the this configuration option:
199
	 *
200
	 *  mshop/review/manager/name = Mymanager
201
	 *
202
	 * The value is the last part of your own class name and it's case sensitive,
203
	 * so take care that the configuration value is exactly named like the last
204
	 * part of the class name.
205
	 *
206
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
207
	 * characters are possible! You should always start the last part of the class
208
	 * name with an upper case character and continue only with lower case characters
209
	 * or numbers. Avoid chamel case names like "MyManager"!
210
	 *
211
	 * @param string Last part of the class name
212
	 * @since 2020.10
213
	 */
214
215
	/** mshop/review/manager/decorators/excludes
216
	 * Excludes decorators added by the "common" option from the review manager
217
	 *
218
	 * Decorators extend the functionality of a class by adding new aspects
219
	 * (e.g. log what is currently done), executing the methods of the underlying
220
	 * class only in certain conditions (e.g. only for logged in users) or
221
	 * modify what is returned to the caller.
222
	 *
223
	 * This option allows you to remove a decorator added via
224
	 * "mshop/common/manager/decorators/default" before they are wrapped
225
	 * around the review manager.
226
	 *
227
	 *  mshop/review/manager/decorators/excludes = array( 'decorator1' )
228
	 *
229
	 * This would remove the decorator named "decorator1" from the list of
230
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
231
	 * "mshop/common/manager/decorators/default" for the review manager.
232
	 *
233
	 * @param array List of decorator names
234
	 * @since 2020.10
235
	 * @see mshop/common/manager/decorators/default
236
	 * @see mshop/review/manager/decorators/global
237
	 * @see mshop/review/manager/decorators/local
238
	 */
239
240
	/** mshop/review/manager/decorators/global
241
	 * Adds a list of globally available decorators only to the review manager
242
	 *
243
	 * Decorators extend the functionality of a class by adding new aspects
244
	 * (e.g. log what is currently done), executing the methods of the underlying
245
	 * class only in certain conditions (e.g. only for logged in users) or
246
	 * modify what is returned to the caller.
247
	 *
248
	 * This option allows you to wrap global decorators
249
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the review manager.
250
	 *
251
	 *  mshop/review/manager/decorators/global = array( 'decorator1' )
252
	 *
253
	 * This would add the decorator named "decorator1" defined by
254
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the review
255
	 * manager.
256
	 *
257
	 * @param array List of decorator names
258
	 * @since 2020.10
259
	 * @see mshop/common/manager/decorators/default
260
	 * @see mshop/review/manager/decorators/excludes
261
	 * @see mshop/review/manager/decorators/local
262
	 */
263
264
	/** mshop/review/manager/decorators/local
265
	 * Adds a list of local decorators only to the review manager
266
	 *
267
	 * Decorators extend the functionality of a class by adding new aspects
268
	 * (e.g. log what is currently done), executing the methods of the underlying
269
	 * class only in certain conditions (e.g. only for logged in users) or
270
	 * modify what is returned to the caller.
271
	 *
272
	 * This option allows you to wrap local decorators
273
	 * ("\Aimeos\MShop\Review\Manager\Decorator\*") around the review manager.
274
	 *
275
	 *  mshop/review/manager/decorators/local = array( 'decorator2' )
276
	 *
277
	 * This would add the decorator named "decorator2" defined by
278
	 * "\Aimeos\MShop\Review\Manager\Decorator\Decorator2" only to the review
279
	 * manager.
280
	 *
281
	 * @param array List of decorator names
282
	 * @since 2020.10
283
	 * @see mshop/common/manager/decorators/default
284
	 * @see mshop/review/manager/decorators/excludes
285
	 * @see mshop/review/manager/decorators/global
286
	 */
287
288
	/** mshop/review/manager/resource
289
	 * Name of the database connection resource to use
290
	 *
291
	 * You can configure a different database connection for each data domain
292
	 * and if no such connection name exists, the "db" connection will be used.
293
	 * It's also possible to use the same database connection for different
294
	 * data domains by configuring the same connection name using this setting.
295
	 *
296
	 * @param string Database connection name
297
	 * @since 2023.04
298
	 */
299
300
301
	/** mshop/review/manager/delete/mysql
302
	 * Deletes the items matched by the given IDs from the database
303
	 *
304
	 * @see mshop/review/manager/delete/ansi
305
	 */
306
307
	/** mshop/review/manager/delete/ansi
308
	 * Deletes the items matched by the given IDs from the database
309
	 *
310
	 * Removes the records specified by the given IDs from the review database.
311
	 * The records must be from the site that is configured via the
312
	 * context item.
313
	 *
314
	 * The ":cond" placeholder is replaced by the name of the ID column and
315
	 * the given ID or list of IDs while the site ID is bound to the question
316
	 * mark.
317
	 *
318
	 * The SQL statement should conform to the ANSI standard to be
319
	 * compatible with most relational database systems. This also
320
	 * includes using double quotes for table and column names.
321
	 *
322
	 * @param string SQL statement for deleting items
323
	 * @since 2020.10
324
	 * @see mshop/review/manager/insert/ansi
325
	 * @see mshop/review/manager/update/ansi
326
	 * @see mshop/review/manager/newid/ansi
327
	 * @see mshop/review/manager/search/ansi
328
	 * @see mshop/review/manager/count/ansi
329
	 */
330
331
	 /** mshop/review/manager/submanagers
332
	 * List of manager names that can be instantiated by the review manager
333
	 *
334
	 * Managers provide a generic interface to the underlying storage.
335
	 * Each manager has or can have sub-managers caring about particular
336
	 * aspects. Each of these sub-managers can be instantiated by its
337
	 * parent manager using the getSubManager() method.
338
	 *
339
	 * The search keys from sub-managers can be normally used in the
340
	 * manager as well. It allows you to search for items of the manager
341
	 * using the search keys of the sub-managers to further limit the
342
	 * retrieved list of items.
343
	 *
344
	 * @param array List of sub-manager names
345
	 * @since 2020.10
346
	 */
347
348
	 /** mshop/review/manager/insert/mysql
349
	 * Inserts a new review record into the database table
350
	 *
351
	 * @see mshop/review/manager/insert/ansi
352
	 */
353
354
	/** mshop/review/manager/insert/ansi
355
	 * Inserts a new review record into the database table
356
	 *
357
	 * Items with no ID yet (i.e. the ID is NULL) will be created in
358
	 * the database and the newly created ID retrieved afterwards
359
	 * using the "newid" SQL statement.
360
	 *
361
	 * The SQL statement must be a string suitable for being used as
362
	 * prepared statement. It must include question marks for binding
363
	 * the values from the review item to the statement before they are
364
	 * sent to the database server. The number of question marks must
365
	 * be the same as the number of columns listed in the INSERT
366
	 * statement. The catalog of the columns must correspond to the
367
	 * catalog in the save() method, so the correct values are
368
	 * bound to the columns.
369
	 *
370
	 * The SQL statement should conform to the ANSI standard to be
371
	 * compatible with most relational database systems. This also
372
	 * includes using double quotes for table and column names.
373
	 *
374
	 * @param string SQL statement for inserting records
375
	 * @since 2020.10
376
	 * @see mshop/review/manager/update/ansi
377
	 * @see mshop/review/manager/newid/ansi
378
	 * @see mshop/review/manager/delete/ansi
379
	 * @see mshop/review/manager/search/ansi
380
	 * @see mshop/review/manager/count/ansi
381
	 */
382
383
	 /** mshop/review/manager/update/mysql
384
	 * Updates an existing review record in the database
385
	 *
386
	 * @see mshop/review/manager/update/ansi
387
	 */
388
389
	/** mshop/review/manager/update/ansi
390
	 * Updates an existing review record in the database
391
	 *
392
	 * Items which already have an ID (i.e. the ID is not NULL) will
393
	 * be updated in the database.
394
	 *
395
	 * The SQL statement must be a string suitable for being used as
396
	 * prepared statement. It must include question marks for binding
397
	 * the values from the review item to the statement before they are
398
	 * sent to the database server. The catalog of the columns must
399
	 * correspond to the catalog in the save() method, so the
400
	 * correct values are bound to the columns.
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 updating records
407
	 * @since 2020.10
408
	 * @see mshop/review/manager/insert/ansi
409
	 * @see mshop/review/manager/newid/ansi
410
	 * @see mshop/review/manager/delete/ansi
411
	 * @see mshop/review/manager/search/ansi
412
	 * @see mshop/review/manager/count/ansi
413
	 */
414
415
	/** mshop/review/manager/newid/mysql
416
	 * Retrieves the ID generated by the database when inserting a new record
417
	 *
418
	 * @see mshop/review/manager/newid/ansi
419
	 */
420
421
	/** mshop/review/manager/newid/ansi
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_mrul_id')
433
	 * For SQL Server:
434
	 *  SELECT SCOPE_IDENTITY()
435
	 * For Oracle:
436
	 *  SELECT "seq_mrul_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 2020.10
444
	 * @see mshop/review/manager/insert/ansi
445
	 * @see mshop/review/manager/update/ansi
446
	 * @see mshop/review/manager/delete/ansi
447
	 * @see mshop/review/manager/search/ansi
448
	 * @see mshop/review/manager/count/ansi
449
	 */
450
451
	/** mshop/review/manager/sitemode
452
	 * Mode how items from levels below or above in the site tree are handled
453
	 *
454
	 * By default, only items from the current site are fetched from the
455
	 * storage. If the ai-sites extension is installed, you can create a
456
	 * tree of sites. Then, this setting allows you to define for the
457
	 * whole review domain if items from parent sites are inherited,
458
	 * sites from child sites are aggregated or both.
459
	 *
460
	 * Available constants for the site mode are:
461
	 * * 0 = only items from the current site
462
	 * * 1 = inherit items from parent sites
463
	 * * 2 = aggregate items from child sites
464
	 * * 3 = inherit and aggregate items at the same time
465
	 *
466
	 * You also need to set the mode in the locale manager
467
	 * (mshop/locale/manager/sitelevel) to one of the constants.
468
	 * If you set it to the same value, it will work as described but you
469
	 * can also use different modes. For example, if inheritance and
470
	 * aggregation is configured the locale manager but only inheritance
471
	 * in the domain manager because aggregating items makes no sense in
472
	 * this domain, then items wil be only inherited. Thus, you have full
473
	 * control over inheritance and aggregation in each domain.
474
	 *
475
	 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
476
	 * @since 2018.01
477
	 * @see mshop/locale/manager/sitelevel
478
	 */
479
480
	/** mshop/review/manager/search/mysql
481
	 * Retrieves the records matched by the given criteria in the database
482
	 *
483
	 * @see mshop/review/manager/search/ansi
484
	 */
485
486
	/** mshop/review/manager/search/ansi
487
	 * Retrieves the records matched by the given criteria in the database
488
	 *
489
	 * Fetches the records matched by the given criteria from the review
490
	 * database. The records must be from one of the sites that are
491
	 * configured via the context item. If the current site is part of
492
	 * a tree of sites, the SELECT statement can retrieve all records
493
	 * from the current site and the complete sub-tree of sites.
494
	 *
495
	 * As the records can normally be limited by criteria from sub-managers,
496
	 * their tables must be joined in the SQL context. This is done by
497
	 * using the "internaldeps" property from the definition of the ID
498
	 * column of the sub-managers. These internal dependencies specify
499
	 * the JOIN between the tables and the used columns for joining. The
500
	 * ":joins" placeholder is then replaced by the JOIN strings from
501
	 * the sub-managers.
502
	 *
503
	 * To limit the records matched, conditions can be added to the given
504
	 * criteria object. It can contain comparisons like column names that
505
	 * must match specific values which can be combined by AND, OR or NOT
506
	 * operators. The resulting string of SQL conditions replaces the
507
	 * ":cond" placeholder before the statement is sent to the database
508
	 * server.
509
	 *
510
	 * If the records that are retrieved should be cataloged by one or more
511
	 * columns, the generated string of column / sort direction pairs
512
	 * replaces the ":catalog" placeholder. In case no cataloging is required,
513
	 * the complete ORDER BY part including the "\/*-catalogby*\/...\/*catalogby-*\/"
514
	 * markers is removed to speed up retrieving the records. Columns of
515
	 * sub-managers can also be used for cataloging the result set but then
516
	 * no index can be used.
517
	 *
518
	 * The number of returned records can be limited and can start at any
519
	 * number between the begining and the end of the result set. For that
520
	 * the ":size" and ":start" placeholders are replaced by the
521
	 * corresponding values from the criteria object. The default values
522
	 * are 0 for the start and 100 for the size value.
523
	 *
524
	 * The SQL statement should conform to the ANSI standard to be
525
	 * compatible with most relational database systems. This also
526
	 * includes using double quotes for table and column names.
527
	 *
528
	 * @param string SQL statement for searching items
529
	 * @since 2020.10
530
	 * @see mshop/review/manager/insert/ansi
531
	 * @see mshop/review/manager/update/ansi
532
	 * @see mshop/review/manager/newid/ansi
533
	 * @see mshop/review/manager/delete/ansi
534
	 * @see mshop/review/manager/count/ansi
535
	 */
536
537
	/** mshop/review/manager/count/mysql
538
	 * Counts the number of records matched by the given criteria in the database
539
	 *
540
	 * @see mshop/review/manager/count/ansi
541
	 */
542
543
	/** mshop/review/manager/count/ansi
544
	 * Counts the number of records matched by the given criteria in the database
545
	 *
546
	 * Counts all records matched by the given criteria from the review
547
	 * database. The records must be from one of the sites that are
548
	 * configured via the context item. If the current site is part of
549
	 * a tree of sites, the statement can count all records from the
550
	 * current site and the complete sub-tree of sites.
551
	 *
552
	 * As the records can normally be limited by criteria from sub-managers,
553
	 * their tables must be joined in the SQL context. This is done by
554
	 * using the "internaldeps" property from the definition of the ID
555
	 * column of the sub-managers. These internal dependencies specify
556
	 * the JOIN between the tables and the used columns for joining. The
557
	 * ":joins" placeholder is then replaced by the JOIN strings from
558
	 * the sub-managers.
559
	 *
560
	 * To limit the records matched, conditions can be added to the given
561
	 * criteria object. It can contain comparisons like column names that
562
	 * must match specific values which can be combined by AND, OR or NOT
563
	 * operators. The resulting string of SQL conditions replaces the
564
	 * ":cond" placeholder before the statement is sent to the database
565
	 * server.
566
	 *
567
	 * Both, the strings for ":joins" and for ":cond" are the same as for
568
	 * the "search" SQL statement.
569
	 *
570
	 * Contrary to the "search" statement, it doesn't return any records
571
	 * but instead the number of records that have been found. As counting
572
	 * thousands of records can be a long running task, the maximum number
573
	 * of counted records is limited for performance reasons.
574
	 *
575
	 * The SQL statement should conform to the ANSI standard to be
576
	 * compatible with most relational database systems. This also
577
	 * includes using double quotes for table and column names.
578
	 *
579
	 * @param string SQL statement for counting items
580
	 * @since 2020.10
581
	 * @see mshop/review/manager/insert/ansi
582
	 * @see mshop/review/manager/update/ansi
583
	 * @see mshop/review/manager/newid/ansi
584
	 * @see mshop/review/manager/delete/ansi
585
	 * @see mshop/review/manager/search/ansi
586
	 */
587
}
588