PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.11
Booking for Appointments and Events Calendar – Amelia v1.2.11
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 / SpecialDayPeriodRepository.php
ameliabooking / src / Infrastructure / Repository / Schedule Last commit date
DayOffRepository.php 6 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
SpecialDayPeriodRepository.php
111 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Schedule;
4
5 use AmeliaBooking\Domain\Entity\Schedule\SpecialDayPeriod;
6 use AmeliaBooking\Domain\Factory\Schedule\SpecialDayPeriodFactory;
7 use AmeliaBooking\Infrastructure\Licence;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class SpecialDayPeriodRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Schedule
15 */
16 class SpecialDayPeriodRepository extends AbstractRepository
17 {
18 const FACTORY = SpecialDayPeriodFactory::class;
19
20 /**
21 * @param SpecialDayPeriod $entity
22 * @param int $specialDayId
23 *
24 * @return bool
25 * @throws QueryExecutionException
26 */
27 public function add($entity, $specialDayId)
28 {
29 $data = $entity->toArray();
30
31 $params = [
32 ':specialDayId' => $specialDayId,
33 ':startTime' => $data['startTime'],
34 ':endTime' => $data['endTime']
35 ];
36
37 $additionalData = Licence\DataModifier::getPeriodRepositoryData($data);
38
39 $params = array_merge($params, $additionalData['values']);
40
41 try {
42 $statement = $this->connection->prepare(
43 "INSERT INTO
44 {$this->table}
45 (
46 {$additionalData['columns']}
47 `specialDayId`,
48 `startTime`,
49 `endTime`
50 ) VALUES (
51 {$additionalData['placeholders']}
52 :specialDayId,
53 :startTime,
54 :endTime
55 )"
56 );
57
58 $res = $statement->execute($params);
59 if (!$res) {
60 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
61 }
62 } catch (\Exception $e) {
63 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
64 }
65
66 return $this->connection->lastInsertId();
67 }
68
69 /**
70 * @param SpecialDayPeriod $entity
71 * @param int $id
72 *
73 * @return int
74 * @throws QueryExecutionException
75 */
76 public function update($entity, $id)
77 {
78 $data = $entity->toArray();
79
80 $params = [
81 ':id' => $id,
82 ':startTime' => $data['startTime'],
83 ':endTime' => $data['endTime']
84 ];
85
86 $additionalData = Licence\DataModifier::getPeriodRepositoryData($data);
87
88 $params = array_merge($params, $additionalData['values']);
89
90 try {
91 $statement = $this->connection->prepare(
92 "UPDATE {$this->table}
93 SET
94 {$additionalData['columnsPlaceholders']}
95 `startTime` = :startTime,
96 `endTime` = :endTime
97 WHERE id = :id"
98 );
99
100 $res = $statement->execute($params);
101 if (!$res) {
102 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
103 }
104
105 return $res;
106 } catch (\Exception $e) {
107 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
108 }
109 }
110 }
111