PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 3 months ago CustomerBookingEventTicketRepository.php 3 months ago EventPeriodsRepository.php 3 months ago EventProvidersRepository.php 3 months ago EventRepository.php 3 days ago EventTagsRepository.php 2 months ago EventTicketRepository.php 3 months ago
EventTicketRepository.php
120 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 int
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 $statement->execute($params);
67
68 return $this->connection->lastInsertId();
69 } catch (\Exception $e) {
70 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
71 }
72 }
73
74 /**
75 * @param int $id
76 * @param EventTicket $entity
77 *
78 * @return mixed
79 * @throws QueryExecutionException
80 */
81 public function update($id, $entity)
82 {
83 $data = $entity->toArray();
84
85 $params = [
86 ':id' => $id,
87 ':eventId' => $data['eventId'],
88 ':name' => $data['name'],
89 ':enabled' => $data['enabled'] ? 1 : 0,
90 ':price' => $data['price'],
91 ':spots' => $data['spots'],
92 ':waitingListSpots' => $data['waitingListSpots'] ?: 0,
93 ':dateRanges' => $data['dateRanges'],
94 ':translations' => $data['translations'],
95 ];
96
97 try {
98 $statement = $this->connection->prepare(
99 "UPDATE {$this->table}
100 SET
101 `eventId` = :eventId,
102 `name` = :name,
103 `enabled` = :enabled,
104 `price` = :price,
105 `spots` = :spots,
106 `waitingListSpots` = :waitingListSpots,
107 `dateRanges` = :dateRanges,
108 `translations` = :translations
109 WHERE id = :id"
110 );
111
112 $statement->execute($params);
113
114 return true;
115 } catch (\Exception $e) {
116 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
117 }
118 }
119 }
120