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