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