1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Locale |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Locale\Manager\Currency; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation for managing currencies. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Locale |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
|
|
|
|
23
|
|
|
implements \Aimeos\MShop\Locale\Manager\Currency\Iface |
24
|
|
|
{ |
25
|
|
|
private $searchConfig = array( |
26
|
|
|
'locale.currency.id' => array( |
27
|
|
|
'code' => 'locale.currency.id', |
28
|
|
|
'internalcode' => 'mloccu."id"', |
29
|
|
|
'internaldeps' => array( 'LEFT JOIN "mshop_locale_currency" AS mloccu ON (mloc."currencyid" = mloccu."id")' ), |
30
|
|
|
'label' => 'Currency ID', |
31
|
|
|
'type' => 'string', |
32
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
33
|
|
|
'public' => false, |
34
|
|
|
), |
35
|
|
|
'locale.currency.siteid' => array( |
36
|
|
|
'code' => 'locale.currency.siteid', |
37
|
|
|
'internalcode' => 'mloccu."siteid"', |
38
|
|
|
'label' => 'Currency site ID', |
39
|
|
|
'type' => 'string', |
40
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
41
|
|
|
'public' => false, |
42
|
|
|
), |
43
|
|
|
'locale.currency.label' => array( |
44
|
|
|
'code' => 'locale.currency.label', |
45
|
|
|
'internalcode' => 'mloccu."label"', |
46
|
|
|
'label' => 'Currency label', |
47
|
|
|
'type' => 'string', |
48
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
49
|
|
|
), |
50
|
|
|
'locale.currency.code' => array( |
51
|
|
|
'code' => 'locale.currency.code', |
52
|
|
|
'internalcode' => 'mloccu."id"', |
53
|
|
|
'label' => 'Currency code', |
54
|
|
|
'type' => 'string', |
55
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
56
|
|
|
), |
57
|
|
|
'locale.currency.status' => array( |
58
|
|
|
'code' => 'locale.currency.status', |
59
|
|
|
'internalcode' => 'mloccu."status"', |
60
|
|
|
'label' => 'Currency status', |
61
|
|
|
'type' => 'integer', |
62
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
63
|
|
|
), |
64
|
|
|
'locale.currency.ctime' => array( |
65
|
|
|
'code' => 'locale.currency.ctime', |
66
|
|
|
'internalcode' => 'mloccu."ctime"', |
67
|
|
|
'label' => 'Currency create date/time', |
68
|
|
|
'type' => 'datetime', |
69
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
70
|
|
|
'public' => false, |
71
|
|
|
), |
72
|
|
|
'locale.currency.mtime' => array( |
73
|
|
|
'code' => 'locale.currency.mtime', |
74
|
|
|
'internalcode' => 'mloccu."mtime"', |
75
|
|
|
'label' => 'Currency modify date/time', |
76
|
|
|
'type' => 'datetime', |
77
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
78
|
|
|
'public' => false, |
79
|
|
|
), |
80
|
|
|
'locale.currency.editor' => array( |
81
|
|
|
'code' => 'locale.currency.editor', |
82
|
|
|
'internalcode' => 'mloccu."editor"', |
83
|
|
|
'label' => 'Currency editor', |
84
|
|
|
'type' => 'string', |
85
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
86
|
|
|
'public' => false, |
87
|
|
|
), |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Initializes the object. |
93
|
|
|
* |
94
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
95
|
|
|
*/ |
96
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
97
|
|
|
{ |
98
|
|
|
parent::__construct( $context ); |
99
|
|
|
$this->setResourceName( 'db-locale' ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Creates new currency object. |
105
|
|
|
* |
106
|
|
|
* @return \Aimeos\MShop\Locale\Item\Currency\Iface |
107
|
|
|
* @throws \Aimeos\MShop\Locale\Exception On failures with the language item object |
108
|
|
|
*/ |
109
|
|
|
public function createItem() |
110
|
|
|
{ |
111
|
|
|
try { |
112
|
|
|
$values = array( 'locale.currency.siteid' => $this->getContext()->getLocale()->getSiteId() ); |
113
|
|
|
} catch( \Exception $ex ) { |
114
|
|
|
$values = array( 'locale.currency.siteid' => null ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->createItemBase( $values ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Saves a currency item to the storage. |
123
|
|
|
* |
124
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface $item Currency item to save in the storage |
125
|
|
|
* @param boolean $fetch True if the new ID should be returned in the item |
126
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID |
127
|
|
|
* |
128
|
|
|
* @throws \Aimeos\MW\DB\Exception If currency object couldn't be saved |
129
|
|
|
* @throws \Aimeos\MShop\Locale\Exception If failures with currency item object |
130
|
|
|
*/ |
131
|
|
|
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true ) |
132
|
|
|
{ |
133
|
|
|
$iface = '\\Aimeos\\MShop\\Locale\\Item\\Currency\\Iface'; |
134
|
|
|
if( !( $item instanceof $iface ) ) { |
135
|
|
|
throw new \Aimeos\MShop\Locale\Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if( !$item->isModified() ) { |
139
|
|
|
return $item; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$context = $this->getContext(); |
143
|
|
|
|
144
|
|
|
$dbm = $context->getDatabaseManager(); |
145
|
|
|
$dbname = $this->getResourceName(); |
146
|
|
|
$conn = $dbm->acquire( $dbname ); |
147
|
|
|
|
148
|
|
|
try |
149
|
|
|
{ |
150
|
|
|
$id = $item->getId(); |
151
|
|
|
$date = date( 'Y-m-d H:i:s' ); |
152
|
|
|
|
153
|
|
|
if( $id === null ) |
154
|
|
|
{ |
155
|
|
|
/** mshop/locale/manager/currency/standard/insert/mysql |
156
|
|
|
* Inserts a new currency record into the database table |
157
|
|
|
* |
158
|
|
|
* @see mshop/locale/manager/currency/standard/insert/ansi |
159
|
|
|
*/ |
160
|
|
|
|
161
|
|
|
/** mshop/locale/manager/currency/standard/insert/ansi |
162
|
|
|
* Inserts a new currency record into the database table |
163
|
|
|
* |
164
|
|
|
* The SQL statement must be a string suitable for being used as |
165
|
|
|
* prepared statement. It must include question marks for binding |
166
|
|
|
* the values from the currency item to the statement before they are |
167
|
|
|
* sent to the database server. The number of question marks must |
168
|
|
|
* be the same as the number of columns listed in the INSERT |
169
|
|
|
* statement. The order of the columns must correspond to the |
170
|
|
|
* order in the saveItems() method, so the correct values are |
171
|
|
|
* bound to the columns. |
172
|
|
|
* |
173
|
|
|
* The SQL statement should conform to the ANSI standard to be |
174
|
|
|
* compatible with most relational database systems. This also |
175
|
|
|
* includes using double quotes for table and column names. |
176
|
|
|
* |
177
|
|
|
* @param string SQL statement for inserting records |
178
|
|
|
* @since 2014.03 |
179
|
|
|
* @category Developer |
180
|
|
|
* @see mshop/locale/manager/currency/standard/update/ansi |
181
|
|
|
* @see mshop/locale/manager/currency/standard/delete/ansi |
182
|
|
|
* @see mshop/locale/manager/currency/standard/search/ansi |
183
|
|
|
* @see mshop/locale/manager/currency/standard/count/ansi |
184
|
|
|
*/ |
185
|
|
|
$path = 'mshop/locale/manager/currency/standard/insert'; |
186
|
|
|
} |
187
|
|
|
else |
188
|
|
|
{ |
189
|
|
|
/** mshop/locale/manager/currency/standard/update/mysql |
190
|
|
|
* Updates an existing currency record in the database |
191
|
|
|
* |
192
|
|
|
* @see mshop/locale/manager/currency/standard/update/ansi |
193
|
|
|
*/ |
194
|
|
|
|
195
|
|
|
/** mshop/locale/manager/currency/standard/update/ansi |
196
|
|
|
* Updates an existing currency record in the database |
197
|
|
|
* |
198
|
|
|
* The SQL statement must be a string suitable for being used as |
199
|
|
|
* prepared statement. It must include question marks for binding |
200
|
|
|
* the values from the currency item to the statement before they are |
201
|
|
|
* sent to the database server. The order of the columns must |
202
|
|
|
* correspond to the order in the saveItems() method, so the |
203
|
|
|
* correct values are bound to the columns. |
204
|
|
|
* |
205
|
|
|
* The SQL statement should conform to the ANSI standard to be |
206
|
|
|
* compatible with most relational database systems. This also |
207
|
|
|
* includes using double quotes for table and column names. |
208
|
|
|
* |
209
|
|
|
* @param string SQL statement for updating records |
210
|
|
|
* @since 2014.03 |
211
|
|
|
* @category Developer |
212
|
|
|
* @see mshop/locale/manager/currency/standard/insert/ansi |
213
|
|
|
* @see mshop/locale/manager/currency/standard/delete/ansi |
214
|
|
|
* @see mshop/locale/manager/currency/standard/search/ansi |
215
|
|
|
* @see mshop/locale/manager/currency/standard/count/ansi |
216
|
|
|
*/ |
217
|
|
|
$path = 'mshop/locale/manager/currency/standard/update'; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$stmt = $this->getCachedStatement( $conn, $path ); |
221
|
|
|
|
222
|
|
|
$stmt->bind( 1, $item->getLabel() ); |
223
|
|
|
$stmt->bind( 2, $item->getStatus(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
224
|
|
|
$stmt->bind( 3, $item->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
225
|
|
|
$stmt->bind( 4, $date ); // mtime |
226
|
|
|
$stmt->bind( 5, $context->getEditor() ); |
227
|
|
|
// bind ID but code and id are identical after saveing the stuff |
228
|
|
|
// id is the flag to detect updates or inserts! |
229
|
|
|
$stmt->bind( 6, $item->getCode() ); |
230
|
|
|
|
231
|
|
|
if( $id === null ) { |
232
|
|
|
$stmt->bind( 7, $date ); // ctime |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$stmt->execute()->finish(); |
236
|
|
|
|
237
|
|
|
$item->setId( $item->getCode() ); // set modified flag to false |
238
|
|
|
|
239
|
|
|
$dbm->release( $conn, $dbname ); |
240
|
|
|
} |
241
|
|
|
catch( \Exception $e ) |
242
|
|
|
{ |
243
|
|
|
$dbm->release( $conn, $dbname ); |
244
|
|
|
throw $e; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return $item; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Removes multiple items specified by ids in the array. |
253
|
|
|
* |
254
|
|
|
* @param array $ids List of IDs |
255
|
|
|
*/ |
256
|
|
|
public function deleteItems( array $ids ) |
257
|
|
|
{ |
258
|
|
|
/** mshop/locale/manager/currency/standard/delete/mysql |
259
|
|
|
* Deletes the items matched by the given IDs from the database |
260
|
|
|
* |
261
|
|
|
* @see mshop/locale/manager/currency/standard/delete/ansi |
262
|
|
|
*/ |
263
|
|
|
|
264
|
|
|
/** mshop/locale/manager/currency/standard/delete/ansi |
265
|
|
|
* Deletes the items matched by the given IDs from the database |
266
|
|
|
* |
267
|
|
|
* Removes the language records specified by the given IDs from the |
268
|
|
|
* locale database. The records must be from the site that is configured |
269
|
|
|
* via the context item. |
270
|
|
|
* |
271
|
|
|
* The ":cond" placeholder is replaced by the name of the ID column and |
272
|
|
|
* the given ID or list of IDs while the site ID is bound to the question |
273
|
|
|
* mark. |
274
|
|
|
* |
275
|
|
|
* The SQL statement should conform to the ANSI standard to be |
276
|
|
|
* compatible with most relational database systems. This also |
277
|
|
|
* includes using double quotes for table and column names. |
278
|
|
|
* |
279
|
|
|
* @param string SQL statement for deleting items |
280
|
|
|
* @since 2014.03 |
281
|
|
|
* @category Developer |
282
|
|
|
* @see mshop/locale/manager/currency/standard/insert/ansi |
283
|
|
|
* @see mshop/locale/manager/currency/standard/update/ansi |
284
|
|
|
* @see mshop/locale/manager/currency/standard/search/ansi |
285
|
|
|
* @see mshop/locale/manager/currency/standard/count/ansi |
286
|
|
|
*/ |
287
|
|
|
$path = 'mshop/locale/manager/currency/standard/delete'; |
288
|
|
|
$this->deleteItemsBase( $ids, $path ); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Returns the currency object with the given currency ID. |
294
|
|
|
* |
295
|
|
|
* @param string $id Currency ID indentifying the currency object |
296
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
297
|
|
|
* @param boolean $default Add default criteria |
298
|
|
|
* @return \Aimeos\MShop\Locale\Item\Currency\Iface Returns the currency item of the given id |
299
|
|
|
* @throws \Aimeos\MShop\Exception If item couldn't be found |
300
|
|
|
*/ |
301
|
|
|
public function getItem( $id, array $ref = [], $default = false ) |
302
|
|
|
{ |
303
|
|
|
return $this->getItemBase( 'locale.currency.id', $id, $ref, $default ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Returns the available manager types |
309
|
|
|
* |
310
|
|
|
* @param boolean $withsub Return also the resource type of sub-managers if true |
311
|
|
|
* @return array Type of the manager and submanagers, subtypes are separated by slashes |
312
|
|
|
*/ |
313
|
|
|
public function getResourceType( $withsub = true ) |
314
|
|
|
{ |
315
|
|
|
$path = 'mshop/locale/manager/currency/submanagers'; |
316
|
|
|
|
317
|
|
|
return $this->getResourceTypeBase( 'locale/currency', $path, [], $withsub ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Returns the attributes that can be used for searching. |
323
|
|
|
* |
324
|
|
|
* @param boolean $withsub Return also attributes of sub-managers if true |
325
|
|
|
* @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface |
326
|
|
|
*/ |
327
|
|
|
public function getSearchAttributes( $withsub = true ) |
328
|
|
|
{ |
329
|
|
|
/** mshop/locale/manager/currency/submanagers |
330
|
|
|
* List of manager names that can be instantiated by the locale currency manager |
331
|
|
|
* |
332
|
|
|
* Managers provide a generic interface to the underlying storage. |
333
|
|
|
* Each manager has or can have sub-managers caring about particular |
334
|
|
|
* aspects. Each of these sub-managers can be instantiated by its |
335
|
|
|
* parent manager using the getSubManager() method. |
336
|
|
|
* |
337
|
|
|
* The search keys from sub-managers can be normally used in the |
338
|
|
|
* manager as well. It allows you to search for items of the manager |
339
|
|
|
* using the search keys of the sub-managers to further limit the |
340
|
|
|
* retrieved list of items. |
341
|
|
|
* |
342
|
|
|
* @param array List of sub-manager names |
343
|
|
|
* @since 2014.03 |
344
|
|
|
* @category Developer |
345
|
|
|
*/ |
346
|
|
|
$path = 'mshop/locale/manager/currency/submanagers'; |
347
|
|
|
|
348
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Search for currency items matching the given criteria. |
354
|
|
|
* |
355
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
356
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
357
|
|
|
* @param integer|null &$total Number of items that are available in total |
358
|
|
|
* @return array List of items implementing \Aimeos\MShop\Locale\Item\Currency\Iface |
359
|
|
|
*/ |
360
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
361
|
|
|
{ |
362
|
|
|
$context = $this->getContext(); |
363
|
|
|
|
364
|
|
|
$dbm = $context->getDatabaseManager(); |
365
|
|
|
$dbname = $this->getResourceName(); |
366
|
|
|
$conn = $dbm->acquire( $dbname ); |
367
|
|
|
|
368
|
|
|
$items = []; |
369
|
|
|
|
370
|
|
|
try |
371
|
|
|
{ |
372
|
|
|
$attributes = $this->getObject()->getSearchAttributes(); |
373
|
|
|
$types = $this->getSearchTypes( $attributes ); |
374
|
|
|
$translations = $this->getSearchTranslations( $attributes ); |
375
|
|
|
$columns = $search->getColumnString( $search->getSortations(), $translations ); |
376
|
|
|
|
377
|
|
|
$find = array( ':cond', ':order', ':columns', ':start', ':size' ); |
378
|
|
|
$replace = array( |
379
|
|
|
$search->getConditionString( $types, $translations ), |
380
|
|
|
$search->getSortationString( $types, $translations ), |
381
|
|
|
( $columns ? ', ' . $columns : '' ), |
382
|
|
|
$search->getSliceStart(), |
383
|
|
|
$search->getSliceSize(), |
384
|
|
|
); |
385
|
|
|
|
386
|
|
|
/** mshop/locale/manager/currency/standard/search/mysql |
387
|
|
|
* Retrieves the records matched by the given criteria in the database |
388
|
|
|
* |
389
|
|
|
* @see mshop/locale/manager/currency/standard/search/ansi |
390
|
|
|
*/ |
391
|
|
|
|
392
|
|
|
/** mshop/locale/manager/currency/standard/search/ansi |
393
|
|
|
* Retrieves the records matched by the given criteria in the database |
394
|
|
|
* |
395
|
|
|
* Fetches the records matched by the given criteria from the attribute |
396
|
|
|
* database. The records must be from one of the sites that are |
397
|
|
|
* configured via the context item. If the current site is part of |
398
|
|
|
* a tree of sites, the SELECT statement can retrieve all records |
399
|
|
|
* from the current site and the complete sub-tree of sites. |
400
|
|
|
* |
401
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
402
|
|
|
* their tables must be joined in the SQL context. This is done by |
403
|
|
|
* using the "internaldeps" property from the definition of the ID |
404
|
|
|
* column of the sub-managers. These internal dependencies specify |
405
|
|
|
* the JOIN between the tables and the used columns for joining. The |
406
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
407
|
|
|
* the sub-managers. |
408
|
|
|
* |
409
|
|
|
* To limit the records matched, conditions can be added to the given |
410
|
|
|
* criteria object. It can contain comparisons like column names that |
411
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
412
|
|
|
* operators. The resulting string of SQL conditions replaces the |
413
|
|
|
* ":cond" placeholder before the statement is sent to the database |
414
|
|
|
* server. |
415
|
|
|
* |
416
|
|
|
* If the records that are retrieved should be ordered by one or more |
417
|
|
|
* columns, the generated string of column / sort direction pairs |
418
|
|
|
* replaces the ":order" placeholder. In case no ordering is required, |
419
|
|
|
* the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
420
|
|
|
* markers is removed to speed up retrieving the records. Columns of |
421
|
|
|
* sub-managers can also be used for ordering the result set but then |
422
|
|
|
* no index can be used. |
423
|
|
|
* |
424
|
|
|
* The number of returned records can be limited and can start at any |
425
|
|
|
* number between the begining and the end of the result set. For that |
426
|
|
|
* the ":size" and ":start" placeholders are replaced by the |
427
|
|
|
* corresponding values from the criteria object. The default values |
428
|
|
|
* are 0 for the start and 100 for the size value. |
429
|
|
|
* |
430
|
|
|
* The SQL statement should conform to the ANSI standard to be |
431
|
|
|
* compatible with most relational database systems. This also |
432
|
|
|
* includes using double quotes for table and column names. |
433
|
|
|
* |
434
|
|
|
* @param string SQL statement for searching items |
435
|
|
|
* @since 2014.03 |
436
|
|
|
* @category Developer |
437
|
|
|
* @see mshop/locale/manager/currency/standard/insert/ansi |
438
|
|
|
* @see mshop/locale/manager/currency/standard/update/ansi |
439
|
|
|
* @see mshop/locale/manager/currency/standard/delete/ansi |
440
|
|
|
* @see mshop/locale/manager/currency/standard/count/ansi |
441
|
|
|
*/ |
442
|
|
|
$path = 'mshop/locale/manager/currency/standard/search'; |
443
|
|
|
|
444
|
|
|
$sql = $this->getSqlConfig( $path ); |
445
|
|
|
$results = $this->getSearchResults( $conn, str_replace( $find, $replace, $sql ) ); |
446
|
|
|
|
447
|
|
|
try |
448
|
|
|
{ |
449
|
|
|
while( ( $row = $results->fetch() ) !== false ) { |
450
|
|
|
$items[$row['locale.currency.id']] = $this->createItemBase( $row ); |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
catch( \Exception $e ) |
454
|
|
|
{ |
455
|
|
|
$results->finish(); |
456
|
|
|
throw $e; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
if( $total !== null ) { |
460
|
|
|
$total = $this->getTotal( $conn, $find, $replace ); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
$dbm->release( $conn, $dbname ); |
464
|
|
|
} |
465
|
|
|
catch( \Exception $e ) |
466
|
|
|
{ |
467
|
|
|
$dbm->release( $conn, $dbname ); |
468
|
|
|
throw $e; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
return $items; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Returns a new sub manager of the given type and name. |
477
|
|
|
* |
478
|
|
|
* @param string $manager Name of the sub manager type in lower case |
479
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
480
|
|
|
* @return \Aimeos\MShop\Locale\Manager\Iface manager |
481
|
|
|
*/ |
482
|
|
|
public function getSubManager( $manager, $name = null ) |
483
|
|
|
{ |
484
|
|
|
/** mshop/locale/manager/currency/name |
485
|
|
|
* Class name of the used locale currency manager implementation |
486
|
|
|
* |
487
|
|
|
* Each default locale currency manager can be replaced by an alternative imlementation. |
488
|
|
|
* To use this implementation, you have to set the last part of the class |
489
|
|
|
* name as configuration value so the manager factory knows which class it |
490
|
|
|
* has to instantiate. |
491
|
|
|
* |
492
|
|
|
* For example, if the name of the default class is |
493
|
|
|
* |
494
|
|
|
* \Aimeos\MShop\Locale\Manager\Currency\Standard |
495
|
|
|
* |
496
|
|
|
* and you want to replace it with your own version named |
497
|
|
|
* |
498
|
|
|
* \Aimeos\MShop\Locale\Manager\Currency\Mycurrency |
499
|
|
|
* |
500
|
|
|
* then you have to set the this configuration option: |
501
|
|
|
* |
502
|
|
|
* mshop/locale/manager/currency/name = Mycurrency |
503
|
|
|
* |
504
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
505
|
|
|
* so take care that the configuration value is exactly named like the last |
506
|
|
|
* part of the class name. |
507
|
|
|
* |
508
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
509
|
|
|
* characters are possible! You should always start the last part of the class |
510
|
|
|
* name with an upper case character and continue only with lower case characters |
511
|
|
|
* or numbers. Avoid chamel case names like "MyCurrency"! |
512
|
|
|
* |
513
|
|
|
* @param string Last part of the class name |
514
|
|
|
* @since 2014.03 |
515
|
|
|
* @category Developer |
516
|
|
|
*/ |
517
|
|
|
|
518
|
|
|
/** mshop/locale/manager/currency/decorators/excludes |
519
|
|
|
* Excludes decorators added by the "common" option from the locale currency manager |
520
|
|
|
* |
521
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
522
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
523
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
524
|
|
|
* modify what is returned to the caller. |
525
|
|
|
* |
526
|
|
|
* This option allows you to remove a decorator added via |
527
|
|
|
* "mshop/common/manager/decorators/default" before they are wrapped |
528
|
|
|
* around the locale currency manager. |
529
|
|
|
* |
530
|
|
|
* mshop/locale/manager/currency/decorators/excludes = array( 'decorator1' ) |
531
|
|
|
* |
532
|
|
|
* This would remove the decorator named "decorator1" from the list of |
533
|
|
|
* common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
534
|
|
|
* "mshop/common/manager/decorators/default" for the locale currency manager. |
535
|
|
|
* |
536
|
|
|
* @param array List of decorator names |
537
|
|
|
* @since 2014.03 |
538
|
|
|
* @category Developer |
539
|
|
|
* @see mshop/common/manager/decorators/default |
540
|
|
|
* @see mshop/locale/manager/currency/decorators/global |
541
|
|
|
* @see mshop/locale/manager/currency/decorators/local |
542
|
|
|
*/ |
543
|
|
|
|
544
|
|
|
/** mshop/locale/manager/currency/decorators/global |
545
|
|
|
* Adds a list of globally available decorators only to the locale currency manager |
546
|
|
|
* |
547
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
548
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
549
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
550
|
|
|
* modify what is returned to the caller. |
551
|
|
|
* |
552
|
|
|
* This option allows you to wrap global decorators |
553
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the locale currency manager. |
554
|
|
|
* |
555
|
|
|
* mshop/locale/manager/currency/decorators/global = array( 'decorator1' ) |
556
|
|
|
* |
557
|
|
|
* This would add the decorator named "decorator1" defined by |
558
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the locale controller. |
559
|
|
|
* |
560
|
|
|
* @param array List of decorator names |
561
|
|
|
* @since 2014.03 |
562
|
|
|
* @category Developer |
563
|
|
|
* @see mshop/common/manager/decorators/default |
564
|
|
|
* @see mshop/locale/manager/currency/decorators/excludes |
565
|
|
|
* @see mshop/locale/manager/currency/decorators/local |
566
|
|
|
*/ |
567
|
|
|
|
568
|
|
|
/** mshop/locale/manager/currency/decorators/local |
569
|
|
|
* Adds a list of local decorators only to the locale currency manager |
570
|
|
|
* |
571
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
572
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
573
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
574
|
|
|
* modify what is returned to the caller. |
575
|
|
|
* |
576
|
|
|
* This option allows you to wrap local decorators |
577
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the locale currency manager. |
578
|
|
|
* |
579
|
|
|
* mshop/locale/manager/currency/decorators/local = array( 'decorator2' ) |
580
|
|
|
* |
581
|
|
|
* This would add the decorator named "decorator2" defined by |
582
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator2" only to the locale |
583
|
|
|
* controller. |
584
|
|
|
* |
585
|
|
|
* @param array List of decorator names |
586
|
|
|
* @since 2014.03 |
587
|
|
|
* @category Developer |
588
|
|
|
* @see mshop/common/manager/decorators/default |
589
|
|
|
* @see mshop/locale/manager/currency/decorators/excludes |
590
|
|
|
* @see mshop/locale/manager/currency/decorators/global |
591
|
|
|
*/ |
592
|
|
|
|
593
|
|
|
return $this->getSubManagerBase( 'locale', 'currency/' . $manager, $name ); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Returns the item specified by its code and domain/type if necessary |
599
|
|
|
* |
600
|
|
|
* @param string $code Code of the item |
601
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
602
|
|
|
* @param string|null $domain Domain of the item if necessary to identify the item uniquely |
603
|
|
|
* @param string|null $type Type code of the item if necessary to identify the item uniquely |
604
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface Item object |
605
|
|
|
*/ |
606
|
|
|
public function findItem( $code, array $ref = [], $domain = null, $type = null ) |
607
|
|
|
{ |
608
|
|
|
return $this->findItemBase( array( 'locale.currency.id' => $code ), $ref ); |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Creates a search object and sets base criteria. |
614
|
|
|
* |
615
|
|
|
* @param boolean $default |
616
|
|
|
* @return \Aimeos\MW\Criteria\Iface |
617
|
|
|
*/ |
618
|
|
|
public function createSearch( $default = false ) |
619
|
|
|
{ |
620
|
|
|
if( $default === true ) { |
621
|
|
|
return $this->createSearchBase( 'locale.currency' ); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
return parent::createSearch(); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* Returns the search results for the given SQL statement. |
630
|
|
|
* |
631
|
|
|
* @param \Aimeos\MW\DB\Connection\Iface $conn Database connection |
632
|
|
|
* @param $sql SQL statement |
633
|
|
|
* @return \Aimeos\MW\DB\Result\Iface Search result object |
634
|
|
|
*/ |
635
|
|
|
protected function getSearchResults( \Aimeos\MW\DB\Connection\Iface $conn, $sql ) |
636
|
|
|
{ |
637
|
|
|
$statement = $conn->create( $sql ); |
638
|
|
|
$this->getContext()->getLogger()->log( __METHOD__ . ': SQL statement: ' . $statement, \Aimeos\MW\Logger\Base::DEBUG ); |
639
|
|
|
|
640
|
|
|
$results = $statement->execute(); |
641
|
|
|
|
642
|
|
|
return $results; |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* Create new item object initialized with given parameters. |
648
|
|
|
* |
649
|
|
|
* @param array $data Associative list of item key/value pairs |
650
|
|
|
* @return \Aimeos\MShop\Locale\Item\Currency\Iface Currency item object |
651
|
|
|
*/ |
652
|
|
|
protected function createItemBase( array $data = [] ) |
653
|
|
|
{ |
654
|
|
|
return new \Aimeos\MShop\Locale\Item\Currency\Standard( $data ); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* Returns the total number of items found for the conditions |
660
|
|
|
* |
661
|
|
|
* @param \Aimeos\MW\DB\Connection\Iface $conn Database connection |
662
|
|
|
* @param array $find List of markers that should be replaced in the SQL statement |
663
|
|
|
* @param array $replace List of replacements for the markers in the SQL statement |
664
|
|
|
* @throws \Aimeos\MShop\Locale\Exception If no total value was found |
665
|
|
|
* @return integer Total number of found items |
666
|
|
|
*/ |
667
|
|
|
protected function getTotal( \Aimeos\MW\DB\Connection\Iface $conn, array $find, array $replace ) |
668
|
|
|
{ |
669
|
|
|
/** mshop/locale/manager/currency/standard/count/mysql |
670
|
|
|
* Counts the number of records matched by the given criteria in the database |
671
|
|
|
* |
672
|
|
|
* @see mshop/locale/manager/currency/standard/count/ansi |
673
|
|
|
*/ |
674
|
|
|
|
675
|
|
|
/** mshop/locale/manager/currency/standard/count/ansi |
676
|
|
|
* Counts the number of records matched by the given criteria in the database |
677
|
|
|
* |
678
|
|
|
* Counts all records matched by the given criteria from the attribute |
679
|
|
|
* database. The records must be from one of the sites that are |
680
|
|
|
* configured via the context item. If the current site is part of |
681
|
|
|
* a tree of sites, the statement can count all records from the |
682
|
|
|
* current site and the complete sub-tree of sites. |
683
|
|
|
* |
684
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
685
|
|
|
* their tables must be joined in the SQL context. This is done by |
686
|
|
|
* using the "internaldeps" property from the definition of the ID |
687
|
|
|
* column of the sub-managers. These internal dependencies specify |
688
|
|
|
* the JOIN between the tables and the used columns for joining. The |
689
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
690
|
|
|
* the sub-managers. |
691
|
|
|
* |
692
|
|
|
* To limit the records matched, conditions can be added to the given |
693
|
|
|
* criteria object. It can contain comparisons like column names that |
694
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
695
|
|
|
* operators. The resulting string of SQL conditions replaces the |
696
|
|
|
* ":cond" placeholder before the statement is sent to the database |
697
|
|
|
* server. |
698
|
|
|
* |
699
|
|
|
* Both, the strings for ":joins" and for ":cond" are the same as for |
700
|
|
|
* the "search" SQL statement. |
701
|
|
|
* |
702
|
|
|
* Contrary to the "search" statement, it doesn't return any records |
703
|
|
|
* but instead the number of records that have been found. As counting |
704
|
|
|
* thousands of records can be a long running task, the maximum number |
705
|
|
|
* of counted records is limited for performance reasons. |
706
|
|
|
* |
707
|
|
|
* The SQL statement should conform to the ANSI standard to be |
708
|
|
|
* compatible with most relational database systems. This also |
709
|
|
|
* includes using double quotes for table and column names. |
710
|
|
|
* |
711
|
|
|
* @param string SQL statement for counting items |
712
|
|
|
* @since 2014.03 |
713
|
|
|
* @category Developer |
714
|
|
|
* @see mshop/locale/manager/currency/standard/insert/ansi |
715
|
|
|
* @see mshop/locale/manager/currency/standard/update/ansi |
716
|
|
|
* @see mshop/locale/manager/currency/standard/delete/ansi |
717
|
|
|
* @see mshop/locale/manager/currency/standard/search/ansi |
718
|
|
|
*/ |
719
|
|
|
$path = 'mshop/locale/manager/currency/standard/count'; |
720
|
|
|
|
721
|
|
|
$sql = $this->getSqlConfig( $path ); |
722
|
|
|
$results = $this->getSearchResults( $conn, str_replace( $find, $replace, $sql ) ); |
723
|
|
|
|
724
|
|
|
$row = $results->fetch(); |
725
|
|
|
$results->finish(); |
726
|
|
|
|
727
|
|
|
if( $row === false ) { |
728
|
|
|
throw new \Aimeos\MShop\Locale\Exception( 'No total results value found' ); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
return $row['count']; |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
|