PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 2 weeks ago CustomerBookingExtraRepository.php 3 months ago CustomerBookingRepository.php 2 weeks ago
CustomerBookingExtraRepository.php
106 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 $statement->execute($params);
61
62 return $this->connection->lastInsertId();
63 } catch (\Exception $e) {
64 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
65 }
66 }
67
68 /**
69 * @param int $id
70 * @param CustomerBookingExtra $entity
71 *
72 * @return mixed
73 * @throws QueryExecutionException
74 */
75 public function update($id, $entity)
76 {
77 $data = $entity->toArray();
78
79 $params = [
80 ':id' => $id,
81 ':customerBookingId' => $data['customerBookingId'],
82 ':extraId' => $data['extraId'],
83 ':quantity' => $data['quantity'],
84 ':aggregatedPrice' => $data['aggregatedPrice'] ? 1 : 0,
85 ];
86
87 try {
88 $statement = $this->connection->prepare(
89 "UPDATE {$this->table}
90 SET
91 `customerBookingId` = :customerBookingId,
92 `extraId` = :extraId,
93 `aggregatedPrice` = :aggregatedPrice,
94 `quantity` = :quantity
95 WHERE id = :id"
96 );
97
98 $statement->execute($params);
99
100 return true;
101 } catch (\Exception $e) {
102 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
103 }
104 }
105 }
106