PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 1 month ago PeriodLocationRepository.php 3 months ago PeriodRepository.php 3 months ago PeriodServiceRepository.php 3 months ago SpecialDayPeriodLocationRepository.php 3 months ago SpecialDayPeriodRepository.php 3 months ago SpecialDayPeriodServiceRepository.php 3 months ago SpecialDayRepository.php 3 months ago TimeOutRepository.php 3 months ago WeekDayRepository.php 3 months ago
SpecialDayPeriodRepository.php
103 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 public const FACTORY = SpecialDayPeriodFactory::class;
19
20 /**
21 * @param SpecialDayPeriod $entity
22 * @param int $specialDayId
23 *
24 * @return int
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 $statement->execute($params);
59 } catch (\Exception $e) {
60 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
61 }
62
63 return $this->connection->lastInsertId();
64 }
65
66 /**
67 * @param SpecialDayPeriod $entity
68 * @param int $id
69 *
70 * @return void
71 * @throws QueryExecutionException
72 */
73 public function update($entity, $id)
74 {
75 $data = $entity->toArray();
76
77 $params = [
78 ':id' => $id,
79 ':startTime' => $data['startTime'],
80 ':endTime' => $data['endTime']
81 ];
82
83 $additionalData = Licence\DataModifier::getPeriodRepositoryData($data);
84
85 $params = array_merge($params, $additionalData['values']);
86
87 try {
88 $statement = $this->connection->prepare(
89 "UPDATE {$this->table}
90 SET
91 {$additionalData['columnsPlaceholders']}
92 `startTime` = :startTime,
93 `endTime` = :endTime
94 WHERE id = :id"
95 );
96
97 $statement->execute($params);
98 } catch (\Exception $e) {
99 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
100 }
101 }
102 }
103