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 / Event / EventTicketRepository.php
ameliabooking / src / Infrastructure / Repository / Booking / Event Last commit date
CustomerBookingEventPeriodRepository.php 6 years ago CustomerBookingEventTicketRepository.php 1 year ago EventPeriodsRepository.php 4 years ago EventProvidersRepository.php 6 years ago EventRepository.php 1 year ago EventTagsRepository.php 6 years ago EventTicketRepository.php 1 year ago
EventTicketRepository.php
146 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Booking\Event;
4
5 use AmeliaBooking\Domain\Entity\Booking\Event\EventTicket;
6 use AmeliaBooking\Domain\Factory\Booking\Event\EventTicketFactory;
7 use AmeliaBooking\Domain\Repository\Booking\Event\EventRepositoryInterface;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class EventTicketRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Booking\Event
15 */
16 class EventTicketRepository extends AbstractRepository implements EventRepositoryInterface
17 {
18
19 const FACTORY = EventTicketFactory::class;
20
21 /**
22 * @param EventTicket $entity
23 *
24 * @return bool
25 * @throws QueryExecutionException
26 */
27 public function add($entity)
28 {
29 $data = $entity->toArray();
30
31 $params = [
32 ':eventId' => $data['eventId'],
33 ':name' => $data['name'],
34 ':enabled' => $data['enabled'] ? 1 : 0,
35 ':price' => $data['price'],
36 ':spots' => $data['spots'],
37 ':waitingListSpots' => $data['waitingListSpots'] ?: 0,
38 ':dateRanges' => $data['dateRanges'],
39 ':translations' => $data['translations'],
40 ];
41
42 try {
43 $statement = $this->connection->prepare(
44 "INSERT INTO {$this->table}
45 (
46 `eventId`,
47 `name`,
48 `enabled`,
49 `price`,
50 `spots`,
51 `waitingListSpots`,
52 `dateRanges`,
53 `translations`
54 )
55 VALUES (
56 :eventId,
57 :name,
58 :enabled,
59 :price,
60 :spots,
61 :waitingListSpots,
62 :dateRanges,
63 :translations
64 )"
65 );
66
67 $res = $statement->execute($params);
68
69 if (!$res) {
70 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
71 }
72
73 return $this->connection->lastInsertId();
74 } catch (\Exception $e) {
75 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
76 }
77 }
78
79 /**
80 * @param int $id
81 * @param EventTicket $entity
82 *
83 * @return mixed
84 * @throws QueryExecutionException
85 */
86 public function update($id, $entity)
87 {
88 $data = $entity->toArray();
89
90 $params = [
91 ':id' => $id,
92 ':eventId' => $data['eventId'],
93 ':name' => $data['name'],
94 ':enabled' => $data['enabled'] ? 1 : 0,
95 ':price' => $data['price'],
96 ':spots' => $data['spots'],
97 ':waitingListSpots' => $data['waitingListSpots'] ?: 0,
98 ':dateRanges' => $data['dateRanges'],
99 ':translations' => $data['translations'],
100 ];
101
102 try {
103 $statement = $this->connection->prepare(
104 "UPDATE {$this->table}
105 SET
106 `eventId` = :eventId,
107 `name` = :name,
108 `enabled` = :enabled,
109 `price` = :price,
110 `spots` = :spots,
111 `waitingListSpots` = :waitingListSpots,
112 `dateRanges` = :dateRanges,
113 `translations` = :translations
114 WHERE id = :id"
115 );
116
117 $res = $statement->execute($params);
118
119 if (!$res) {
120 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
121 }
122
123 return $res;
124 } catch (\Exception $e) {
125 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
126 }
127 }
128
129 /**
130 * @param int eventId
131 *
132 * @return bool
133 * @throws QueryExecutionException
134 */
135 public function deleteByEventId($eventId)
136 {
137 try {
138 $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE eventId = :eventId");
139 $statement->bindParam(':eventId', $eventId);
140 return $statement->execute();
141 } catch (\Exception $e) {
142 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
143 }
144 }
145 }
146