Passed
Push — master ( b98f34...b02400 )
by Aimeos
05:49 queued 01:38
created

Standard::searchRefs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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