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 |