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 / PackageFactory.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
PackageFactory.php
289 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\Package;
12 use AmeliaBooking\Domain\Entity\Entities;
13 use AmeliaBooking\Domain\Entity\Gallery\GalleryImage;
14 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
15 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
16 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
17 use AmeliaBooking\Domain\ValueObjects\DiscountPercentageValue;
18 use AmeliaBooking\Domain\ValueObjects\Json;
19 use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger;
20 use AmeliaBooking\Domain\ValueObjects\Picture;
21 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
22 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
23 use AmeliaBooking\Domain\ValueObjects\String\DepositType;
24 use AmeliaBooking\Domain\ValueObjects\String\EntityType;
25 use AmeliaBooking\Domain\ValueObjects\String\Color;
26 use AmeliaBooking\Domain\ValueObjects\String\Description;
27 use AmeliaBooking\Domain\ValueObjects\String\Label;
28 use AmeliaBooking\Domain\ValueObjects\String\Name;
29 use AmeliaBooking\Domain\ValueObjects\String\Status;
30
31 /**
32 * Class PackageFactory
33 *
34 * @package AmeliaBooking\Domain\Factory\Bookable\Service
35 */
36 class PackageFactory
37 {
38 /**
39 * @param $data
40 *
41 * @return Package
42 * @throws InvalidArgumentException
43 */
44 public static function create($data)
45 {
46 /** @var Package $package */
47 $package = new Package();
48
49 if (isset($data['id'])) {
50 $package->setId(new Id($data['id']));
51 }
52
53 if (isset($data['name'])) {
54 $package->setName(new Name($data['name']));
55 }
56
57 if (isset($data['price'])) {
58 $package->setPrice(new Price($data['price']));
59 }
60
61 if (isset($data['description'])) {
62 $package->setDescription(new Description($data['description']));
63 }
64
65 if (isset($data['color'])) {
66 $package->setColor(new Color($data['color']));
67 }
68
69 if (!empty($data['pictureFullPath']) && !empty($data['pictureThumbPath'])) {
70 $package->setPicture(new Picture($data['pictureFullPath'], $data['pictureThumbPath']));
71 }
72
73 if (!empty($data['position'])) {
74 $package->setPosition(new PositiveInteger($data['position']));
75 }
76
77 if (!empty($data['status'])) {
78 $package->setStatus(new Status($data['status']));
79 }
80
81 if (isset($data['calculatedPrice'])) {
82 $package->setCalculatedPrice(new BooleanValueObject($data['calculatedPrice']));
83 }
84
85 if (isset($data['discount'])) {
86 $package->setDiscount(new DiscountPercentageValue($data['discount']));
87 }
88
89 if (!empty($data['settings'])) {
90 $package->setSettings(new Json($data['settings']));
91 }
92
93 if (!empty($data['endDate'])) {
94 $package->setEndDate(
95 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['endDate']))
96 );
97 }
98
99 if (!empty($data['durationCount'])) {
100 $package->setDurationCount(new PositiveInteger($data['durationCount']));
101 }
102
103 if (!empty($data['durationType'])) {
104 $package->setDurationType(new Label($data['durationType']));
105 }
106
107 if (isset($data['deposit'])) {
108 $package->setDeposit(new Price($data['deposit']));
109 }
110
111 if (isset($data['depositPayment'])) {
112 $package->setDepositPayment(new DepositType($data['depositPayment']));
113 }
114
115 if (isset($data['fullPayment'])) {
116 $package->setFullPayment(new BooleanValueObject($data['fullPayment']));
117 }
118
119 if (isset($data['limitPerCustomer'])) {
120 $package->setLimitPerCustomer(new Json($data['limitPerCustomer']));
121 }
122
123 /** @var Collection $gallery */
124 $gallery = new Collection();
125
126 if (!empty($data['gallery'])) {
127 foreach ((array)$data['gallery'] as $image) {
128 $galleryImage = new GalleryImage(
129 new EntityType(Entities::PACKAGE),
130 new Picture($image['pictureFullPath'], $image['pictureThumbPath']),
131 new PositiveInteger($image['position'])
132 );
133
134 if (!empty($image['id'])) {
135 $galleryImage->setId(new Id($image['id']));
136 }
137
138 if ($package->getId()) {
139 $galleryImage->setEntityId($package->getId());
140 }
141
142 $gallery->addItem($galleryImage);
143 }
144 }
145
146 $package->setGallery($gallery);
147
148 if (!empty($data['translations'])) {
149 $package->setTranslations(new Json($data['translations']));
150 }
151
152 if (isset($data['sharedCapacity'])) {
153 $package->setSharedCapacity(new BooleanValueObject($data['sharedCapacity']));
154 }
155
156 if (isset($data['quantity'])) {
157 $package->setQuantity(new PositiveInteger($data['quantity']));
158 }
159
160 /** @var Collection $bookable */
161 $bookable = new Collection();
162
163 if (!empty($data['bookable'])) {
164 foreach ($data['bookable'] as $key => $value) {
165 $bookable->addItem(PackageServiceFactory::create($value), $key);
166 }
167 }
168
169 $package->setBookable($bookable);
170
171 return $package;
172 }
173
174 /**
175 * @param array $rows
176 *
177 * @return Collection
178 * @throws InvalidArgumentException
179 */
180 public static function createCollection($rows)
181 {
182 $packages = [];
183
184 foreach ($rows as $row) {
185 $packageId = $row['package_id'];
186 $bookableId = $row['package_service_id'];
187 $galleryId = isset($row['gallery_id']) ? $row['gallery_id'] : null;
188 $providerId = isset($row['provider_id']) ? $row['provider_id'] : null;
189 $locationId = isset($row['location_id']) ? $row['location_id'] : null;
190
191 $packages[$packageId]['id'] = $row['package_id'];
192 $packages[$packageId]['name'] = $row['package_name'];
193 $packages[$packageId]['description'] = $row['package_description'];
194 $packages[$packageId]['color'] = $row['package_color'];
195 $packages[$packageId]['price'] = $row['package_price'];
196 $packages[$packageId]['status'] = $row['package_status'];
197 $packages[$packageId]['pictureFullPath'] = $row['package_picture_full'];
198 $packages[$packageId]['pictureThumbPath'] = $row['package_picture_thumb'];
199 $packages[$packageId]['position'] = isset($row['package_position']) ? $row['package_position'] : 0;
200 $packages[$packageId]['calculatedPrice'] = $row['package_calculated_price'];
201 $packages[$packageId]['sharedCapacity'] = isset($row['package_sharedCapacity']) ?
202 $row['package_sharedCapacity'] : null;
203 $packages[$packageId]['quantity'] = isset($row['package_quantity']) ?
204 $row['package_quantity'] : null;
205 $packages[$packageId]['discount'] = $row['package_discount'];
206 $packages[$packageId]['settings'] = $row['package_settings'];
207 $packages[$packageId]['endDate'] = $row['package_endDate'];
208 $packages[$packageId]['durationCount'] = $row['package_durationCount'];
209 $packages[$packageId]['durationType'] = $row['package_durationType'];
210 $packages[$packageId]['translations'] = $row['package_translations'];
211 $packages[$packageId]['deposit'] = isset($row['package_deposit']) ? $row['package_deposit'] : null;
212 $packages[$packageId]['depositPayment'] = isset($row['package_depositPayment']) ?
213 $row['package_depositPayment'] : null;
214 $packages[$packageId]['fullPayment'] = isset($row['package_fullPayment']) ?
215 $row['package_fullPayment'] : 0;
216 $packages[$packageId]['limitPerCustomer'] = isset($row['package_limitPerCustomer']) ?
217 $row['package_limitPerCustomer'] : null;
218
219 if ($bookableId) {
220 $packages[$packageId]['bookable'][$bookableId]['id'] = $bookableId;
221 $packages[$packageId]['bookable'][$bookableId]['service']['id'] = $row['service_id'];
222 $packages[$packageId]['bookable'][$bookableId]['service']['name'] = $row['service_name'];
223 $packages[$packageId]['bookable'][$bookableId]['service']['description'] = !empty($row['service_description']) ? $row['service_description'] : null;
224 $packages[$packageId]['bookable'][$bookableId]['service']['status'] = $row['service_status'];
225 $packages[$packageId]['bookable'][$bookableId]['service']['categoryId'] = $row['service_categoryId'];
226 $packages[$packageId]['bookable'][$bookableId]['service']['duration'] = $row['service_duration'];
227 $packages[$packageId]['bookable'][$bookableId]['service']['timeBefore'] = $row['service_timeBefore'];
228 $packages[$packageId]['bookable'][$bookableId]['service']['timeAfter'] = $row['service_timeAfter'];
229 $packages[$packageId]['bookable'][$bookableId]['service']['price'] = $row['service_price'];
230 $packages[$packageId]['bookable'][$bookableId]['service']['minCapacity'] = $row['service_minCapacity'];
231 $packages[$packageId]['bookable'][$bookableId]['service']['maxCapacity'] = $row['service_maxCapacity'];
232 $packages[$packageId]['bookable'][$bookableId]['service']['pictureFullPath'] = $row['service_picture_full'];
233 $packages[$packageId]['bookable'][$bookableId]['service']['pictureThumbPath'] = $row['service_picture_thumb'];
234 $packages[$packageId]['bookable'][$bookableId]['service']['translations'] = !empty($row['service_translations']) ? $row['service_translations'] : null;
235 $packages[$packageId]['bookable'][$bookableId]['quantity'] = $row['package_service_quantity'];
236 $packages[$packageId]['bookable'][$bookableId]['minimumScheduled'] = $row['package_service_minimumScheduled'];
237 $packages[$packageId]['bookable'][$bookableId]['maximumScheduled'] = $row['package_service_maximumScheduled'];
238 $packages[$packageId]['bookable'][$bookableId]['allowProviderSelection'] = $row['package_service_allowProviderSelection'];
239 $packages[$packageId]['bookable'][$bookableId]['position'] = $row['package_service_position'];
240 $packages[$packageId]['bookable'][$bookableId]['service']['show'] = !empty($row['service_show']) ? $row['service_show'] : null;
241 }
242
243 if ($galleryId) {
244 $packages[$packageId]['gallery'][$galleryId]['id'] = $row['gallery_id'];
245 $packages[$packageId]['gallery'][$galleryId]['pictureFullPath'] = $row['gallery_picture_full'];
246 $packages[$packageId]['gallery'][$galleryId]['pictureThumbPath'] = $row['gallery_picture_thumb'];
247 $packages[$packageId]['gallery'][$galleryId]['position'] = $row['gallery_position'];
248 }
249
250 if ($providerId) {
251 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['id'] = $row['provider_id'];
252 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['firstName'] = $row['provider_firstName'];
253 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['lastName'] = $row['provider_lastName'];
254 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['email'] = $row['provider_email'];
255 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['status'] = !empty($row['provider_status']) ? $row['provider_status'] : Status::VISIBLE;
256 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['type'] = Entities::PROVIDER;
257 $packages[$packageId]['bookable'][$bookableId]['providers'][$providerId]['stripeConnect'] =
258 !empty($row['provider_stripeConnect'])
259 ? json_decode($row['provider_stripeConnect'], true)
260 : null;
261 }
262
263 if ($locationId) {
264 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['id'] = $row['location_id'];
265 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['name'] = $row['location_name'];
266 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['address'] = $row['location_address'];
267 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['phone'] = $row['location_phone'];
268 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['latitude'] = $row['location_latitude'];
269 $packages[$packageId]['bookable'][$bookableId]['locations'][$locationId]['longitude'] = $row['location_longitude'];
270 }
271 }
272
273 $packagesCollection = new Collection();
274
275 foreach ($packages as $packageKey => $packageArray) {
276 if (!array_key_exists('gallery', $packageArray)) {
277 $packageArray['gallery'] = [];
278 }
279
280 $packagesCollection->addItem(
281 self::create($packageArray),
282 $packageKey
283 );
284 }
285
286 return $packagesCollection;
287 }
288 }
289