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