PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
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 / Infrastructure / Repository / Booking / Appointment / CustomerBookingExtraRepository.php
ameliabooking / src / Infrastructure / Repository / Booking / Appointment Last commit date
AppointmentRepository.php 1 year ago CustomerBookingExtraRepository.php 1 year ago CustomerBookingRepository.php 10 months ago
CustomerBookingExtraRepository.php
114 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Booking\Appointment;
4
5 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBookingExtra;
6 use AmeliaBooking\Domain\Factory\Booking\Appointment\CustomerBookingExtraFactory;
7 use AmeliaBooking\Domain\Repository\Booking\Appointment\CustomerBookingExtraRepositoryInterface;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class CustomerBookingExtraRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Booking\Appointment
15 */
16 class CustomerBookingExtraRepository extends AbstractRepository implements CustomerBookingExtraRepositoryInterface
17 {
18 public const FACTORY = CustomerBookingExtraFactory::class;
19
20 /**
21 * @param CustomerBookingExtra $entity
22 *
23 * @return mixed
24 * @throws QueryExecutionException
25 */
26 public function add($entity)
27 {
28 $data = $entity->toArray();
29
30 $params = [
31 ':customerBookingId' => $data['customerBookingId'],
32 ':extraId' => $data['extraId'],
33 ':quantity' => $data['quantity'],
34 ':price' => $data['price'],
35 ':tax' => !empty($data['tax']) ? json_encode($data['tax']) : null,
36 ':aggregatedPrice' => $data['aggregatedPrice'] ? 1 : 0,
37 ];
38
39 try {
40 $statement = $this->connection->prepare(
41 "INSERT INTO {$this->table}
42 (
43 `customerBookingId`,
44 `extraId`,
45 `quantity`,
46 `aggregatedPrice`,
47 `price`,
48 `tax`
49 )
50 VALUES (
51 :customerBookingId,
52 :extraId,
53 :quantity,
54 :aggregatedPrice,
55 :price,
56 :tax
57 )"
58 );
59
60 $res = $statement->execute($params);
61
62 if (!$res) {
63 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
64 }
65
66 return $this->connection->lastInsertId();
67 } catch (\Exception $e) {
68 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
69 }
70 }
71
72 /**
73 * @param int $id
74 * @param CustomerBookingExtra $entity
75 *
76 * @return mixed
77 * @throws QueryExecutionException
78 */
79 public function update($id, $entity)
80 {
81 $data = $entity->toArray();
82
83 $params = [
84 ':id' => $id,
85 ':customerBookingId' => $data['customerBookingId'],
86 ':extraId' => $data['extraId'],
87 ':quantity' => $data['quantity'],
88 ':aggregatedPrice' => $data['aggregatedPrice'] ? 1 : 0,
89 ];
90
91 try {
92 $statement = $this->connection->prepare(
93 "UPDATE {$this->table}
94 SET
95 `customerBookingId` = :customerBookingId,
96 `extraId` = :extraId,
97 `aggregatedPrice` = :aggregatedPrice,
98 `quantity` = :quantity
99 WHERE id = :id"
100 );
101
102 $res = $statement->execute($params);
103
104 if (!$res) {
105 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
106 }
107
108 return $res;
109 } catch (\Exception $e) {
110 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
111 }
112 }
113 }
114