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 / Location / ProviderLocationRepository.php
ameliabooking / src / Infrastructure / Repository / Location Last commit date
LocationRepository.php 1 year ago ProviderLocationRepository.php 6 years ago
ProviderLocationRepository.php
102 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Location;
4
5 use AmeliaBooking\Domain\Entity\Location\ProviderLocation;
6 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
7 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
8
9 /**
10 * Class ProviderLocationRepository
11 *
12 * @package AmeliaBooking\Infrastructure\Repository\Location
13 */
14 class ProviderLocationRepository extends AbstractRepository
15 {
16 const FACTORY = ProviderLocationRepository::class;
17
18 /**
19 * @param ProviderLocation $entity
20 *
21 * @return int
22 * @throws QueryExecutionException
23 */
24 public function add($entity)
25 {
26 $data = $entity->toArray();
27
28 $params = [
29 ':userId' => $data['userId'],
30 ':locationId' => $data['locationId'],
31 ];
32
33 try {
34 $statement = $this->connection->prepare(
35 "INSERT INTO {$this->table}
36 (`userId`, `locationId`)
37 VALUES
38 (:userId, :locationId)"
39 );
40
41 $res = $statement->execute($params);
42 if (!$res) {
43 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
44 }
45 } catch (\Exception $e) {
46 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
47 }
48
49 return $this->connection->lastInsertId();
50 }
51
52 /**
53 * @param int $userId
54 *
55 * @return bool
56 * @throws QueryExecutionException
57 */
58 public function delete($userId)
59 {
60 try {
61 $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE userId = :userId");
62 $statement->bindParam(':userId', $userId);
63 return $statement->execute();
64 } catch (\Exception $e) {
65 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
66 }
67 }
68
69 /**
70 * @param ProviderLocation $entity
71 *
72 * @return int
73 * @throws QueryExecutionException
74 */
75 public function update($entity)
76 {
77 $data = $entity->toArray();
78
79 $params = [
80 ':userId' => $data['userId'],
81 ':locationId' => $data['locationId'],
82 ];
83
84 try {
85 $statement = $this->connection->prepare(
86 "UPDATE {$this->table}
87 SET `locationId` = :locationId
88 WHERE userId = :userId"
89 );
90
91 $res = $statement->execute($params);
92 if (!$res) {
93 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
94 }
95 } catch (\Exception $e) {
96 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
97 }
98
99 return $this->connection->lastInsertId();
100 }
101 }
102