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