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