1 <?php
2
3 /* --------------------------------------------------------------
4 OrderItemAttributeRepository.inc.php 2015-11-10
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 /**
14 * Class OrderItemAttributeRepository
15 *
16 * @category System
17 * @package Order
18 * @subpackage Repositories
19 */
20 class OrderItemAttributeRepository implements OrderItemAttributeRepositoryInterface
21 {
22 /**
23 * Order item attribute repository writer.
24 * @var OrderItemAttributeRepositoryWriterInterface
25 */
26 protected $writer;
27
28 /**
29 * Order item attribute repository reader.
30 * @var OrderItemAttributeRepositoryReaderInterface
31 */
32 protected $reader;
33
34 /**
35 * Order item attribute repository deleter.
36 * @var OrderItemAttributeRepositoryDeleterInterface
37 */
38 protected $deleter;
39
40
41 /**
42 * OrderItemAttributeRepository constructor.
43 *
44 * @param OrderItemAttributeRepositoryReaderInterface $reader Order item attribute repository reader.
45 * @param OrderItemAttributeRepositoryWriterInterface $writer Order item attribute repository writer.
46 * @param OrderItemAttributeRepositoryDeleterInterface $deleter Order item attribute repository deleter.
47 */
48 public function __construct(OrderItemAttributeRepositoryReaderInterface $reader,
49 OrderItemAttributeRepositoryWriterInterface $writer,
50 OrderItemAttributeRepositoryDeleterInterface $deleter)
51 {
52 $this->writer = $writer;
53 $this->reader = $reader;
54 $this->deleter = $deleter;
55 }
56
57
58 /**
59 * Adds an attribute to an order item.
60 *
61 * @param IdType $orderItemId ID of the order item.
62 * @param OrderItemAttributeInterface $orderItemAttribute Order item attribute to add.
63 *
64 * @return int ID of stored order item attribute.
65 */
66 public function addToOrderItem(IdType $orderItemId, OrderItemAttributeInterface $orderItemAttribute)
67 {
68 return $this->writer->insertIntoOrderItem($orderItemId, $orderItemAttribute);
69 }
70
71
72 /**
73 * Saves the attribute to the repository.
74 *
75 * @param StoredOrderItemAttributeInterface $orderItemAttribute Attribute to save.
76 *
77 * @return OrderItemAttributeRepositoryInterface Same instance for method chaining.
78 */
79 public function store(StoredOrderItemAttributeInterface $orderItemAttribute)
80 {
81 $this->writer->update($orderItemAttribute);
82
83 return $this;
84 }
85
86
87 /**
88 * Returns a stored attribute by the given ID.
89 *
90 * @param IdType $orderItemAttributeId ID of item attribute.
91 *
92 * @return StoredOrderItemAttributeInterface Stored attribute.
93 */
94 public function getItemAttributeById(IdType $orderItemAttributeId)
95 {
96 return $this->reader->getAttributeById($orderItemAttributeId);
97 }
98
99
100 /**
101 * Returns a stored attribute collection by the given order item ID.
102 *
103 * @param IdType $orderItemId ID of order item.
104 *
105 * @return StoredOrderItemAttributeCollection Stored item attribute collection.
106 */
107 public function getItemAttributesByOrderItemId(IdType $orderItemId)
108 {
109 return $this->reader->getAttributesByOrderItemId($orderItemId);
110 }
111
112
113 /**
114 * Deletes an item attribute by the given item attribute ID.
115 *
116 * @param IdType $orderItemAttributeId ID of order item attribute.
117 *
118 * @return OrderItemAttributeRepository Same instance for method chaining.
119 */
120 public function deleteItemAttributeById(IdType $orderItemAttributeId)
121 {
122 $this->deleter->deleteAttributeById($orderItemAttributeId);
123
124 return $this;
125 }
126
127
128 /**
129 * Deletes an item attribute by the given order item ID.
130 *
131 * @param IdType $orderItemId ID of order item.
132 *
133 * @return OrderItemAttributeRepository Same instance for method chaining.
134 */
135 public function deleteItemAttributesByOrderItemId(IdType $orderItemId)
136 {
137 $this->deleter->deleteAttributesByOrderItemId($orderItemId);
138
139 return $this;
140 }
141 }