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 / Bookable / Service / ExtraRepository.php
ameliabooking / src / Infrastructure / Repository / Bookable / Service Last commit date
CategoryRepository.php 3 months ago ExtraRepository.php 3 months ago PackageCustomerRepository.php 1 month ago PackageCustomerServiceRepository.php 2 weeks ago PackageRepository.php 2 months ago PackageServiceLocationRepository.php 3 months ago PackageServiceProviderRepository.php 3 months ago PackageServiceRepository.php 3 months ago ProviderServiceRepository.php 3 months ago ResourceEntitiesRepository.php 3 months ago ResourceRepository.php 3 months ago ServiceRepository.php 2 weeks ago
ExtraRepository.php
126 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 int
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 $statement->execute($params);
70
71 return $this->connection->lastInsertId();
72 } catch (\Exception $e) {
73 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
74 }
75 }
76
77 /**
78 * @param int $id
79 * @param Extra $entity
80 *
81 * @return mixed
82 * @throws QueryExecutionException
83 */
84 public function update($id, $entity)
85 {
86 $data = $entity->toArray();
87
88 $params = [
89 ':name' => $data['name'],
90 ':description' => $data['description'],
91 ':price' => $data['price'],
92 ':maxQuantity' => $data['maxQuantity'],
93 ':duration' => $data['duration'],
94 ':serviceId' => $data['serviceId'],
95 ':aggregatedPrice' => $data['aggregatedPrice'] === null ?
96 $data['aggregatedPrice'] : ((int)$data['aggregatedPrice']),
97 ':position' => $data['position'],
98 ':translations' => $data['translations'],
99 ':id' => $id
100 ];
101
102 try {
103 $statement = $this->connection->prepare(
104 "UPDATE {$this->table}
105 SET
106 `name` = :name,
107 `description` = :description,
108 `price` = :price,
109 `maxQuantity` = :maxQuantity,
110 `duration` = :duration,
111 `serviceId` = :serviceId,
112 `aggregatedPrice` = :aggregatedPrice,
113 `position` = :position,
114 `translations` = :translations
115 WHERE id = :id"
116 );
117
118 $statement->execute($params);
119
120 return true;
121 } catch (\Exception $e) {
122 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
123 }
124 }
125 }
126