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