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
EventProvidersRepository.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\Repository\Booking\Event; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Entity\Booking\Event\Event; |
| 6 | use AmeliaBooking\Domain\Entity\User\Provider; |
| 7 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 8 | use AmeliaBooking\Infrastructure\Repository\AbstractRepository; |
| 9 | |
| 10 | /** |
| 11 | * Class EventProvidersRepository |
| 12 | * |
| 13 | * @package AmeliaBooking\Infrastructure\Repository\Booking\Event |
| 14 | */ |
| 15 | class EventProvidersRepository extends AbstractRepository |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * @param Event $event |
| 20 | * @param Provider $provider |
| 21 | * |
| 22 | * @return mixed |
| 23 | * @throws QueryExecutionException |
| 24 | */ |
| 25 | public function add($event, $provider) |
| 26 | { |
| 27 | $eventData = $event->toArray(); |
| 28 | $providerData = $provider->toArray(); |
| 29 | |
| 30 | $params = [ |
| 31 | ':userId' => $providerData['id'], |
| 32 | ':eventId' => $eventData['id'], |
| 33 | ]; |
| 34 | |
| 35 | try { |
| 36 | $statement = $this->connection->prepare( |
| 37 | "INSERT INTO {$this->table} |
| 38 | ( |
| 39 | `userId`, |
| 40 | `eventId` |
| 41 | ) |
| 42 | VALUES ( |
| 43 | :userId, |
| 44 | :eventId |
| 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 eventId |
| 62 | * |
| 63 | * @return bool |
| 64 | * @throws QueryExecutionException |
| 65 | */ |
| 66 | public function deleteByEventId($eventId) |
| 67 | { |
| 68 | try { |
| 69 | $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE eventId = :eventId"); |
| 70 | $statement->bindParam(':eventId', $eventId); |
| 71 | return $statement->execute(); |
| 72 | } catch (\Exception $e) { |
| 73 | throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 |