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