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 / PackageCustomerFactory.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
PackageCustomerFactory.php
120 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\PackageCustomer;
13 use AmeliaBooking\Domain\Factory\Coupon\CouponFactory;
14 use AmeliaBooking\Domain\Factory\Payment\PaymentFactory;
15 use AmeliaBooking\Domain\Factory\User\UserFactory;
16 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
17 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
18 use AmeliaBooking\Domain\ValueObjects\Json;
19 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
20 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
21 use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber;
22 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
23
24 /**
25 * Class PackageCustomerFactory
26 *
27 * @package AmeliaBooking\Domain\Factory\Bookable\Service
28 */
29 class PackageCustomerFactory
30 {
31 /**
32 * @param $data
33 *
34 * @return PackageCustomer
35 * @throws InvalidArgumentException
36 */
37 public static function create($data)
38 {
39 /** @var PackageCustomer $packageCustomer */
40 $packageCustomer = new PackageCustomer();
41
42 if (isset($data['id'])) {
43 $packageCustomer->setId(new Id($data['id']));
44 }
45
46 if (isset($data['packageId'])) {
47 $packageCustomer->setPackageId(new Id($data['packageId']));
48 }
49
50 if (isset($data['customerId'])) {
51 $packageCustomer->setCustomerId(new Id($data['customerId']));
52 }
53
54 if (isset($data['customer'])) {
55 $packageCustomer->setCustomer(UserFactory::create($data['customer']));
56 }
57
58 if (isset($data['price'])) {
59 $packageCustomer->setPrice(new Price($data['price']));
60 }
61
62 $payments = new Collection();
63 if (!empty($data['payments'])) {
64 /** @var array $paymentsList */
65 $paymentsList = $data['payments'];
66 foreach ($paymentsList as $paymentKey => $payment) {
67 $payments->addItem(PaymentFactory::create($payment), $paymentKey);
68 }
69 }
70 $packageCustomer->setPayments($payments);
71
72
73 if (!empty($data['end'])) {
74 $packageCustomer->setEnd(
75 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['end']))
76 );
77 }
78
79 if (!empty($data['start'])) {
80 $packageCustomer->setStart(
81 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['start']))
82 );
83 }
84
85 if (!empty($data['purchased'])) {
86 $packageCustomer->setPurchased(
87 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['purchased']))
88 );
89 }
90
91 if (!empty($data['status'])) {
92 $packageCustomer->setStatus(
93 new BookingStatus($data['status'])
94 );
95 }
96
97 if (isset($data['bookingsCount'])) {
98 $packageCustomer->setBookingsCount(new WholeNumber($data['bookingsCount']));
99 }
100
101 if (isset($data['couponId'])) {
102 $packageCustomer->setCouponId(new Id($data['couponId']));
103 }
104
105 if (isset($data['coupon'])) {
106 $packageCustomer->setCoupon(CouponFactory::create($data['coupon']));
107 }
108
109 if (!empty($data['tax'])) {
110 if (is_string($data['tax'])) {
111 $packageCustomer->setTax(new Json($data['tax']));
112 } elseif (json_encode($data['tax']) !== false) {
113 $packageCustomer->setTax(new Json(json_encode($data['tax'])));
114 }
115 }
116
117 return $packageCustomer;
118 }
119 }
120