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 / CustomField / CustomFieldServiceRepository.php
ameliabooking / src / Infrastructure / Repository / CustomField Last commit date
CustomFieldEventRepository.php 5 years ago CustomFieldOptionRepository.php 1 year ago CustomFieldRepository.php 1 year ago CustomFieldServiceRepository.php 5 years ago
CustomFieldServiceRepository.php
151 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Infrastructure\Repository\CustomField;
8
9 use AmeliaBooking\Domain\Entity\CustomField\CustomFieldOption;
10 use AmeliaBooking\Domain\Factory\CustomField\CustomFieldOptionFactory;
11 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13
14 /**
15 * Class CustomFieldOptionRepository
16 *
17 * @package AmeliaBooking\Infrastructure\Repository\CustomField
18 */
19 class CustomFieldServiceRepository extends AbstractRepository
20 {
21
22 const FACTORY = CustomFieldOptionFactory::class;
23
24 /**
25 * @param $customFieldId
26 * @param $serviceId
27 *
28 * @return bool
29 * @throws QueryExecutionException
30 */
31 public function add($customFieldId, $serviceId)
32 {
33 $params = [
34 ':customFieldId' => $customFieldId,
35 ':serviceId' => $serviceId
36 ];
37
38 try {
39 $statement = $this->connection->prepare(
40 "INSERT INTO
41 {$this->table}
42 (
43 `customFieldId`, `serviceId`
44 ) VALUES (
45 :customFieldId, :serviceId
46 )"
47 );
48
49 $response = $statement->execute($params);
50 } catch (\Exception $e) {
51 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
52 }
53
54 if (!$response) {
55 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
56 }
57
58 return $this->connection->lastInsertId();
59 }
60
61 /**
62 * @param int $id
63 * @param CustomFieldOption $entity
64 *
65 * @return bool
66 * @throws QueryExecutionException
67 */
68 public function update($id, $entity)
69 {
70 $data = $entity->toArray();
71
72 $params = [
73 ':customFieldId' => $data['customFieldId'],
74 ':label' => $data['label'],
75 ':position' => $data['position'],
76 ':id' => $id,
77 ];
78
79 try {
80 $statement = $this->connection->prepare(
81 "UPDATE {$this->table}
82 SET
83 `customFieldId` = :customFieldId,
84 `label` = :label,
85 `position` = :position
86 WHERE
87 id = :id"
88 );
89
90 $response = $statement->execute($params);
91 } catch (\Exception $e) {
92 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
93 }
94
95 if (!$response) {
96 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
97 }
98
99 return $response;
100 }
101
102 /**
103 * @param int $customFieldId
104 *
105 * @return array
106 * @throws QueryExecutionException
107 */
108 public function getByCustomFieldId($customFieldId)
109 {
110 try {
111 $statement = $this->connection->query(
112 "SELECT
113 cfs.id,
114 cfs.customFieldId,
115 cfs.serviceId
116 FROM {$this->table} cfs
117 WHERE cfs.customFieldId = {$customFieldId}"
118 );
119
120 $rows = $statement->fetchAll();
121 } catch (\Exception $e) {
122 throw new QueryExecutionException('Unable to find by id in ' . __CLASS__, $e->getCode(), $e);
123 }
124
125 return $rows;
126 }
127
128 /**
129 * @param int $customFieldId
130 * @param $serviceId
131 *
132 * @return bool
133 * @throws QueryExecutionException
134 */
135 public function deleteByCustomFieldIdAndServiceId($customFieldId, $serviceId)
136 {
137 try {
138 $statement = $this->connection->prepare(
139 "DELETE FROM {$this->table} WHERE customFieldId = :customFieldId AND serviceId = :serviceId"
140 );
141
142 $statement->bindParam(':customFieldId', $customFieldId);
143 $statement->bindParam(':serviceId', $serviceId);
144
145 return $statement->execute();
146 } catch (\Exception $e) {
147 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
148 }
149 }
150 }
151