ameliabooking
/
src
/
Infrastructure
/
Repository
/
Booking
/
Event
/
CustomerBookingEventPeriodRepository.php
CustomerBookingEventPeriodRepository.php
6 years ago
CustomerBookingEventTicketRepository.php
1 year ago
EventPeriodsRepository.php
4 years ago
EventProvidersRepository.php
6 years ago
EventRepository.php
1 year ago
EventTagsRepository.php
6 years ago
EventTicketRepository.php
1 year ago
CustomerBookingEventPeriodRepository.php
99 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 | |
| 18 | const FACTORY = CustomerBookingEventPeriod::class; |
| 19 | |
| 20 | /** |
| 21 | * @param CustomerBookingEventPeriod $entity |
| 22 | * |
| 23 | * @return bool |
| 24 | * @throws QueryExecutionException |
| 25 | */ |
| 26 | public function add($entity) |
| 27 | { |
| 28 | $data = $entity->toArray(); |
| 29 | |
| 30 | $params = [ |
| 31 | ':eventPeriodId' => $data['eventPeriodId'], |
| 32 | ':customerBookingId' => $data['customerBookingId'], |
| 33 | ]; |
| 34 | |
| 35 | try { |
| 36 | $statement = $this->connection->prepare( |
| 37 | "INSERT INTO {$this->table} |
| 38 | ( |
| 39 | `eventPeriodId`, |
| 40 | `customerBookingId` |
| 41 | ) |
| 42 | VALUES ( |
| 43 | :eventPeriodId, |
| 44 | :customerBookingId |
| 45 | )" |
| 46 | ); |
| 47 | |
| 48 | $res = $statement->execute($params); |
| 49 | |
| 50 | if (!$res) { |
| 51 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__); |
| 52 | } |
| 53 | |
| 54 | return $this->connection->lastInsertId(); |
| 55 | } catch (\Exception $e) { |
| 56 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param int $id |
| 62 | * @param CustomerBookingEventPeriod $entity |
| 63 | * |
| 64 | * @return mixed |
| 65 | * @throws QueryExecutionException |
| 66 | */ |
| 67 | public function update($id, $entity) |
| 68 | { |
| 69 | $data = $entity->toArray(); |
| 70 | |
| 71 | $params = [ |
| 72 | ':id' => $id, |
| 73 | ':eventPeriodId' => $data['eventPeriodId'], |
| 74 | ':customerBookingId' => $data['customerBookingId'], |
| 75 | ]; |
| 76 | |
| 77 | try { |
| 78 | $statement = $this->connection->prepare( |
| 79 | "UPDATE {$this->table} |
| 80 | SET |
| 81 | `eventPeriodId` = :eventPeriodId, |
| 82 | `customerBookingId` = :customerBookingId |
| 83 | WHERE id = :id" |
| 84 | ); |
| 85 | |
| 86 | $res = $statement->execute($params); |
| 87 | |
| 88 | if (!$res) { |
| 89 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__); |
| 90 | } |
| 91 | |
| 92 | return $res; |
| 93 | } catch (\Exception $e) { |
| 94 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | } |
| 99 |