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
EventProvidersRepository.php
73 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 | * @param Event $event |
| 19 | * @param Provider $provider |
| 20 | * |
| 21 | * @return mixed |
| 22 | * @throws QueryExecutionException |
| 23 | */ |
| 24 | public function add($event, $provider) |
| 25 | { |
| 26 | $eventData = $event->toArray(); |
| 27 | $providerData = $provider->toArray(); |
| 28 | |
| 29 | $params = [ |
| 30 | ':userId' => $providerData['id'], |
| 31 | ':eventId' => $eventData['id'], |
| 32 | ]; |
| 33 | |
| 34 | try { |
| 35 | $statement = $this->connection->prepare( |
| 36 | "INSERT INTO {$this->table} |
| 37 | ( |
| 38 | `userId`, |
| 39 | `eventId` |
| 40 | ) |
| 41 | VALUES ( |
| 42 | :userId, |
| 43 | :eventId |
| 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 $eventId |
| 57 | * |
| 58 | * @return bool |
| 59 | * @throws QueryExecutionException |
| 60 | */ |
| 61 | public function deleteByEventId($eventId) |
| 62 | { |
| 63 | try { |
| 64 | $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE eventId = :eventId"); |
| 65 | $statement->bindParam(':eventId', $eventId); |
| 66 | $statement->execute(); |
| 67 | return true; |
| 68 | } catch (\Exception $e) { |
| 69 | throw new QueryExecutionException('Unable to delete data from ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |