PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.27
Booking for Appointments and Events Calendar – Amelia v1.2.27
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Domain / Factory / Bookable / Service / ServiceFactory.php
ameliabooking / src / Domain / Factory / Bookable / Service Last commit date
CategoryFactory.php 2 years ago ExtraFactory.php 2 years ago PackageCustomerFactory.php 1 year ago PackageCustomerServiceFactory.php 1 year ago PackageFactory.php 1 year ago PackageServiceFactory.php 1 year ago ResourceFactory.php 1 year ago ServiceFactory.php 1 year ago
ServiceFactory.php
335 lines
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Domain\Factory\Bookable\Service;
9
10 use AmeliaBooking\Domain\Collection\Collection;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
13 use AmeliaBooking\Domain\Entity\Entities;
14 use AmeliaBooking\Domain\Entity\Gallery\GalleryImage;
15 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
16 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
17 use AmeliaBooking\Domain\ValueObjects\Duration;
18 use AmeliaBooking\Domain\ValueObjects\Json;
19 use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger;
20 use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber;
21 use AmeliaBooking\Domain\ValueObjects\Picture;
22 use AmeliaBooking\Domain\ValueObjects\PositiveDuration;
23 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
24 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
25 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
26 use AmeliaBooking\Domain\ValueObjects\String\Cycle;
27 use AmeliaBooking\Domain\ValueObjects\String\DepositType;
28 use AmeliaBooking\Domain\ValueObjects\String\EntityType;
29 use AmeliaBooking\Domain\ValueObjects\String\Status;
30 use AmeliaBooking\Domain\ValueObjects\Priority;
31 use AmeliaBooking\Domain\ValueObjects\String\Color;
32 use AmeliaBooking\Domain\ValueObjects\String\Description;
33 use AmeliaBooking\Domain\ValueObjects\String\Name;
34 use AmeliaBooking\Infrastructure\Licence;
35
36 /**
37 * Class ServiceFactory
38 *
39 * @package AmeliaBooking\Domain\Factory\Bookable\Service
40 */
41 class ServiceFactory
42 {
43 /**
44 * @param $data
45 *
46 * @return Service
47 * @throws InvalidArgumentException
48 */
49 public static function create($data)
50 {
51 Licence\DataModifier::serviceFactory($data);
52
53 $service = new Service();
54
55 if (isset($data['id'])) {
56 $service->setId(new Id($data['id']));
57 }
58
59 if (isset($data['name'])) {
60 $service->setName(new Name($data['name']));
61 }
62
63 if (isset($data['price'])) {
64 $service->setPrice(new Price($data['price']));
65 }
66
67 if (isset($data['status'])) {
68 $service->setStatus(new Status($data['status']));
69 }
70
71 if (isset($data['categoryId'])) {
72 $service->setCategoryId(new Id($data['categoryId']));
73 }
74
75 if (isset($data['minCapacity'])) {
76 $service->setMinCapacity(new IntegerValue($data['minCapacity']));
77 }
78
79 if (isset($data['maxCapacity'])) {
80 $service->setMaxCapacity(new IntegerValue($data['maxCapacity']));
81 }
82
83 if (isset($data['duration'])) {
84 $service->setDuration(new PositiveDuration($data['duration']));
85 }
86
87 if (isset($data['description'])) {
88 $service->setDescription(new Description($data['description']));
89 }
90
91 if (isset($data['color'])) {
92 $service->setColor(new Color($data['color']));
93 }
94
95 if (!empty($data['timeBefore'])) {
96 $service->setTimeBefore(new Duration($data['timeBefore']));
97 }
98
99 if (!empty($data['timeAfter'])) {
100 $service->setTimeAfter(new Duration($data['timeAfter']));
101 }
102
103 if (isset($data['bringingAnyone'])) {
104 $service->setBringingAnyone(new BooleanValueObject($data['bringingAnyone']));
105 }
106
107 if (isset($data['aggregatedPrice'])) {
108 $service->setAggregatedPrice(new BooleanValueObject($data['aggregatedPrice']));
109 }
110
111 if (!empty($data['priority'])) {
112 $service->setPriority(new Priority($data['priority']));
113 }
114
115 if (!empty($data['pictureFullPath']) && !empty($data['pictureThumbPath'])) {
116 $service->setPicture(new Picture($data['pictureFullPath'], $data['pictureThumbPath']));
117 }
118
119 if (!empty($data['position'])) {
120 $service->setPosition(new PositiveInteger($data['position']));
121 }
122
123 if (isset($data['show'])) {
124 $service->setShow(new BooleanValueObject($data['show']));
125 }
126
127 if (!empty($data['settings'])) {
128 $service->setSettings(new Json($data['settings']));
129 }
130
131 if (!empty($data['recurringCycle'])) {
132 $service->setRecurringCycle(new Cycle($data['recurringCycle']));
133 }
134
135 if (!empty($data['recurringSub'])) {
136 $service->setRecurringSub(new Name($data['recurringSub']));
137 }
138
139 if (isset($data['recurringPayment'])) {
140 $service->setRecurringPayment(new WholeNumber($data['recurringPayment']));
141 } else {
142 $service->setRecurringPayment(new WholeNumber(0));
143 }
144
145 if (isset($data['translations'])) {
146 $service->setTranslations(new Json($data['translations']));
147 }
148
149 if (!empty($data['customPricing'])) {
150 $service->setCustomPricing(new Json($data['customPricing']));
151 }
152
153 if (isset($data['limitPerCustomer'])) {
154 $service->setLimitPerCustomer(new Json($data['limitPerCustomer']));
155 }
156
157 if (isset($data['deposit'])) {
158 $service->setDeposit(new Price($data['deposit']));
159 }
160
161 if (isset($data['depositPayment'])) {
162 $service->setDepositPayment(new DepositType($data['depositPayment']));
163 }
164
165 if (isset($data['depositPerPerson'])) {
166 $service->setDepositPerPerson(new BooleanValueObject($data['depositPerPerson']));
167 }
168
169 if (isset($data['mandatoryExtra'])) {
170 $service->setMandatoryExtra(new BooleanValueObject($data['mandatoryExtra']));
171 }
172
173 if (!empty($data['minSelectedExtras'])) {
174 $service->setMinSelectedExtras(new IntegerValue($data['minSelectedExtras']));
175 }
176
177 if (isset($data['fullPayment'])) {
178 $service->setFullPayment(new BooleanValueObject($data['fullPayment']));
179 }
180
181 $gallery = new Collection();
182
183 if (!empty($data['gallery'])) {
184 foreach ((array)$data['gallery'] as $image) {
185 $galleryImage = new GalleryImage(
186 new EntityType(Entities::SERVICE),
187 new Picture($image['pictureFullPath'], $image['pictureThumbPath']),
188 new PositiveInteger($image['position'])
189 );
190
191 if (!empty($image['id'])) {
192 $galleryImage->setId(new Id($image['id']));
193 }
194
195 if ($service->getId()) {
196 $galleryImage->setEntityId($service->getId());
197 }
198
199 $gallery->addItem($galleryImage);
200 }
201 }
202
203 $service->setGallery($gallery);
204
205 $extras = new Collection();
206 if (!empty($data['extras'])) {
207 /** @var array $extrasList */
208 $extrasList = $data['extras'];
209 foreach ($extrasList as $extraKey => $extra) {
210 $extras->addItem(ExtraFactory::create($extra), $extraKey);
211 }
212 }
213 $service->setExtras($extras);
214
215 $coupons = new Collection();
216 if (!empty($data['coupons'])) {
217 /** @var array $couponsList */
218 $couponsList = $data['coupons'];
219 foreach ($couponsList as $couponKey => $coupon) {
220 $coupons->addItem(CouponFactory::create($coupon), $couponKey);
221 }
222 }
223 $service->setCoupons($coupons);
224
225 if (isset($data['maxExtraPeople'])) {
226 $service->setMaxExtraPeople(new IntegerValue($data['maxExtraPeople']));
227 }
228
229 return $service;
230 }
231
232 /**
233 * @param array $rows
234 *
235 * @return Collection
236 * @throws InvalidArgumentException
237 */
238 public static function createCollection($rows)
239 {
240 $services = [];
241
242 foreach ($rows as $row) {
243 $serviceId = $row['service_id'];
244 $extraId = $row['extra_id'];
245 $galleryId = isset($row['gallery_id']) ? $row['gallery_id'] : null;
246
247 $services[$serviceId]['id'] = $row['service_id'];
248 $services[$serviceId]['name'] = $row['service_name'];
249 $services[$serviceId]['description'] = $row['service_description'];
250 $services[$serviceId]['color'] = $row['service_color'];
251 $services[$serviceId]['price'] = $row['service_price'];
252 $services[$serviceId]['status'] = $row['service_status'];
253 $services[$serviceId]['categoryId'] = $row['service_categoryId'];
254 $services[$serviceId]['minCapacity'] = $row['service_minCapacity'];
255 $services[$serviceId]['maxCapacity'] = $row['service_maxCapacity'];
256 $services[$serviceId]['maxExtraPeople'] = isset($row['service_maxExtraPeople'])
257 ? $row['service_maxExtraPeople'] : null;
258 $services[$serviceId]['duration'] = $row['service_duration'];
259 $services[$serviceId]['timeAfter'] = $row['service_timeAfter'];
260 $services[$serviceId]['timeBefore'] = $row['service_timeBefore'];
261 $services[$serviceId]['bringingAnyone'] = $row['service_bringingAnyone'];
262 $services[$serviceId]['pictureFullPath'] = $row['service_picture_full'];
263 $services[$serviceId]['pictureThumbPath'] = $row['service_picture_thumb'];
264 $services[$serviceId]['position'] = isset($row['service_position']) ? $row['service_position'] : 0;
265 $services[$serviceId]['show'] = isset($row['service_show']) ? $row['service_show'] : 0;
266 $services[$serviceId]['aggregatedPrice'] = isset($row['service_aggregatedPrice']) ?
267 $row['service_aggregatedPrice'] : 0;
268 $services[$serviceId]['settings'] = isset($row['service_settings']) ?
269 $row['service_settings'] : null;
270 $services[$serviceId]['recurringCycle'] = isset($row['service_recurringCycle']) ?
271 $row['service_recurringCycle'] : null;
272 $services[$serviceId]['recurringSub'] = isset($row['service_recurringSub']) ?
273 $row['service_recurringSub'] : null;
274 $services[$serviceId]['recurringPayment'] = isset($row['service_recurringPayment']) ?
275 $row['service_recurringPayment'] : null;
276 $services[$serviceId]['translations'] = isset($row['service_translations']) ?
277 $row['service_translations'] : null;
278 $services[$serviceId]['customPricing'] = isset($row['service_customPricing']) ?
279 $row['service_customPricing'] : null;
280 $services[$serviceId]['limitPerCustomer'] = isset($row['service_limitPerCustomer']) ?
281 $row['service_limitPerCustomer'] : null;
282 $services[$serviceId]['deposit'] = isset($row['service_deposit']) ? $row['service_deposit'] : 0;
283 $services[$serviceId]['depositPayment'] = isset($row['service_depositPayment']) ?
284 $row['service_depositPayment'] : 'disabled';
285 $services[$serviceId]['depositPerPerson'] = isset($row['service_depositPerPerson']) ?
286 $row['service_depositPerPerson'] : 1;
287 $services[$serviceId]['mandatoryExtra'] = isset($row['service_mandatoryExtra']) ?
288 $row['service_mandatoryExtra'] : null;
289 $services[$serviceId]['minSelectedExtras'] = isset($row['service_minSelectedExtras']) ?
290 $row['service_minSelectedExtras'] : null;
291 $services[$serviceId]['fullPayment'] = isset($row['service_fullPayment']) ?
292 $row['service_fullPayment'] : null;
293
294 if ($extraId) {
295 $services[$serviceId]['extras'][$extraId]['id'] = $row['extra_id'];
296 $services[$serviceId]['extras'][$extraId]['name'] = $row['extra_name'];
297 $services[$serviceId]['extras'][$extraId]['description'] = isset($row['extra_description']) ?
298 $row['extra_description'] : null;
299 $services[$serviceId]['extras'][$extraId]['price'] = $row['extra_price'];
300 $services[$serviceId]['extras'][$extraId]['maxQuantity'] = $row['extra_maxQuantity'];
301 $services[$serviceId]['extras'][$extraId]['duration'] = $row['extra_duration'];
302 $services[$serviceId]['extras'][$extraId]['position'] = $row['extra_position'];
303 $services[$serviceId]['extras'][$extraId]['aggregatedPrice'] = $row['extra_aggregatedPrice'];
304 $services[$serviceId]['extras'][$extraId]['translations'] = $row['extra_translations'];
305 }
306
307 if ($galleryId) {
308 $services[$serviceId]['gallery'][$galleryId]['id'] = $row['gallery_id'];
309 $services[$serviceId]['gallery'][$galleryId]['pictureFullPath'] = $row['gallery_picture_full'];
310 $services[$serviceId]['gallery'][$galleryId]['pictureThumbPath'] = $row['gallery_picture_thumb'];
311 $services[$serviceId]['gallery'][$galleryId]['position'] = $row['gallery_position'];
312 }
313 }
314
315 $servicesCollection = new Collection();
316
317 foreach ($services as $serviceKey => $serviceArray) {
318 if (!array_key_exists('extras', $serviceArray)) {
319 $serviceArray['extras'] = [];
320 }
321
322 if (!array_key_exists('gallery', $serviceArray)) {
323 $serviceArray['gallery'] = [];
324 }
325
326 $servicesCollection->addItem(
327 self::create($serviceArray),
328 $serviceKey
329 );
330 }
331
332 return $servicesCollection;
333 }
334 }
335