1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Locale |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Locale\Manager\Site; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation for managing sites. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Locale |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
23
|
|
|
implements \Aimeos\MShop\Locale\Manager\Site\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
24
|
|
|
{ |
25
|
|
|
private $cache = []; |
26
|
|
|
|
27
|
|
|
private $searchConfig = array( |
28
|
|
|
'locale.site.id' => array( |
29
|
|
|
'code' => 'locale.site.id', |
30
|
|
|
'internalcode' => 'mlocsi."id"', |
31
|
|
|
'internaldeps' => ['LEFT JOIN "mshop_locale_site" AS mlocsi ON (mloc."siteid" = mlocsi."siteid")'], |
32
|
|
|
'label' => 'Site ID', |
33
|
|
|
'type' => 'string', |
34
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
35
|
|
|
'public' => false, |
36
|
|
|
), |
37
|
|
|
'locale.site.siteid' => array( |
38
|
|
|
'code' => 'locale.site.siteid', |
39
|
|
|
'internalcode' => 'mlocsi."siteid"', |
40
|
|
|
'label' => 'Unique site ID', |
41
|
|
|
'type' => 'string', |
42
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
43
|
|
|
'public' => false, |
44
|
|
|
), |
45
|
|
|
'locale.site.label' => array( |
46
|
|
|
'code' => 'locale.site.label', |
47
|
|
|
'internalcode' => 'mlocsi."label"', |
48
|
|
|
'label' => 'Site label', |
49
|
|
|
'type' => 'string', |
50
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
51
|
|
|
), |
52
|
|
|
'locale.site.code' => array( |
53
|
|
|
'code' => 'locale.site.code', |
54
|
|
|
'internalcode' => 'mlocsi."code"', |
55
|
|
|
'label' => 'Site code', |
56
|
|
|
'type' => 'string', |
57
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
58
|
|
|
), |
59
|
|
|
'locale.site.status' => array( |
60
|
|
|
'code' => 'locale.site.status', |
61
|
|
|
'internalcode' => 'mlocsi."status"', |
62
|
|
|
'label' => 'Site status', |
63
|
|
|
'type' => 'integer', |
64
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
65
|
|
|
), |
66
|
|
|
'locale.site.level' => array( |
67
|
|
|
'code' => 'locale.site.level', |
68
|
|
|
'internalcode' => 'mlocsi."level"', |
69
|
|
|
'label' => 'Site tree level', |
70
|
|
|
'type' => 'integer', |
71
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
72
|
|
|
'public' => false, |
73
|
|
|
), |
74
|
|
|
'locale.site.config' => array( |
75
|
|
|
'code' => 'locale.site.config', |
76
|
|
|
'internalcode' => 'mlocsi."config"', |
77
|
|
|
'label' => 'Site config', |
78
|
|
|
'type' => 'string', |
79
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
80
|
|
|
'public' => false, |
81
|
|
|
), |
82
|
|
|
'locale.site.icon' => array( |
83
|
|
|
'code' => 'locale.site.icon', |
84
|
|
|
'internalcode' => 'mlocsi."icon"', |
85
|
|
|
'label' => 'Site icon', |
86
|
|
|
'type' => 'string', |
87
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
88
|
|
|
'public' => false, |
89
|
|
|
), |
90
|
|
|
'locale.site.logo' => array( |
91
|
|
|
'code' => 'locale.site.logo', |
92
|
|
|
'internalcode' => 'mlocsi."logo"', |
93
|
|
|
'label' => 'Site logo', |
94
|
|
|
'type' => 'string', |
95
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
96
|
|
|
'public' => false, |
97
|
|
|
), |
98
|
|
|
'locale.site.rating' => array( |
99
|
|
|
'code' => 'locale.site.rating', |
100
|
|
|
'internalcode' => 'mlocsi."rating"', |
101
|
|
|
'label' => 'Rating value', |
102
|
|
|
'type' => 'decimal', |
103
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
104
|
|
|
'public' => false, |
105
|
|
|
), |
106
|
|
|
'locale.site.ratings' => array( |
107
|
|
|
'code' => 'locale.site.ratings', |
108
|
|
|
'internalcode' => 'mlocsi."ratings"', |
109
|
|
|
'label' => 'Number of ratings', |
110
|
|
|
'type' => 'integer', |
111
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT, |
112
|
|
|
'public' => false, |
113
|
|
|
), |
114
|
|
|
'locale.site.refid' => array( |
115
|
|
|
'code' => 'locale.site.refid', |
116
|
|
|
'internalcode' => 'mlocsi."refid"', |
117
|
|
|
'label' => 'Site-related supplier ID', |
118
|
|
|
'type' => 'string', |
119
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
120
|
|
|
'public' => false, |
121
|
|
|
), |
122
|
|
|
'locale.site.theme' => array( |
123
|
|
|
'code' => 'locale.site.theme', |
124
|
|
|
'internalcode' => 'mlocsi."theme"', |
125
|
|
|
'label' => 'Site theme', |
126
|
|
|
'type' => 'string', |
127
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
128
|
|
|
'public' => false, |
129
|
|
|
), |
130
|
|
|
'locale.site.ctime' => array( |
131
|
|
|
'code' => 'locale.site.ctime', |
132
|
|
|
'internalcode' => 'mlocsi."ctime"', |
133
|
|
|
'label' => 'Site create date/time', |
134
|
|
|
'type' => 'datetime', |
135
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
136
|
|
|
'public' => false, |
137
|
|
|
), |
138
|
|
|
'locale.site.mtime' => array( |
139
|
|
|
'code' => 'locale.site.mtime', |
140
|
|
|
'internalcode' => 'mlocsi."mtime"', |
141
|
|
|
'label' => 'Site modify date/time', |
142
|
|
|
'type' => 'datetime', |
143
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
144
|
|
|
'public' => false, |
145
|
|
|
), |
146
|
|
|
'locale.site.editor' => array( |
147
|
|
|
'code' => 'locale.site.editor', |
148
|
|
|
'internalcode' => 'mlocsi."editor"', |
149
|
|
|
'label' => 'Site editor', |
150
|
|
|
'type' => 'string', |
151
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
152
|
|
|
'public' => false, |
153
|
|
|
), |
154
|
|
|
'parentid' => array( |
155
|
|
|
'code' => 'locale.site.parentid', |
156
|
|
|
'internalcode' => 'mlocsi."parentid"', |
157
|
|
|
'label' => 'Parent site ID', |
158
|
|
|
'type' => 'string', |
159
|
|
|
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR, |
160
|
|
|
'public' => false, |
161
|
|
|
), |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Initializes the object. |
167
|
|
|
* |
168
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object |
169
|
|
|
*/ |
170
|
|
|
public function __construct( \Aimeos\MShop\ContextIface $context ) |
171
|
|
|
{ |
172
|
|
|
parent::__construct( $context ); |
173
|
|
|
$this->setResourceName( 'db-locale' ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Removes old entries from the storage. |
179
|
|
|
* |
180
|
|
|
* @param iterable $siteids List of IDs for sites whose entries should be deleted |
181
|
|
|
* @return \Aimeos\MShop\Locale\Manager\Site\Iface Manager object for chaining method calls |
182
|
|
|
*/ |
183
|
|
|
public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface |
184
|
|
|
{ |
185
|
|
|
if( empty( $siteids ) ) { |
186
|
|
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$context = $this->context(); |
190
|
|
|
$config = $context->config(); |
191
|
|
|
|
192
|
|
|
/** mshop/locale/manager/site/cleanup/shop/domains |
193
|
|
|
* List of madmin domains names whose items referring to the same site should be deleted as well |
194
|
|
|
* |
195
|
|
|
* As items for each domain can be stored in a separate database, the |
196
|
|
|
* site manager needs a list of domain names used to connect to the |
197
|
|
|
* correct database and to remove all items that belong the the deleted |
198
|
|
|
* site. |
199
|
|
|
* |
200
|
|
|
* For each domain the cleanup will be done by the corresponding MShop |
201
|
|
|
* manager. To keep records for old sites in the database even if the |
202
|
|
|
* site was already deleted, you can configure a new list with the |
203
|
|
|
* domains removed you would like to keep, e.g. the "order" domain to |
204
|
|
|
* keep all orders ever placed. |
205
|
|
|
* |
206
|
|
|
* @param array List of domain names in lower case |
207
|
|
|
* @since 2014.03 |
208
|
|
|
* @category Developer |
209
|
|
|
* @see mshop/locale/manager/site/cleanup/admin/domains |
210
|
|
|
*/ |
211
|
|
|
$path = 'mshop/locale/manager/site/cleanup/shop/domains'; |
212
|
|
|
|
213
|
|
|
foreach( $config->get( $path, [] ) as $domain ) { |
214
|
|
|
\Aimeos\MShop::create( $context, $domain )->clear( $siteids ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** mshop/locale/manager/site/cleanup/admin/domains |
218
|
|
|
* List of mshop domains names whose items referring to the same site should be deleted as well |
219
|
|
|
* |
220
|
|
|
* As items for each domain can be stored in a separate database, the |
221
|
|
|
* site manager needs a list of domain names used to connect to the |
222
|
|
|
* correct database and to remove all items that belong the the deleted |
223
|
|
|
* site. |
224
|
|
|
* |
225
|
|
|
* For each domain the cleanup will be done by the corresponding MAdmin |
226
|
|
|
* manager. To keep records for old sites in the database even if the |
227
|
|
|
* site was already deleted, you can configure a new list with the |
228
|
|
|
* domains removed you would like to keep, e.g. the "log" domain to |
229
|
|
|
* keep all log entries ever written. |
230
|
|
|
* |
231
|
|
|
* @param array List of domain names in lower case |
232
|
|
|
* @since 2014.03 |
233
|
|
|
* @category Developer |
234
|
|
|
* @see mshop/locale/manager/site/cleanup/shop/domains |
235
|
|
|
*/ |
236
|
|
|
$path = 'mshop/locale/manager/site/cleanup/admin/domains'; |
237
|
|
|
|
238
|
|
|
foreach( $config->get( $path, [] ) as $domain ) { |
239
|
|
|
\Aimeos\MAdmin::create( $context, $domain )->clear( $siteids ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Creates a new empty item instance |
248
|
|
|
* |
249
|
|
|
* @param array $values Values the item should be initialized with |
250
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface New locale site item object |
251
|
|
|
*/ |
252
|
|
|
public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface |
253
|
|
|
{ |
254
|
|
|
return $this->createItemBase( $values ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Adds a new site to the storage or updates an existing one. |
260
|
|
|
* |
261
|
|
|
* @param \Aimeos\MShop\Locale\Item\Site\Iface $item New site item for saving to the storage |
262
|
|
|
* @param bool $fetch True if the new ID should be returned in the item |
263
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface $item Updated item including the generated ID |
264
|
|
|
*/ |
265
|
|
|
public function saveItem( \Aimeos\MShop\Locale\Item\Site\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Locale\Item\Site\Iface |
266
|
|
|
{ |
267
|
|
|
if( $item->getId() === null ) |
268
|
|
|
{ |
269
|
|
|
$msg = $this->context()->translate( 'mshop', 'Newly created item can not be saved using method "save()", use "insert()" instead' ); |
270
|
|
|
throw new \Aimeos\MShop\Locale\Exception( $msg ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
if( !$item->isModified() ) { |
274
|
|
|
return $item; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$context = $this->context(); |
278
|
|
|
$conn = $context->db( $this->getResourceName() ); |
279
|
|
|
|
280
|
|
|
$id = $item->getId(); |
281
|
|
|
$columns = $this->object()->getSaveAttributes(); |
282
|
|
|
|
283
|
|
|
/** mshop/locale/manager/site/update/mysql |
284
|
|
|
* Updates an existing site record in the database |
285
|
|
|
* |
286
|
|
|
* @see mshop/locale/manager/site/update/ansi |
287
|
|
|
*/ |
288
|
|
|
|
289
|
|
|
/** mshop/locale/manager/site/update/ansi |
290
|
|
|
* Updates an existing site record in the database |
291
|
|
|
* |
292
|
|
|
* The SQL statement must be a string suitable for being used as |
293
|
|
|
* prepared statement. It must include question marks for binding |
294
|
|
|
* the values from the site item to the statement before they are |
295
|
|
|
* sent to the database server. The order of the columns must |
296
|
|
|
* correspond to the order in the save() method, so the |
297
|
|
|
* correct values are bound to the columns. |
298
|
|
|
* |
299
|
|
|
* The SQL statement should conform to the ANSI standard to be |
300
|
|
|
* compatible with most relational database systems. This also |
301
|
|
|
* includes using double quotes for table and column names. |
302
|
|
|
* |
303
|
|
|
* @param string SQL statement for updating records |
304
|
|
|
* @since 2014.03 |
305
|
|
|
* @category Developer |
306
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
307
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
308
|
|
|
* @see mshop/locale/manager/site/search/ansi |
309
|
|
|
* @see mshop/locale/manager/site/count/ansi |
310
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
311
|
|
|
*/ |
312
|
|
|
$path = 'mshop/locale/manager/site/update'; |
313
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false ); |
|
|
|
|
314
|
|
|
|
315
|
|
|
$idx = 1; |
316
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
317
|
|
|
|
318
|
|
|
foreach( $columns as $name => $entry ) { |
319
|
|
|
$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() ); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$stmt->bind( $idx++, $item->getSiteId() ); |
323
|
|
|
$stmt->bind( $idx++, $item->getCode() ); |
324
|
|
|
$stmt->bind( $idx++, $item->getLabel() ); |
325
|
|
|
$stmt->bind( $idx++, json_encode( $item->getConfig(), JSON_FORCE_OBJECT ) ); |
326
|
|
|
$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
327
|
|
|
$stmt->bind( $idx++, $item->getIcon() ); |
328
|
|
|
$stmt->bind( $idx++, json_encode( $item->getLogos(), JSON_FORCE_OBJECT ) ); |
329
|
|
|
$stmt->bind( $idx++, $item->getRefId() ); |
330
|
|
|
$stmt->bind( $idx++, $item->getTheme() ); |
331
|
|
|
$stmt->bind( $idx++, $context->editor() ); |
332
|
|
|
$stmt->bind( $idx++, date( 'Y-m-d H:i:s' ) ); // mtime |
333
|
|
|
$stmt->bind( $idx++, $id, \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
334
|
|
|
|
335
|
|
|
$stmt->execute()->finish(); |
336
|
|
|
$item->setId( $id ); // set Modified false |
337
|
|
|
|
338
|
|
|
return $item; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Removes multiple items. |
344
|
|
|
* |
345
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface|array|string $items List of item objects or IDs of the items |
346
|
|
|
* @return \Aimeos\MShop\Locale\Manager\Site\Iface Manager object for chaining method calls |
347
|
|
|
*/ |
348
|
|
|
public function delete( $items ) : \Aimeos\MShop\Common\Manager\Iface |
349
|
|
|
{ |
350
|
|
|
if( is_map( $items ) ) { $items = $items->toArray(); } |
351
|
|
|
if( !is_array( $items ) ) { $items = [$items]; } |
352
|
|
|
if( empty( $items ) ) { return $this; } |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
$filter = $this->object()->filter() |
356
|
|
|
->add( ['locale.site.id' => $items] ) |
357
|
|
|
->slice( 0, count( $items ) ); |
358
|
|
|
|
359
|
|
|
$siteIds = $this->object()->search( $filter )->getSiteId()->toArray(); |
360
|
|
|
$this->object()->clear( $siteIds ); |
361
|
|
|
|
362
|
|
|
|
363
|
|
|
/** mshop/locale/manager/site/delete/mysql |
364
|
|
|
* Deletes the items matched by the given IDs from the database |
365
|
|
|
* |
366
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
367
|
|
|
*/ |
368
|
|
|
|
369
|
|
|
/** mshop/locale/manager/site/delete/ansi |
370
|
|
|
* Deletes the items matched by the given IDs from the database |
371
|
|
|
* |
372
|
|
|
* Removes the site records specified by the given IDs from the |
373
|
|
|
* locale database. The records must be from the site that is configured |
374
|
|
|
* via the context item. |
375
|
|
|
* |
376
|
|
|
* The ":cond" placeholder is replaced by the name of the ID column and |
377
|
|
|
* the given ID or list of IDs while the site ID is bound to the question |
378
|
|
|
* mark. |
379
|
|
|
* |
380
|
|
|
* The SQL statement should conform to the ANSI standard to be |
381
|
|
|
* compatible with most relational database systems. This also |
382
|
|
|
* includes using double quotes for table and column names. |
383
|
|
|
* |
384
|
|
|
* @param string SQL statement for deleting items |
385
|
|
|
* @since 2014.03 |
386
|
|
|
* @category Developer |
387
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
388
|
|
|
* @see mshop/locale/manager/site/update/ansi |
389
|
|
|
* @see mshop/locale/manager/site/search/ansi |
390
|
|
|
* @see mshop/locale/manager/site/count/ansi |
391
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
392
|
|
|
* @see mshop/locale/manager/site/rate/ansi |
393
|
|
|
*/ |
394
|
|
|
$path = 'mshop/locale/manager/site/delete'; |
395
|
|
|
|
396
|
|
|
return $this->deleteItemsBase( $items, $path, false ); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Returns the item specified by its code and domain/type if necessary |
402
|
|
|
* |
403
|
|
|
* @param string $code Code of the item |
404
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
405
|
|
|
* @param string|null $domain Domain of the item if necessary to identify the item uniquely |
406
|
|
|
* @param string|null $type Type code of the item if necessary to identify the item uniquely |
407
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
408
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface Item object |
409
|
|
|
*/ |
410
|
|
|
public function find( string $code, array $ref = [], string $domain = null, string $type = null, |
411
|
|
|
?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
412
|
|
|
{ |
413
|
|
|
return $this->findBase( array( 'locale.site.code' => $code ), $ref, $default ); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Returns the site item specified by its ID. |
419
|
|
|
* |
420
|
|
|
* @param string $id Unique ID of the site data in the storage |
421
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
422
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
423
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Returns the site item of the given id |
424
|
|
|
* @throws \Aimeos\MShop\Exception If the item couldn't be found |
425
|
|
|
*/ |
426
|
|
|
public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
427
|
|
|
{ |
428
|
|
|
return $this->getItemBase( 'locale.site.id', $id, $ref, $default ); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Returns the available manager types |
434
|
|
|
* |
435
|
|
|
* @param bool $withsub Return also the resource type of sub-managers if true |
436
|
|
|
* @return string Type of the manager and submanagers, subtypes are separated by slashes |
437
|
|
|
*/ |
438
|
|
|
public function getResourceType( bool $withsub = true ) : array |
439
|
|
|
{ |
440
|
|
|
$path = 'mshop/locale/manager/site/submanagers'; |
441
|
|
|
|
442
|
|
|
return $this->getResourceTypeBase( 'locale/site', $path, [], $withsub ); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Returns the attributes that can be used for searching. |
448
|
|
|
* |
449
|
|
|
* @param bool $withsub Return also attributes of sub-managers if true |
450
|
|
|
* @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items |
451
|
|
|
*/ |
452
|
|
|
public function getSearchAttributes( bool $withsub = true ) : array |
453
|
|
|
{ |
454
|
|
|
/** mshop/locale/manager/site/submanagers |
455
|
|
|
* List of manager names that can be instantiated by the locale site manager |
456
|
|
|
* |
457
|
|
|
* Managers provide a generic interface to the underlying storage. |
458
|
|
|
* Each manager has or can have sub-managers caring about particular |
459
|
|
|
* aspects. Each of these sub-managers can be instantiated by its |
460
|
|
|
* parent manager using the getSubManager() method. |
461
|
|
|
* |
462
|
|
|
* The search keys from sub-managers can be normally used in the |
463
|
|
|
* manager as well. It allows you to search for items of the manager |
464
|
|
|
* using the search keys of the sub-managers to further limit the |
465
|
|
|
* retrieved list of items. |
466
|
|
|
* |
467
|
|
|
* @param array List of sub-manager names |
468
|
|
|
* @since 2014.03 |
469
|
|
|
* @category Developer |
470
|
|
|
*/ |
471
|
|
|
$path = 'mshop/locale/manager/site/submanagers'; |
472
|
|
|
|
473
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Returns a new sub manager of the given type and name. |
479
|
|
|
* |
480
|
|
|
* @param string $manager Name of the sub manager type in lower case |
481
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
482
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Sub manager |
483
|
|
|
*/ |
484
|
|
|
public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface |
485
|
|
|
{ |
486
|
|
|
/** mshop/locale/manager/site/name |
487
|
|
|
* Class name of the used locale site manager implementation |
488
|
|
|
* |
489
|
|
|
* Each default locale site manager can be replaced by an alternative imlementation. |
490
|
|
|
* To use this implementation, you have to set the last part of the class |
491
|
|
|
* name as configuration value so the manager factory knows which class it |
492
|
|
|
* has to instantiate. |
493
|
|
|
* |
494
|
|
|
* For example, if the name of the default class is |
495
|
|
|
* |
496
|
|
|
* \Aimeos\MShop\Locale\Manager\Site\Standard |
497
|
|
|
* |
498
|
|
|
* and you want to replace it with your own version named |
499
|
|
|
* |
500
|
|
|
* \Aimeos\MShop\Locale\Manager\Site\Mysite |
501
|
|
|
* |
502
|
|
|
* then you have to set the this configuration option: |
503
|
|
|
* |
504
|
|
|
* mshop/locale/manager/site/name = Mysite |
505
|
|
|
* |
506
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
507
|
|
|
* so take care that the configuration value is exactly named like the last |
508
|
|
|
* part of the class name. |
509
|
|
|
* |
510
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
511
|
|
|
* characters are possible! You should always start the last part of the class |
512
|
|
|
* name with an upper case character and continue only with lower case characters |
513
|
|
|
* or numbers. Avoid chamel case names like "MySite"! |
514
|
|
|
* |
515
|
|
|
* @param string Last part of the class name |
516
|
|
|
* @since 2014.03 |
517
|
|
|
* @category Developer |
518
|
|
|
*/ |
519
|
|
|
|
520
|
|
|
/** mshop/locale/manager/site/decorators/excludes |
521
|
|
|
* Excludes decorators added by the "common" option from the locale site manager |
522
|
|
|
* |
523
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
524
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
525
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
526
|
|
|
* modify what is returned to the caller. |
527
|
|
|
* |
528
|
|
|
* This option allows you to remove a decorator added via |
529
|
|
|
* "mshop/common/manager/decorators/default" before they are wrapped |
530
|
|
|
* around the locale site manager. |
531
|
|
|
* |
532
|
|
|
* mshop/locale/manager/site/decorators/excludes = array( 'decorator1' ) |
533
|
|
|
* |
534
|
|
|
* This would remove the decorator named "decorator1" from the list of |
535
|
|
|
* common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
536
|
|
|
* "mshop/common/manager/decorators/default" for the locale site manager. |
537
|
|
|
* |
538
|
|
|
* @param array List of decorator names |
539
|
|
|
* @since 2014.03 |
540
|
|
|
* @category Developer |
541
|
|
|
* @see mshop/common/manager/decorators/default |
542
|
|
|
* @see mshop/locale/manager/site/decorators/global |
543
|
|
|
* @see mshop/locale/manager/site/decorators/local |
544
|
|
|
*/ |
545
|
|
|
|
546
|
|
|
/** mshop/locale/manager/site/decorators/global |
547
|
|
|
* Adds a list of globally available decorators only to the locale site manager |
548
|
|
|
* |
549
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
550
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
551
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
552
|
|
|
* modify what is returned to the caller. |
553
|
|
|
* |
554
|
|
|
* This option allows you to wrap global decorators |
555
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the locale site |
556
|
|
|
* manager. |
557
|
|
|
* |
558
|
|
|
* mshop/locale/manager/site/decorators/global = array( 'decorator1' ) |
559
|
|
|
* |
560
|
|
|
* This would add the decorator named "decorator1" defined by |
561
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the locale |
562
|
|
|
* site manager. |
563
|
|
|
* |
564
|
|
|
* @param array List of decorator names |
565
|
|
|
* @since 2014.03 |
566
|
|
|
* @category Developer |
567
|
|
|
* @see mshop/common/manager/decorators/default |
568
|
|
|
* @see mshop/locale/manager/site/decorators/excludes |
569
|
|
|
* @see mshop/locale/manager/site/decorators/local |
570
|
|
|
*/ |
571
|
|
|
|
572
|
|
|
/** mshop/locale/manager/site/decorators/local |
573
|
|
|
* Adds a list of local decorators only to the locale site manager |
574
|
|
|
* |
575
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
576
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
577
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
578
|
|
|
* modify what is returned to the caller. |
579
|
|
|
* |
580
|
|
|
* This option allows you to wrap local decorators |
581
|
|
|
* ("\Aimeos\MShop\Locale\Manager\Site\Decorator\*") around the locale site |
582
|
|
|
* manager. |
583
|
|
|
* |
584
|
|
|
* mshop/locale/manager/site/decorators/local = array( 'decorator2' ) |
585
|
|
|
* |
586
|
|
|
* This would add the decorator named "decorator2" defined by |
587
|
|
|
* "\Aimeos\MShop\Locale\Manager\Site\Decorator\Decorator2" only to the |
588
|
|
|
* locale site manager. |
589
|
|
|
* |
590
|
|
|
* @param array List of decorator names |
591
|
|
|
* @since 2014.03 |
592
|
|
|
* @category Developer |
593
|
|
|
* @see mshop/common/manager/decorators/default |
594
|
|
|
* @see mshop/locale/manager/site/decorators/excludes |
595
|
|
|
* @see mshop/locale/manager/site/decorators/global |
596
|
|
|
*/ |
597
|
|
|
|
598
|
|
|
return $this->getSubManagerBase( 'locale', 'site/' . $manager, $name ); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Searches for site items matching the given criteria. |
604
|
|
|
* |
605
|
|
|
* @param \Aimeos\Base\Criteria\Iface $search Search criteria object |
606
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
607
|
|
|
* @param int|null &$total Number of items that are available in total |
608
|
|
|
* @return \Aimeos\Map List of items implementing \Aimeos\MShop\Locale\Item\Site\Iface with ids as keys |
609
|
|
|
*/ |
610
|
|
|
public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map |
611
|
|
|
{ |
612
|
|
|
$items = []; |
613
|
|
|
$context = $this->context(); |
614
|
|
|
$conn = $context->db( $this->getResourceName() ); |
615
|
|
|
|
616
|
|
|
$attributes = $this->object()->getSearchAttributes(); |
617
|
|
|
$translations = $this->getSearchTranslations( $attributes ); |
618
|
|
|
$types = $this->getSearchTypes( $attributes ); |
619
|
|
|
$columns = $this->object()->getSaveAttributes(); |
620
|
|
|
$sortcols = $search->translate( $search->getSortations(), $translations ); |
621
|
|
|
|
622
|
|
|
$colstring = ''; |
623
|
|
|
foreach( $columns as $name => $entry ) { |
624
|
|
|
$colstring .= $entry->getInternalCode() . ', '; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
$find = array( ':columns', ':cond', ':order', ':start', ':size' ); |
628
|
|
|
$replace = array( |
629
|
|
|
$colstring . ( $sortcols ? join( ', ', $sortcols ) . ', ' : '' ), |
630
|
|
|
$search->getConditionSource( $types, $translations ), |
631
|
|
|
$search->getSortationSource( $types, $translations ), |
632
|
|
|
$search->getOffset(), |
633
|
|
|
$search->getLimit(), |
634
|
|
|
); |
635
|
|
|
|
636
|
|
|
/** mshop/locale/manager/site/search/mysql |
637
|
|
|
* Retrieves the records matched by the given criteria in the database |
638
|
|
|
* |
639
|
|
|
* @see mshop/locale/manager/site/search/ansi |
640
|
|
|
*/ |
641
|
|
|
|
642
|
|
|
/** mshop/locale/manager/site/search/ansi |
643
|
|
|
* Retrieves the records matched by the given criteria in the database |
644
|
|
|
* |
645
|
|
|
* Fetches the records matched by the given criteria from the attribute |
646
|
|
|
* database. The records must be from one of the sites that are |
647
|
|
|
* configured via the context item. If the current site is part of |
648
|
|
|
* a tree of sites, the SELECT statement can retrieve all records |
649
|
|
|
* from the current site and the complete sub-tree of sites. |
650
|
|
|
* |
651
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
652
|
|
|
* their tables must be joined in the SQL context. This is done by |
653
|
|
|
* using the "internaldeps" property from the definition of the ID |
654
|
|
|
* column of the sub-managers. These internal dependencies specify |
655
|
|
|
* the JOIN between the tables and the used columns for joining. The |
656
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
657
|
|
|
* the sub-managers. |
658
|
|
|
* |
659
|
|
|
* To limit the records matched, conditions can be added to the given |
660
|
|
|
* criteria object. It can contain comparisons like column names that |
661
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
662
|
|
|
* operators. The resulting string of SQL conditions replaces the |
663
|
|
|
* ":cond" placeholder before the statement is sent to the database |
664
|
|
|
* server. |
665
|
|
|
* |
666
|
|
|
* If the records that are retrieved should be ordered by one or more |
667
|
|
|
* columns, the generated string of column / sort direction pairs |
668
|
|
|
* replaces the ":order" placeholder. In case no ordering is required, |
669
|
|
|
* the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
670
|
|
|
* markers is removed to speed up retrieving the records. Columns of |
671
|
|
|
* sub-managers can also be used for ordering the result set but then |
672
|
|
|
* no index can be used. |
673
|
|
|
* |
674
|
|
|
* The number of returned records can be limited and can start at any |
675
|
|
|
* number between the begining and the end of the result set. For that |
676
|
|
|
* the ":size" and ":start" placeholders are replaced by the |
677
|
|
|
* corresponding values from the criteria object. The default values |
678
|
|
|
* are 0 for the start and 100 for the size value. |
679
|
|
|
* |
680
|
|
|
* The SQL statement should conform to the ANSI standard to be |
681
|
|
|
* compatible with most relational database systems. This also |
682
|
|
|
* includes using double quotes for table and column names. |
683
|
|
|
* |
684
|
|
|
* @param string SQL statement for searching items |
685
|
|
|
* @since 2014.03 |
686
|
|
|
* @category Developer |
687
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
688
|
|
|
* @see mshop/locale/manager/site/update/ansi |
689
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
690
|
|
|
* @see mshop/locale/manager/site/count/ansi |
691
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
692
|
|
|
* @see mshop/locale/manager/site/rate/ansi |
693
|
|
|
*/ |
694
|
|
|
$path = 'mshop/locale/manager/site/search'; |
695
|
|
|
|
696
|
|
|
$sql = $this->getSqlConfig( $path ); |
697
|
|
|
$results = $this->getSearchResults( $conn, str_replace( $find, $replace, $sql ) ); |
698
|
|
|
|
699
|
|
|
try |
700
|
|
|
{ |
701
|
|
|
while( ( $row = $results->fetch() ) !== null ) |
702
|
|
|
{ |
703
|
|
|
$id = $row['locale.site.id']; |
704
|
|
|
$logos = $row['locale.site.logo'] ?? '{}'; |
705
|
|
|
$config = $row['locale.site.config'] ?? '{}'; |
706
|
|
|
|
707
|
|
|
if( ( $row['locale.site.logo'] = json_decode( $logos, true ) ) === null ) |
708
|
|
|
{ |
709
|
|
|
$msg = sprintf( 'Invalid JSON as result of search for ID "%2$s" in "%1$s": %3$s', 'mshop_locale_site.logo', $id, $logos ); |
710
|
|
|
$this->context()->logger()->warning( $msg, 'core/locale/site' ); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
if( ( $row['locale.site.config'] = json_decode( $config, true ) ) === null ) |
714
|
|
|
{ |
715
|
|
|
$msg = sprintf( 'Invalid JSON as result of search for ID "%2$s" in "%1$s": %3$s', 'mshop_locale_site.config', $id, $config ); |
716
|
|
|
$this->context()->logger()->warning( $msg, 'core/locale/site' ); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
if( $item = $this->applyFilter( $this->createItemBase( $row ) ) ) { |
720
|
|
|
$items[$row['locale.site.id']] = $item; |
721
|
|
|
} |
722
|
|
|
} |
723
|
|
|
} |
724
|
|
|
catch( \Exception $e ) |
725
|
|
|
{ |
726
|
|
|
$results->finish(); |
727
|
|
|
throw $e; |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
if( $total !== null ) { |
731
|
|
|
$total = $this->getTotal( $conn, $find, $replace ); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
return map( $items ); |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* Creates a filter object. |
740
|
|
|
* |
741
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
742
|
|
|
* @param bool $site TRUE for adding site criteria to limit items by the site of related items |
743
|
|
|
* @return \Aimeos\Base\Criteria\Iface Returns the filter object |
744
|
|
|
*/ |
745
|
|
|
public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface |
746
|
|
|
{ |
747
|
|
|
$search = $this->filterBase( 'locale.site', $default ); |
748
|
|
|
|
749
|
|
|
$expr = array( |
750
|
|
|
$search->compare( '==', 'locale.site.level', 0 ), |
751
|
|
|
$search->getConditions(), |
752
|
|
|
); |
753
|
|
|
|
754
|
|
|
$search->setConditions( $search->and( $expr ) ); |
755
|
|
|
|
756
|
|
|
return $search; |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Returns a list of item IDs, that are in the path of given item ID. |
762
|
|
|
* |
763
|
|
|
* @param string $id ID of item to get the path for |
764
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
765
|
|
|
* @return \Aimeos\Map List of IDs as keys and items implementing \Aimeos\MShop\Locale\Item\Site\Iface |
766
|
|
|
*/ |
767
|
|
|
public function getPath( string $id, array $ref = [] ) : \Aimeos\Map |
768
|
|
|
{ |
769
|
|
|
$item = $this->getTree( $id, $ref, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
770
|
|
|
return map( [$item->getId() => $item] ); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* Returns a node and its descendants depending on the given resource. |
776
|
|
|
* |
777
|
|
|
* @param string|null $id Retrieve nodes starting from the given ID |
778
|
|
|
* @param string[] $ref List of domains (e.g. text, media, etc.) whose referenced items should be attached to the objects |
779
|
|
|
* @param int $level One of the level constants from \Aimeos\MW\Tree\Manager\Base |
780
|
|
|
* @param \Aimeos\Base\Criteria\Iface|null $criteria Optional criteria object with conditions |
781
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Site node, maybe with subnodes |
782
|
|
|
*/ |
783
|
|
|
public function getTree( string $id = null, array $ref = [], int $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, |
784
|
|
|
\Aimeos\Base\Criteria\Iface $criteria = null ) : \Aimeos\MShop\Locale\Item\Site\Iface |
785
|
|
|
{ |
786
|
|
|
if( $id !== null ) |
787
|
|
|
{ |
788
|
|
|
if( count( $ref ) > 0 ) { |
789
|
|
|
return $this->object()->get( $id, $ref ); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
if( !isset( $this->cache[$id] ) ) { |
793
|
|
|
$this->cache[$id] = $this->object()->get( $id, $ref ); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
return $this->cache[$id]; |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
$criteria = $criteria ? clone $criteria : $this->object()->filter(); |
800
|
|
|
$criteria->add( ['locale.site.code' => 'default'] )->slice( 0, 1 ); |
801
|
|
|
|
802
|
|
|
if( ( $item = $this->object()->search( $criteria, $ref )->first() ) === null ) |
803
|
|
|
{ |
804
|
|
|
$msg = $this->context()->translate( 'mshop', 'Tree root with code "%1$s" in "%2$s" not found' ); |
805
|
|
|
throw new \Aimeos\MShop\Locale\Exception( sprintf( $msg, 'default', 'locale.site.code' ) ); |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
$this->cache[$item->getId()] = $item; |
809
|
|
|
|
810
|
|
|
return $item; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* Adds a new item object. |
816
|
|
|
* |
817
|
|
|
* @param \Aimeos\MShop\Locale\Item\Site\Iface $item Item which should be inserted |
818
|
|
|
* @param string|null $parentId ID of the parent item where the item should be inserted into |
819
|
|
|
* @param string|null $refId ID of the item where the item should be inserted before (null to append) |
820
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface $item Updated item including the generated ID |
821
|
|
|
*/ |
822
|
|
|
public function insert( \Aimeos\MShop\Locale\Item\Site\Iface $item, string $parentId = null, string $refId = null ) : \Aimeos\MShop\Locale\Item\Site\Iface |
823
|
|
|
{ |
824
|
|
|
$context = $this->context(); |
825
|
|
|
$conn = $context->db( $this->getResourceName() ); |
826
|
|
|
|
827
|
|
|
$date = date( 'Y-m-d H:i:s' ); |
828
|
|
|
$columns = $this->object()->getSaveAttributes(); |
829
|
|
|
|
830
|
|
|
/** mshop/locale/manager/site/insert/mysql |
831
|
|
|
* Inserts a new currency record into the database table |
832
|
|
|
* |
833
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
834
|
|
|
*/ |
835
|
|
|
|
836
|
|
|
/** mshop/locale/manager/site/insert/ansi |
837
|
|
|
* Inserts a new currency record into the database table |
838
|
|
|
* |
839
|
|
|
* The SQL statement must be a string suitable for being used as |
840
|
|
|
* prepared statement. It must include question marks for binding |
841
|
|
|
* the values from the site item to the statement before they are |
842
|
|
|
* sent to the database server. The number of question marks must |
843
|
|
|
* be the same as the number of columns listed in the INSERT |
844
|
|
|
* statement. The order of the columns must correspond to the |
845
|
|
|
* order in the save() method, so the correct values are |
846
|
|
|
* bound to the columns. |
847
|
|
|
* |
848
|
|
|
* The SQL statement should conform to the ANSI standard to be |
849
|
|
|
* compatible with most relational database systems. This also |
850
|
|
|
* includes using double quotes for table and column names. |
851
|
|
|
* |
852
|
|
|
* @param string SQL statement for inserting records |
853
|
|
|
* @since 2014.03 |
854
|
|
|
* @category Developer |
855
|
|
|
* @see mshop/locale/manager/site/update/ansi |
856
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
857
|
|
|
* @see mshop/locale/manager/site/search/ansi |
858
|
|
|
* @see mshop/locale/manager/site/count/ansi |
859
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
860
|
|
|
* @see mshop/locale/manager/site/rate/ansi |
861
|
|
|
*/ |
862
|
|
|
$path = 'mshop/locale/manager/site/insert'; |
863
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) ); |
|
|
|
|
864
|
|
|
|
865
|
|
|
$idx = 1; |
866
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
867
|
|
|
|
868
|
|
|
foreach( $columns as $name => $entry ) { |
869
|
|
|
$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() ); |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
$stmt->bind( $idx++, '' ); // site ID |
873
|
|
|
$stmt->bind( $idx++, $item->getCode() ); |
874
|
|
|
$stmt->bind( $idx++, $item->getLabel() ); |
875
|
|
|
$stmt->bind( $idx++, json_encode( $item->getConfig(), JSON_FORCE_OBJECT ) ); |
876
|
|
|
$stmt->bind( $idx++, $item->getStatus(), \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
877
|
|
|
$stmt->bind( $idx++, $item->getIcon() ); |
878
|
|
|
$stmt->bind( $idx++, json_encode( $item->getLogos(), JSON_FORCE_OBJECT ) ); |
879
|
|
|
$stmt->bind( $idx++, $item->getRefId() ); |
880
|
|
|
$stmt->bind( $idx++, $item->getTheme() ); |
881
|
|
|
$stmt->bind( $idx++, $context->editor() ); |
882
|
|
|
$stmt->bind( $idx++, $date ); // mtime |
883
|
|
|
$stmt->bind( $idx++, $date ); // ctime |
884
|
|
|
|
885
|
|
|
$stmt->execute()->finish(); |
886
|
|
|
|
887
|
|
|
/** mshop/locale/manager/site/newid/mysql |
888
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
889
|
|
|
* |
890
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
891
|
|
|
*/ |
892
|
|
|
|
893
|
|
|
/** mshop/locale/manager/site/newid/ansi |
894
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
895
|
|
|
* |
896
|
|
|
* As soon as a new record is inserted into the database table, |
897
|
|
|
* the database server generates a new and unique identifier for |
898
|
|
|
* that record. This ID can be used for retrieving, updating and |
899
|
|
|
* deleting that specific record from the table again. |
900
|
|
|
* |
901
|
|
|
* For MySQL: |
902
|
|
|
* SELECT LAST_INSERT_ID() |
903
|
|
|
* For PostgreSQL: |
904
|
|
|
* SELECT currval('seq_matt_id') |
905
|
|
|
* For SQL Server: |
906
|
|
|
* SELECT SCOPE_IDENTITY() |
907
|
|
|
* For Oracle: |
908
|
|
|
* SELECT "seq_matt_id".CURRVAL FROM DUAL |
909
|
|
|
* |
910
|
|
|
* There's no way to retrive the new ID by a SQL statements that |
911
|
|
|
* fits for most database servers as they implement their own |
912
|
|
|
* specific way. |
913
|
|
|
* |
914
|
|
|
* @param string SQL statement for retrieving the last inserted record ID |
915
|
|
|
* @since 2014.03 |
916
|
|
|
* @category Developer |
917
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
918
|
|
|
* @see mshop/locale/manager/site/update/ansi |
919
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
920
|
|
|
* @see mshop/locale/manager/site/search/ansi |
921
|
|
|
* @see mshop/locale/manager/site/count/ansi |
922
|
|
|
* @see mshop/locale/manager/site/rate/ansi |
923
|
|
|
*/ |
924
|
|
|
$path = 'mshop/locale/manager/newid'; |
925
|
|
|
$item->setId( $this->newId( $conn, $this->getSqlConfig( $path ) ) ); |
|
|
|
|
926
|
|
|
|
927
|
|
|
// Add unique site identifier |
928
|
|
|
$item = $this->object()->save( $item->setSiteId( $item->getId() . '.' ) ); |
929
|
|
|
|
930
|
|
|
return $item; |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
|
934
|
|
|
/** |
935
|
|
|
* Moves an existing item to the new parent in the storage. |
936
|
|
|
* |
937
|
|
|
* @param string $id ID of the item that should be moved |
938
|
|
|
* @param string|null $oldParentId ID of the old parent item which currently contains the item that should be removed |
939
|
|
|
* @param string|null $newParentId ID of the new parent item where the item should be moved to |
940
|
|
|
* @param string|null $refId ID of the item where the item should be inserted before (null to append) |
941
|
|
|
* @return \Aimeos\MShop\Locale\Manager\Site\Iface Manager object for chaining method calls |
942
|
|
|
*/ |
943
|
|
|
public function move( string $id, string $oldParentId = null, string $newParentId = null, |
944
|
|
|
string $refId = null ) : \Aimeos\MShop\Locale\Manager\Site\Iface |
945
|
|
|
{ |
946
|
|
|
$msg = $this->context()->translate( 'mshop', 'Method "%1$s" for locale site manager not available' ); |
947
|
|
|
throw new \Aimeos\MShop\Locale\Exception( sprintf( $msg, 'move()' ) ); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* Updates the rating of the item |
953
|
|
|
* |
954
|
|
|
* @param string $id ID of the item |
955
|
|
|
* @param string $rating Decimal value of the rating |
956
|
|
|
* @param int $ratings Total number of ratings for the item |
957
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls |
958
|
|
|
*/ |
959
|
|
|
public function rate( string $id, string $rating, int $ratings ) : \Aimeos\MShop\Common\Manager\Iface |
960
|
|
|
{ |
961
|
|
|
$context = $this->context(); |
962
|
|
|
$conn = $context->db( $this->getResourceName() ); |
963
|
|
|
|
964
|
|
|
/** mshop/locale/manager/site/rate/mysql |
965
|
|
|
* Updates the rating of the product in the database |
966
|
|
|
* |
967
|
|
|
* @see mshop/locale/manager/site/rate/ansi |
968
|
|
|
*/ |
969
|
|
|
|
970
|
|
|
/** mshop/locale/manager/site/rate/ansi |
971
|
|
|
* Updates the rating of the product in the database |
972
|
|
|
* |
973
|
|
|
* The SQL statement must be a string suitable for being used as |
974
|
|
|
* prepared statement. It must include question marks for binding |
975
|
|
|
* the values for the rating to the statement before they are |
976
|
|
|
* sent to the database server. The order of the columns must |
977
|
|
|
* correspond to the order in the rate() method, so the |
978
|
|
|
* correct values are bound to the columns. |
979
|
|
|
* |
980
|
|
|
* The SQL statement should conform to the ANSI standard to be |
981
|
|
|
* compatible with most relational database systems. This also |
982
|
|
|
* includes using double quotes for table and column names. |
983
|
|
|
* |
984
|
|
|
* @param string SQL statement for update ratings |
985
|
|
|
* @since 2022.10 |
986
|
|
|
* @category Developer |
987
|
|
|
* @see mshop/locale/manager/site/update/ansi |
988
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
989
|
|
|
* @see mshop/locale/manager/site/search/ansi |
990
|
|
|
* @see mshop/locale/manager/site/count/ansi |
991
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
992
|
|
|
*/ |
993
|
|
|
$path = 'mshop/locale/manager/site/rate'; |
994
|
|
|
|
995
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $this->getSqlConfig( $path ) ); |
|
|
|
|
996
|
|
|
|
997
|
|
|
$stmt->bind( 1, $rating ); |
998
|
|
|
$stmt->bind( 2, $ratings, \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
999
|
|
|
$stmt->bind( 3, (int) $id, \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
1000
|
|
|
|
1001
|
|
|
$stmt->execute()->finish(); |
1002
|
|
|
|
1003
|
|
|
return $this; |
1004
|
|
|
} |
1005
|
|
|
|
1006
|
|
|
|
1007
|
|
|
/** |
1008
|
|
|
* Registers a new item filter for the given name |
1009
|
|
|
* |
1010
|
|
|
* Not used for site items but required for trees |
1011
|
|
|
* |
1012
|
|
|
* @param string $name Filter name |
1013
|
|
|
* @param \Closure $fcn Callback function |
1014
|
|
|
*/ |
1015
|
|
|
public function registerItemFilter( string $name, \Closure $fcn ) : \Aimeos\MShop\Locale\Manager\Site\Iface |
1016
|
|
|
{ |
1017
|
|
|
return $this; |
1018
|
|
|
} |
1019
|
|
|
|
1020
|
|
|
|
1021
|
|
|
/** |
1022
|
|
|
* Returns the search results for the given SQL statement. |
1023
|
|
|
* |
1024
|
|
|
* @param \Aimeos\Base\DB\Connection\Iface $conn Database connection |
1025
|
|
|
* @param string $sql SQL statement |
1026
|
|
|
* @return \Aimeos\Base\DB\Result\Iface Search result object |
1027
|
|
|
*/ |
1028
|
|
|
protected function getSearchResults( \Aimeos\Base\DB\Connection\Iface $conn, string $sql ) : \Aimeos\Base\DB\Result\Iface |
1029
|
|
|
{ |
1030
|
|
|
$time = microtime( true ); |
1031
|
|
|
|
1032
|
|
|
$stmt = $conn->create( $sql ); |
1033
|
|
|
$result = $stmt->execute(); |
1034
|
|
|
|
1035
|
|
|
$msg = 'Time: ' . ( microtime( true ) - $time ) * 1000 . "ms\n" |
1036
|
|
|
. 'Class: ' . get_class( $this ) . "\n" |
1037
|
|
|
. str_replace( ["\t", "\n\n"], ['', "\n"], trim( (string) $stmt ) ); |
1038
|
|
|
|
1039
|
|
|
$this->context()->logger()->debug( $msg, 'core/sql' ); |
1040
|
|
|
|
1041
|
|
|
return $result; |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
|
1045
|
|
|
/** |
1046
|
|
|
* Create new item object initialized with given parameters. |
1047
|
|
|
* |
1048
|
|
|
* @param array $values Associative list of item key/value pairs |
1049
|
|
|
* @return \Aimeos\MShop\Locale\Item\Site\Iface Site item object |
1050
|
|
|
*/ |
1051
|
|
|
protected function createItemBase( array $values = [] ) : \Aimeos\MShop\Locale\Item\Site\Iface |
1052
|
|
|
{ |
1053
|
|
|
return new \Aimeos\MShop\Locale\Item\Site\Standard( $values ); |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
|
1057
|
|
|
/** |
1058
|
|
|
* Returns the raw search config array. |
1059
|
|
|
* |
1060
|
|
|
* @return array List of search config arrays |
1061
|
|
|
*/ |
1062
|
|
|
protected function getSearchConfig() : array |
1063
|
|
|
{ |
1064
|
|
|
return $this->searchConfig; |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
|
1068
|
|
|
/** |
1069
|
|
|
* Returns the total number of items found for the conditions |
1070
|
|
|
* |
1071
|
|
|
* @param \Aimeos\Base\DB\Connection\Iface $conn Database connection |
1072
|
|
|
* @param string[] $find List of markers that should be replaced in the SQL statement |
1073
|
|
|
* @param string[] $replace List of replacements for the markers in the SQL statement |
1074
|
|
|
* @throws \Aimeos\MShop\Locale\Exception If no total value was found |
1075
|
|
|
* @return int Total number of found items |
1076
|
|
|
*/ |
1077
|
|
|
protected function getTotal( \Aimeos\Base\DB\Connection\Iface $conn, array $find, array $replace ) : int |
1078
|
|
|
{ |
1079
|
|
|
/** mshop/locale/manager/site/count/mysql |
1080
|
|
|
* Counts the number of records matched by the given criteria in the database |
1081
|
|
|
* |
1082
|
|
|
* @see mshop/locale/manager/site/count/ansi |
1083
|
|
|
*/ |
1084
|
|
|
|
1085
|
|
|
/** mshop/locale/manager/site/count/ansi |
1086
|
|
|
* Counts the number of records matched by the given criteria in the database |
1087
|
|
|
* |
1088
|
|
|
* Counts all records matched by the given criteria from the attribute |
1089
|
|
|
* database. The records must be from one of the sites that are |
1090
|
|
|
* configured via the context item. If the current site is part of |
1091
|
|
|
* a tree of sites, the statement can count all records from the |
1092
|
|
|
* current site and the complete sub-tree of sites. |
1093
|
|
|
* |
1094
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
1095
|
|
|
* their tables must be joined in the SQL context. This is done by |
1096
|
|
|
* using the "internaldeps" property from the definition of the ID |
1097
|
|
|
* column of the sub-managers. These internal dependencies specify |
1098
|
|
|
* the JOIN between the tables and the used columns for joining. The |
1099
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
1100
|
|
|
* the sub-managers. |
1101
|
|
|
* |
1102
|
|
|
* To limit the records matched, conditions can be added to the given |
1103
|
|
|
* criteria object. It can contain comparisons like column names that |
1104
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
1105
|
|
|
* operators. The resulting string of SQL conditions replaces the |
1106
|
|
|
* ":cond" placeholder before the statement is sent to the database |
1107
|
|
|
* server. |
1108
|
|
|
* |
1109
|
|
|
* Both, the strings for ":joins" and for ":cond" are the same as for |
1110
|
|
|
* the "search" SQL statement. |
1111
|
|
|
* |
1112
|
|
|
* Contrary to the "search" statement, it doesn't return any records |
1113
|
|
|
* but instead the number of records that have been found. As counting |
1114
|
|
|
* thousands of records can be a long running task, the maximum number |
1115
|
|
|
* of counted records is limited for performance reasons. |
1116
|
|
|
* |
1117
|
|
|
* The SQL statement should conform to the ANSI standard to be |
1118
|
|
|
* compatible with most relational database systems. This also |
1119
|
|
|
* includes using double quotes for table and column names. |
1120
|
|
|
* |
1121
|
|
|
* @param string SQL statement for counting items |
1122
|
|
|
* @since 2014.03 |
1123
|
|
|
* @category Developer |
1124
|
|
|
* @see mshop/locale/manager/site/insert/ansi |
1125
|
|
|
* @see mshop/locale/manager/site/update/ansi |
1126
|
|
|
* @see mshop/locale/manager/site/delete/ansi |
1127
|
|
|
* @see mshop/locale/manager/site/search/ansi |
1128
|
|
|
* @see mshop/locale/manager/site/newid/ansi |
1129
|
|
|
*/ |
1130
|
|
|
$path = 'mshop/locale/manager/site/count'; |
1131
|
|
|
|
1132
|
|
|
$sql = $this->getSqlConfig( $path ); |
1133
|
|
|
$results = $this->getSearchResults( $conn, str_replace( $find, $replace, $sql ) ); |
1134
|
|
|
|
1135
|
|
|
$row = $results->fetch(); |
1136
|
|
|
$results->finish(); |
1137
|
|
|
|
1138
|
|
|
if( $row === null ) { |
1139
|
|
|
throw new \Aimeos\MShop\Locale\Exception( 'No total results value found' ); |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
return $row['count']; |
1143
|
|
|
} |
1144
|
|
|
} |
1145
|
|
|
|