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