ameliabooking
/
src
/
Infrastructure
/
Repository
/
Booking
/
Event
/
CustomerBookingEventTicketRepository.php
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
CustomerBookingEventTicketRepository.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\Repository\Booking\Event; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Entity\Booking\Event\CustomerBookingEventTicket; |
| 6 | use AmeliaBooking\Domain\Entity\Booking\Event\Event; |
| 7 | use AmeliaBooking\Domain\Factory\Booking\Event\CustomerBookingEventTicketFactory; |
| 8 | use AmeliaBooking\Domain\Repository\Booking\Event\EventRepositoryInterface; |
| 9 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 10 | use AmeliaBooking\Infrastructure\Repository\AbstractRepository; |
| 11 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\CustomerBookingsTable; |
| 12 | |
| 13 | /** |
| 14 | * Class CustomerBookingEventTicketRepository |
| 15 | * |
| 16 | * @package AmeliaBooking\Infrastructure\Repository\Booking\Event |
| 17 | */ |
| 18 | class CustomerBookingEventTicketRepository extends AbstractRepository implements EventRepositoryInterface |
| 19 | { |
| 20 | public const FACTORY = CustomerBookingEventTicketFactory::class; |
| 21 | |
| 22 | /** |
| 23 | * @param CustomerBookingEventTicket $entity |
| 24 | * |
| 25 | * @return int |
| 26 | * @throws QueryExecutionException |
| 27 | */ |
| 28 | public function add($entity) |
| 29 | { |
| 30 | $data = $entity->toArray(); |
| 31 | |
| 32 | $params = [ |
| 33 | ':eventTicketId' => $data['eventTicketId'], |
| 34 | ':customerBookingId' => $data['customerBookingId'], |
| 35 | ':price' => $data['price'], |
| 36 | ':persons' => $data['persons'] |
| 37 | ]; |
| 38 | |
| 39 | try { |
| 40 | $statement = $this->connection->prepare( |
| 41 | "INSERT INTO {$this->table} |
| 42 | ( |
| 43 | `eventTicketId`, |
| 44 | `customerBookingId`, |
| 45 | `price`, |
| 46 | `persons` |
| 47 | ) |
| 48 | VALUES ( |
| 49 | :eventTicketId, |
| 50 | :customerBookingId, |
| 51 | :price, |
| 52 | :persons |
| 53 | )" |
| 54 | ); |
| 55 | |
| 56 | $statement->execute($params); |
| 57 | |
| 58 | return $this->connection->lastInsertId(); |
| 59 | } catch (\Exception $e) { |
| 60 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param int $id |
| 66 | * @param Event $entity |
| 67 | * |
| 68 | * @return mixed |
| 69 | * @throws QueryExecutionException |
| 70 | */ |
| 71 | public function update($id, $entity) |
| 72 | { |
| 73 | $data = $entity; |
| 74 | |
| 75 | $params = [ |
| 76 | ':id' => $id, |
| 77 | ':eventTicketId' => $data['eventTicketId'], |
| 78 | ':customerBookingId' => $data['customerBookingId'], |
| 79 | ':price' => $data['price'], |
| 80 | ':persons' => $data['persons'], |
| 81 | ]; |
| 82 | |
| 83 | try { |
| 84 | $statement = $this->connection->prepare( |
| 85 | "UPDATE {$this->table} |
| 86 | SET |
| 87 | `eventTicketId` = :eventTicketId, |
| 88 | `customerBookingId` = :customerBookingId, |
| 89 | `price` = :price, |
| 90 | `persons` = :persons |
| 91 | WHERE id = :id" |
| 92 | ); |
| 93 | |
| 94 | $statement->execute($params); |
| 95 | |
| 96 | return true; |
| 97 | } catch (\Exception $e) { |
| 98 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 |