PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 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