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 / 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
128 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 public const FACTORY = EventTicketFactory::class;
19
20 /**
21 * @param EventTicket $entity
22 *
23 * @return bool
24 * @throws QueryExecutionException
25 */
26 public function add($entity)
27 {
28 $data = $entity->toArray();
29
30 $params = [
31 ':eventId' => $data['eventId'],
32 ':name' => $data['name'],
33 ':enabled' => $data['enabled'] ? 1 : 0,
34 ':price' => $data['price'],
35 ':spots' => $data['spots'],
36 ':waitingListSpots' => $data['waitingListSpots'] ?: 0,
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 `waitingListSpots`,
51 `dateRanges`,
52 `translations`
53 )
54 VALUES (
55 :eventId,
56 :name,
57 :enabled,
58 :price,
59 :spots,
60 :waitingListSpots,
61 :dateRanges,
62 :translations
63 )"
64 );
65
66 $res = $statement->execute($params);
67
68 if (!$res) {
69 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
70 }
71
72 return $this->connection->lastInsertId();
73 } catch (\Exception $e) {
74 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
75 }
76 }
77
78 /**
79 * @param int $id
80 * @param EventTicket $entity
81 *
82 * @return mixed
83 * @throws QueryExecutionException
84 */
85 public function update($id, $entity)
86 {
87 $data = $entity->toArray();
88
89 $params = [
90 ':id' => $id,
91 ':eventId' => $data['eventId'],
92 ':name' => $data['name'],
93 ':enabled' => $data['enabled'] ? 1 : 0,
94 ':price' => $data['price'],
95 ':spots' => $data['spots'],
96 ':waitingListSpots' => $data['waitingListSpots'] ?: 0,
97 ':dateRanges' => $data['dateRanges'],
98 ':translations' => $data['translations'],
99 ];
100
101 try {
102 $statement = $this->connection->prepare(
103 "UPDATE {$this->table}
104 SET
105 `eventId` = :eventId,
106 `name` = :name,
107 `enabled` = :enabled,
108 `price` = :price,
109 `spots` = :spots,
110 `waitingListSpots` = :waitingListSpots,
111 `dateRanges` = :dateRanges,
112 `translations` = :translations
113 WHERE id = :id"
114 );
115
116 $res = $statement->execute($params);
117
118 if (!$res) {
119 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
120 }
121
122 return $res;
123 } catch (\Exception $e) {
124 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
125 }
126 }
127 }
128