DayOffRepository.php
1 month ago
PeriodLocationRepository.php
3 months ago
PeriodRepository.php
3 months ago
PeriodServiceRepository.php
3 months ago
SpecialDayPeriodLocationRepository.php
3 months ago
SpecialDayPeriodRepository.php
3 months ago
SpecialDayPeriodServiceRepository.php
3 months ago
SpecialDayRepository.php
3 months ago
TimeOutRepository.php
3 months ago
WeekDayRepository.php
3 months ago
PeriodLocationRepository.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\Repository\Schedule; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Entity\Schedule\PeriodLocation; |
| 6 | use AmeliaBooking\Domain\Factory\Schedule\PeriodLocationFactory; |
| 7 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 8 | use AmeliaBooking\Infrastructure\Repository\AbstractRepository; |
| 9 | |
| 10 | /** |
| 11 | * Class PeriodLocationRepository |
| 12 | * |
| 13 | * @package AmeliaBooking\Infrastructure\Repository\Schedule |
| 14 | */ |
| 15 | class PeriodLocationRepository extends AbstractRepository |
| 16 | { |
| 17 | public const FACTORY = PeriodLocationFactory::class; |
| 18 | |
| 19 | /** |
| 20 | * @param PeriodLocation $entity |
| 21 | * @param int $periodId |
| 22 | * |
| 23 | * @return int |
| 24 | * @throws QueryExecutionException |
| 25 | */ |
| 26 | public function add($entity, $periodId) |
| 27 | { |
| 28 | $data = $entity->toArray(); |
| 29 | |
| 30 | $params = [ |
| 31 | ':periodId' => $periodId, |
| 32 | ':locationId' => $data['locationId'], |
| 33 | ]; |
| 34 | |
| 35 | try { |
| 36 | $statement = $this->connection->prepare( |
| 37 | "INSERT INTO {$this->table} |
| 38 | (`periodId`, `locationId`) |
| 39 | VALUES (:periodId, :locationId)" |
| 40 | ); |
| 41 | |
| 42 | $statement->execute($params); |
| 43 | } catch (\Exception $e) { |
| 44 | throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e); |
| 45 | } |
| 46 | |
| 47 | return $this->connection->lastInsertId(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @param PeriodLocation $entity |
| 52 | * @param int $id |
| 53 | * |
| 54 | * @return void |
| 55 | * @throws QueryExecutionException |
| 56 | */ |
| 57 | public function update($entity, $id) |
| 58 | { |
| 59 | $data = $entity->toArray(); |
| 60 | |
| 61 | $params = [ |
| 62 | ':id' => $id, |
| 63 | ':locationId' => $data['locationId'], |
| 64 | ]; |
| 65 | |
| 66 | try { |
| 67 | $statement = $this->connection->prepare( |
| 68 | "UPDATE {$this->table} |
| 69 | SET `locationId` = :locationId |
| 70 | WHERE id = :id" |
| 71 | ); |
| 72 | |
| 73 | $statement->execute($params); |
| 74 | } catch (\Exception $e) { |
| 75 | throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |