PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
2.4.5 2.4.4 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 / Bookable / Service / ExtraRepository.php
ameliabooking / src / Infrastructure / Repository / Bookable / Service Last commit date
CategoryRepository.php 1 year ago ExtraRepository.php 1 year ago PackageCustomerRepository.php 10 months ago PackageCustomerServiceRepository.php 1 year ago PackageRepository.php 1 year ago PackageServiceLocationRepository.php 1 year ago PackageServiceProviderRepository.php 1 year ago PackageServiceRepository.php 1 year ago ProviderServiceRepository.php 1 year ago ResourceEntitiesRepository.php 1 year ago ResourceRepository.php 1 year ago ServiceRepository.php 1 year ago
ExtraRepository.php
134 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Bookable\Service;
4
5 use AmeliaBooking\Domain\Entity\Bookable\Service\Extra;
6 use AmeliaBooking\Domain\Factory\Bookable\Service\ExtraFactory;
7 use AmeliaBooking\Domain\Repository\Bookable\Service\ExtraRepositoryInterface;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class ExtraRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Bookable\Service
15 */
16 class ExtraRepository extends AbstractRepository implements ExtraRepositoryInterface
17 {
18 public const FACTORY = ExtraFactory::class;
19
20 /**
21 * @param Extra $entity
22 *
23 * @return mixed
24 * @throws QueryExecutionException
25 */
26 public function add($entity)
27 {
28 $data = $entity->toArray();
29
30 $params = [
31 ':name' => $data['name'],
32 ':description' => $data['description'],
33 ':price' => $data['price'],
34 ':maxQuantity' => $data['maxQuantity'],
35 ':duration' => $data['duration'],
36 ':serviceId' => $data['serviceId'],
37 ':aggregatedPrice' => $data['aggregatedPrice'] ? 1 : 0,
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 `name`,
48 `description`,
49 `price`,
50 `maxQuantity`,
51 `duration`,
52 `serviceId`,
53 `aggregatedPrice`,
54 `position`,
55 `translations`
56 ) VALUES (
57 :name,
58 :description,
59 :price,
60 :maxQuantity,
61 :duration,
62 :serviceId,
63 :aggregatedPrice,
64 :position,
65 :translations
66 )"
67 );
68
69 $result = $statement->execute($params);
70
71 if (!$result) {
72 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
73 }
74
75 return $this->connection->lastInsertId();
76 } catch (\Exception $e) {
77 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
78 }
79 }
80
81 /**
82 * @param int $id
83 * @param Extra $entity
84 *
85 * @return mixed
86 * @throws QueryExecutionException
87 */
88 public function update($id, $entity)
89 {
90 $data = $entity->toArray();
91
92 $params = [
93 ':name' => $data['name'],
94 ':description' => $data['description'],
95 ':price' => $data['price'],
96 ':maxQuantity' => $data['maxQuantity'],
97 ':duration' => $data['duration'],
98 ':serviceId' => $data['serviceId'],
99 ':aggregatedPrice' => $data['aggregatedPrice'] === null ?
100 $data['aggregatedPrice'] : ((int)$data['aggregatedPrice']),
101 ':position' => $data['position'],
102 ':translations' => $data['translations'],
103 ':id' => $id
104 ];
105
106 try {
107 $statement = $this->connection->prepare(
108 "UPDATE {$this->table}
109 SET
110 `name` = :name,
111 `description` = :description,
112 `price` = :price,
113 `maxQuantity` = :maxQuantity,
114 `duration` = :duration,
115 `serviceId` = :serviceId,
116 `aggregatedPrice` = :aggregatedPrice,
117 `position` = :position,
118 `translations` = :translations
119 WHERE id = :id"
120 );
121
122 $result = $statement->execute($params);
123
124 if (!$result) {
125 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
126 }
127
128 return $result;
129 } catch (\Exception $e) {
130 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
131 }
132 }
133 }
134