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 / CustomFieldOptionRepository.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
CustomFieldOptionRepository.php
101 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\Domain\Repository\CustomField\CustomFieldOptionRepositoryInterface;
13 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
14 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
15
16 /**
17 * Class CustomFieldOptionRepository
18 *
19 * @package AmeliaBooking\Infrastructure\Repository\CustomField
20 */
21 class CustomFieldOptionRepository extends AbstractRepository implements CustomFieldOptionRepositoryInterface
22 {
23 public const FACTORY = CustomFieldOptionFactory::class;
24
25 /**
26 * @param CustomFieldOption $entity
27 *
28 * @return int
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 $statement->execute($params);
55 } catch (\Exception $e) {
56 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
57 }
58
59 return $this->connection->lastInsertId();
60 }
61
62 /**
63 * @param int $id
64 * @param CustomFieldOption $entity
65 *
66 * @return bool
67 * @throws QueryExecutionException
68 */
69 public function update($id, $entity)
70 {
71 $data = $entity->toArray();
72
73 $params = [
74 ':customFieldId' => $data['customFieldId'],
75 ':label' => $data['label'],
76 ':position' => $data['position'],
77 ':translations' => $data['translations'],
78 ':id' => $id,
79 ];
80
81 try {
82 $statement = $this->connection->prepare(
83 "UPDATE {$this->table}
84 SET
85 `customFieldId` = :customFieldId,
86 `label` = :label,
87 `position` = :position,
88 `translations` = :translations
89 WHERE
90 id = :id"
91 );
92
93 $statement->execute($params);
94 } catch (\Exception $e) {
95 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
96 }
97
98 return true;
99 }
100 }
101