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