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