PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.1
Booking for Appointments and Events Calendar – Amelia v2.0.1
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 / PeriodRepository.php
ameliabooking / src / Infrastructure / Repository / Schedule Last commit date
DayOffRepository.php 8 months ago PeriodLocationRepository.php 8 months ago PeriodRepository.php 8 months ago PeriodServiceRepository.php 8 months ago SpecialDayPeriodLocationRepository.php 8 months ago SpecialDayPeriodRepository.php 8 months ago SpecialDayPeriodServiceRepository.php 8 months ago SpecialDayRepository.php 1 year ago TimeOutRepository.php 8 months ago WeekDayRepository.php 1 year ago
PeriodRepository.php
110 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Schedule;
4
5 use AmeliaBooking\Domain\Entity\Schedule\Period;
6 use AmeliaBooking\Domain\Factory\Schedule\PeriodFactory;
7 use AmeliaBooking\Infrastructure\Licence;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class PeriodRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Schedule
15 */
16 class PeriodRepository extends AbstractRepository
17 {
18 public const FACTORY = PeriodFactory::class;
19
20 /**
21 * @param Period $entity
22 * @param int $weekDayId
23 *
24 * @return int
25 * @throws QueryExecutionException
26 */
27 public function add($entity, $weekDayId)
28 {
29 $data = $entity->toArray();
30
31 $params = [
32 ':weekDayId' => $weekDayId,
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 `weekDayId`,
48 `startTime`,
49 `endTime`
50 ) VALUES (
51 {$additionalData['placeholders']}
52 :weekDayId,
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 Period $entity
71 * @param int $id
72 *
73 * @return void
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
98 id = :id"
99 );
100
101 $res = $statement->execute($params);
102 if (!$res) {
103 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
104 }
105 } catch (\Exception $e) {
106 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
107 }
108 }
109 }
110