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 / Location / ProviderLocationRepository.php
ameliabooking / src / Infrastructure / Repository / Location Last commit date
LocationRepository.php 3 months ago ProviderLocationRepository.php 3 months ago
ProviderLocationRepository.php
95 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 public 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 $statement->execute($params);
42 } catch (\Exception $e) {
43 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
44 }
45
46 return $this->connection->lastInsertId();
47 }
48
49 /**
50 * @param int $userId
51 *
52 * @return bool
53 * @throws QueryExecutionException
54 */
55 public function delete($userId)
56 {
57 try {
58 $statement = $this->connection->prepare("DELETE FROM {$this->table} WHERE userId = :userId");
59 $statement->bindParam(':userId', $userId);
60 $statement->execute();
61 return true;
62 } catch (\Exception $e) {
63 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
64 }
65 }
66
67 /**
68 * @param ProviderLocation $entity
69 *
70 * @return void
71 * @throws QueryExecutionException
72 */
73 public function update($entity)
74 {
75 $data = $entity->toArray();
76
77 $params = [
78 ':userId' => $data['userId'],
79 ':locationId' => $data['locationId'],
80 ];
81
82 try {
83 $statement = $this->connection->prepare(
84 "UPDATE {$this->table}
85 SET `locationId` = :locationId
86 WHERE userId = :userId"
87 );
88
89 $statement->execute($params);
90 } catch (\Exception $e) {
91 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
92 }
93 }
94 }
95