1 <?php
2
3 /* --------------------------------------------------------------
4 AddonValueService.inc.php 2015-11-20 gm
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 MainFactory::load_class('AddonValueServiceInterface');
14
15 /**
16 * Class AddonValueService
17 *
18 * This service will handle the addon values for different contexts of the shop. The addon values is
19 * a mechanism for external developers to introduce values to key-entities of the project (e.g. order,
20 * product etc.) without further changing the database structure. Take a look at the "Storages" directory
21 * for the available storage classes. More classes will be created gradually.
22 *
23 * @category System
24 * @package AddonValue
25 */
26 class AddonValueService implements AddonValueServiceInterface
27 {
28 /**
29 * @var AddonValueStorageFactory
30 */
31 protected $addonValueStorageFactory;
32
33
34 /**
35 * AddonValueService Constructor
36 *
37 * @param AddonValueStorageFactoryInterface $addonValueStorageFactory
38 */
39 public function __construct(AddonValueStorageFactoryInterface $addonValueStorageFactory)
40 {
41 $this->addonValueStorageFactory = $addonValueStorageFactory;
42 }
43
44
45 /**
46 * Save the addon values of a storage container in the database.
47 *
48 * @param AddonValueContainerInterface $container
49 *
50 * @return AddonValueService Returns the class instance.
51 */
52 public function storeAddonValues(AddonValueContainerInterface $container)
53 {
54 $addonValueStorage = $this->addonValueStorageFactory->createAddonValueStorageByContainerObject($container);
55 $addonValueStorage->setValues(new IdType($container->getAddonValueContainerId()), $container->getAddonValues());
56
57 return $this;
58 }
59
60
61 /**
62 * Load the addon values of a storage container from the database.
63 *
64 * @param AddonValueContainerInterface $container
65 *
66 * @return AddonValueService Returns the class instance.
67 */
68 public function loadAddonValues(AddonValueContainerInterface $container)
69 {
70 $addonValueStorage = $this->addonValueStorageFactory->createAddonValueStorageByContainerObject($container);
71 $containerValues = $addonValueStorage->getValuesByContainerId(new IdType($container->getAddonValueContainerId()));
72 $container->addAddonValues($containerValues);
73
74 return $this;
75 }
76
77
78 /**
79 * Remove the addon values of a storage container.
80 *
81 * @param AddonValueContainerInterface $container
82 *
83 * @return AddonValueService Returns the class instance.
84 */
85 public function deleteAddonValues(AddonValueContainerInterface $container)
86 {
87 $addonValueStorage = $this->addonValueStorageFactory->createAddonValueStorageByContainerObject($container);
88 $addonValueStorage->deleteValuesByContainerId(new IdType($container->getAddonValueContainerId()));
89
90 return $this;
91 }
92 }