PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1.3
Booking for Appointments and Events Calendar – Amelia v2.1.3
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Repository / Schedule / DayOffRepository.php
ameliabooking / src / Infrastructure / Repository / Schedule Last commit date
DayOffRepository.php 5 months ago PeriodLocationRepository.php 5 months ago PeriodRepository.php 5 months ago PeriodServiceRepository.php 5 months ago SpecialDayPeriodLocationRepository.php 5 months ago SpecialDayPeriodRepository.php 5 months ago SpecialDayPeriodServiceRepository.php 5 months ago SpecialDayRepository.php 5 months ago TimeOutRepository.php 5 months ago WeekDayRepository.php 5 months ago
DayOffRepository.php
86 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 public 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 $statement->execute($params);
47 } catch (\Exception $e) {
48 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
49 }
50
51 return $this->connection->lastInsertId();
52 }
53
54 /**
55 * @param DayOff $entity
56 * @param int $id
57 *
58 * @return void
59 * @throws QueryExecutionException
60 */
61 public function update($entity, $id)
62 {
63 $data = $entity->toArray();
64
65 $params = [
66 ':id' => $id,
67 ':name' => $data['name'],
68 ':startDate' => $data['startDate'],
69 ':endDate' => $data['endDate'],
70 ':repeat' => $data['repeat'],
71 ];
72
73 try {
74 $statement = $this->connection->prepare(
75 "UPDATE {$this->table}
76 SET `name` = :name, `startDate` = :startDate, `endDate` = :endDate, `repeat` = :repeat
77 WHERE id = :id"
78 );
79
80 $statement->execute($params);
81 } catch (\Exception $e) {
82 throw new QueryExecutionException('Unable to add save in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
83 }
84 }
85 }
86