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 / CustomFieldOptionRepository.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
CustomFieldOptionRepository.php
109 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\Domain\Repository\CustomField\CustomFieldOptionRepositoryInterface;
12 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
13 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
14
15 /**
16 * Class CustomFieldOptionRepository
17 *
18 * @package AmeliaBooking\Infrastructure\Repository\CustomField
19 */
20 class CustomFieldOptionRepository extends AbstractRepository implements CustomFieldOptionRepositoryInterface
21 {
22
23 const FACTORY = CustomFieldOptionFactory::class;
24
25 /**
26 * @param CustomFieldOption $entity
27 *
28 * @return bool
29 * @throws QueryExecutionException
30 */
31 public function add($entity)
32 {
33 $data = $entity->toArray();
34
35 $params = [
36 ':customFieldId' => $data['customFieldId'],
37 ':label' => isset($data['label']) ? $data['label'] : '',
38 ':position' => $data['position'],
39 ':translations' => $data['translations'],
40 ];
41
42 try {
43 $statement = $this->connection->prepare(
44 "INSERT INTO
45 {$this->table}
46 (
47 `customFieldId`, `label`, `position`, `translations`
48 ) VALUES (
49 :customFieldId, :label, :position, :translations
50 )"
51 );
52
53
54 $response = $statement->execute($params);
55 } catch (\Exception $e) {
56 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
57 }
58
59 if (!$response) {
60 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
61 }
62
63 return $this->connection->lastInsertId();
64 }
65
66 /**
67 * @param int $id
68 * @param CustomFieldOption $entity
69 *
70 * @return bool
71 * @throws QueryExecutionException
72 */
73 public function update($id, $entity)
74 {
75 $data = $entity->toArray();
76
77 $params = [
78 ':customFieldId' => $data['customFieldId'],
79 ':label' => $data['label'],
80 ':position' => $data['position'],
81 ':translations' => $data['translations'],
82 ':id' => $id,
83 ];
84
85 try {
86 $statement = $this->connection->prepare(
87 "UPDATE {$this->table}
88 SET
89 `customFieldId` = :customFieldId,
90 `label` = :label,
91 `position` = :position,
92 `translations` = :translations
93 WHERE
94 id = :id"
95 );
96
97 $response = $statement->execute($params);
98 } catch (\Exception $e) {
99 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
100 }
101
102 if (!$response) {
103 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
104 }
105
106 return $response;
107 }
108 }
109