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