PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
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 / PeriodLocationRepository.php
ameliabooking / src / Infrastructure / Repository / Schedule Last commit date
DayOffRepository.php 1 year ago PeriodLocationRepository.php 1 year ago PeriodRepository.php 1 year ago PeriodServiceRepository.php 1 year ago SpecialDayPeriodLocationRepository.php 1 year ago SpecialDayPeriodRepository.php 1 year ago SpecialDayPeriodServiceRepository.php 1 year ago SpecialDayRepository.php 1 year ago TimeOutRepository.php 1 year ago WeekDayRepository.php 1 year ago
PeriodLocationRepository.php
87 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Schedule;
4
5 use AmeliaBooking\Domain\Entity\Schedule\PeriodLocation;
6 use AmeliaBooking\Domain\Factory\Schedule\PeriodLocationFactory;
7 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
8 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
9
10 /**
11 * Class PeriodLocationRepository
12 *
13 * @package AmeliaBooking\Infrastructure\Repository\Schedule
14 */
15 class PeriodLocationRepository extends AbstractRepository
16 {
17 public const FACTORY = PeriodLocationFactory::class;
18
19 /**
20 * @param PeriodLocation $entity
21 * @param int $periodId
22 *
23 * @return bool
24 * @throws QueryExecutionException
25 */
26 public function add($entity, $periodId)
27 {
28 $data = $entity->toArray();
29
30 $params = [
31 ':periodId' => $periodId,
32 ':locationId' => $data['locationId'],
33 ];
34
35 try {
36 $statement = $this->connection->prepare(
37 "INSERT INTO {$this->table}
38 (`periodId`, `locationId`)
39 VALUES (:periodId, :locationId)"
40 );
41
42 $res = $statement->execute($params);
43 if (!$res) {
44 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
45 }
46 } catch (\Exception $e) {
47 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
48 }
49
50 return $this->connection->lastInsertId();
51 }
52
53 /**
54 * @param PeriodLocation $entity
55 * @param int $id
56 *
57 * @return int
58 * @throws QueryExecutionException
59 */
60 public function update($entity, $id)
61 {
62 $data = $entity->toArray();
63
64 $params = [
65 ':id' => $id,
66 ':locationId' => $data['locationId'],
67 ];
68
69 try {
70 $statement = $this->connection->prepare(
71 "UPDATE {$this->table}
72 SET `locationId` = :locationId
73 WHERE id = :id"
74 );
75
76 $res = $statement->execute($params);
77 if (!$res) {
78 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
79 }
80
81 return $res;
82 } catch (\Exception $e) {
83 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
84 }
85 }
86 }
87