CustomerBookingEventPeriodRepository.php
1 year ago
CustomerBookingEventTicketRepository.php
1 year ago
EventPeriodsRepository.php
1 year ago
EventProvidersRepository.php
1 year ago
EventRepository.php
1 year ago
EventTagsRepository.php
1 year ago
EventTicketRepository.php
1 year ago
EventPeriodsRepository.php
103 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 bool |
| 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 | $res = $statement->execute($params); |
| 54 | |
| 55 | if (!$res) { |
| 56 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__); |
| 57 | } |
| 58 | |
| 59 | return $this->connection->lastInsertId(); |
| 60 | } catch (\Exception $e) { |
| 61 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @param int $id |
| 67 | * @param EventPeriod $entity |
| 68 | * |
| 69 | * @return mixed |
| 70 | * @throws QueryExecutionException |
| 71 | */ |
| 72 | public function update($id, $entity) |
| 73 | { |
| 74 | $data = $entity->toArray(); |
| 75 | |
| 76 | $params = [ |
| 77 | ':id' => $id, |
| 78 | ':periodStart' => DateTimeService::getCustomDateTimeInUtc($data['periodStart']), |
| 79 | ':periodEnd' => DateTimeService::getCustomDateTimeInUtc($data['periodEnd']) |
| 80 | ]; |
| 81 | |
| 82 | try { |
| 83 | $statement = $this->connection->prepare( |
| 84 | "UPDATE {$this->table} |
| 85 | SET |
| 86 | `periodStart` = :periodStart, |
| 87 | `periodEnd` = :periodEnd |
| 88 | WHERE id = :id" |
| 89 | ); |
| 90 | |
| 91 | $res = $statement->execute($params); |
| 92 | |
| 93 | if (!$res) { |
| 94 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__); |
| 95 | } |
| 96 | |
| 97 | return $res; |
| 98 | } catch (\Exception $e) { |
| 99 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 |