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