PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.5
Booking for Appointments and Events Calendar – Amelia v1.2.5
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 / Infrastructure / Repository / Booking / Event / EventTicketRepository.php
ameliabooking / src / Infrastructure / Repository / Booking / Event Last commit date
CustomerBookingEventPeriodRepository.php 1 year ago CustomerBookingEventTicketRepository.php 1 year ago EventPeriodsRepository.php 1 year ago EventProvidersRepository.php 1 year ago EventRepository.php 1 year ago EventTagsRepository.php 1 year ago EventTicketRepository.php 1 year ago
EventTicketRepository.php
141 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 ':dateRanges' => $data['dateRanges'],
38 ':translations' => $data['translations'],
39 ];
40
41 try {
42 $statement = $this->connection->prepare(
43 "INSERT INTO {$this->table}
44 (
45 `eventId`,
46 `name`,
47 `enabled`,
48 `price`,
49 `spots`,
50 `dateRanges`,
51 `translations`
52 )
53 VALUES (
54 :eventId,
55 :name,
56 :enabled,
57 :price,
58 :spots,
59 :dateRanges,
60 :translations
61 )"
62 );
63
64 $res = $statement->execute($params);
65
66 if (!$res) {
67 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
68 }
69
70 return $this->connection->lastInsertId();
71 } catch (\Exception $e) {
72 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
73 }
74 }
75
76 /**
77 * @param int $id
78 * @param EventTicket $entity
79 *
80 * @return mixed
81 * @throws QueryExecutionException
82 */
83 public function update($id, $entity)
84 {
85 $data = $entity->toArray();
86
87 $params = [
88 ':id' => $id,
89 ':eventId' => $data['eventId'],
90 ':name' => $data['name'],
91 ':enabled' => $data['enabled'] ? 1 : 0,
92 ':price' => $data['price'],
93 ':spots' => $data['spots'],
94 ':dateRanges' => $data['dateRanges'],
95 ':translations' => $data['translations'],
96 ];
97
98 try {
99 $statement = $this->connection->prepare(
100 "UPDATE {$this->table}
101 SET
102 `eventId` = :eventId,
103 `name` = :name,
104 `enabled` = :enabled,
105 `price` = :price,
106 `spots` = :spots,
107 `dateRanges` = :dateRanges,
108 `translations` = :translations
109 WHERE id = :id"
110 );
111
112 $res = $statement->execute($params);
113
114 if (!$res) {
115 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
116 }
117
118 return $res;
119 } catch (\Exception $e) {
120 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
121 }
122 }
123
124 /**
125 * @param int eventId
126 *
127 * @return bool
128 * @throws QueryExecutionException
129 */
130 public function deleteByEventId($eventId)
131 {
132 try {
133 $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE eventId = :eventId");
134 $statement->bindParam(':eventId', $eventId);
135 return $statement->execute();
136 } catch (\Exception $e) {
137 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
138 }
139 }
140 }
141