PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.11
Booking for Appointments and Events Calendar – Amelia v1.2.11
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 / PackageServiceRepository.php
ameliabooking / src / Infrastructure / Repository / Bookable / Service Last commit date
CategoryRepository.php 2 years ago ExtraRepository.php 5 years ago PackageCustomerRepository.php 1 year ago PackageCustomerServiceRepository.php 1 year ago PackageRepository.php 2 years ago PackageServiceLocationRepository.php 5 years ago PackageServiceProviderRepository.php 5 years ago PackageServiceRepository.php 2 years ago ProviderServiceRepository.php 2 years ago ResourceEntitiesRepository.php 2 years ago ResourceRepository.php 2 years ago ServiceRepository.php 2 years ago
PackageServiceRepository.php
141 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Bookable\Service;
4
5 use AmeliaBooking\Domain\Entity\Bookable\Service\PackageService;
6 use AmeliaBooking\Domain\Factory\Bookable\Service\PackageServiceFactory;
7 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
8 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
9
10 /**
11 * Class PackageServiceRepository
12 *
13 * @package AmeliaBooking\Infrastructure\Repository\Bookable\Service
14 */
15 class PackageServiceRepository extends AbstractRepository
16 {
17 const FACTORY = PackageServiceFactory::class;
18
19 /**
20 * @param PackageService $entity
21 * @param int $packageId
22 *
23 * @return int
24 * @throws QueryExecutionException
25 */
26 public function add($entity, $packageId)
27 {
28 $data = $entity->toArray();
29
30 $params = [
31 ':packageId' => $packageId,
32 ':serviceId' => $data['service']['id'],
33 ':quantity' => $data['quantity'],
34 ':minimumScheduled' => $data['minimumScheduled'],
35 ':maximumScheduled' => $data['maximumScheduled'],
36 ':allowProviderSelection' => $data['allowProviderSelection'] ? 1 : 0,
37 ':position' => $data['position']
38 ];
39
40 try {
41 $statement = $this->connection->prepare(
42 "INSERT INTO {$this->table}
43 (`packageId`, `serviceId`, `quantity`, `minimumScheduled`, `maximumScheduled`, `allowProviderSelection`, `position`)
44 VALUES
45 (:packageId, :serviceId, :quantity, :minimumScheduled, :maximumScheduled, :allowProviderSelection, :position)"
46 );
47
48 $res = $statement->execute($params);
49 if (!$res) {
50 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
51 }
52 } catch (\Exception $e) {
53 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
54 }
55
56 return $this->connection->lastInsertId();
57 }
58
59 /**
60 * @param int $id
61 * @param PackageService $entity
62 *
63 * @return mixed
64 * @throws QueryExecutionException
65 */
66 public function update($id, $entity)
67 {
68 $data = $entity->toArray();
69
70 $params = [
71 ':quantity' => $data['quantity'],
72 ':minimumScheduled' => $data['minimumScheduled'],
73 ':maximumScheduled' => $data['maximumScheduled'],
74 ':allowProviderSelection' => $data['allowProviderSelection'] ? 1 : 0,
75 ':id' => $id,
76 ':position' => $data['position'],
77 ];
78
79
80 try {
81 $statement = $this->connection->prepare(
82 "UPDATE {$this->table}
83 SET
84 `quantity` = :quantity,
85 `minimumScheduled` = :minimumScheduled,
86 `maximumScheduled` = :maximumScheduled,
87 `allowProviderSelection` = :allowProviderSelection,
88 `position` = :position
89 WHERE
90 id = :id"
91 );
92
93 $result = $statement->execute($params);
94
95 if (!$result) {
96 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
97 }
98
99 return $result;
100 } catch (\Exception $e) {
101 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
102 }
103 }
104
105 /**
106 *
107 * It will delete all relations for one package except ones that are sent in services array
108 *
109 * @param array $servicesIds
110 * @param int $packageId
111 *
112 * @return bool
113 * @throws QueryExecutionException
114 */
115 public function deleteAllNotInServicesArrayForPackage($servicesIds, $packageId)
116 {
117 $services = ' ';
118
119 if (!empty($servicesIds)) {
120 foreach ($servicesIds as $index => $value) {
121 ++$index;
122 $services .= ':serviceId' . $index . ', ';
123 $params[':serviceId' . $index] = (int)$value;
124 }
125 $services = 'AND `serviceId` NOT IN (' . rtrim($services, ', ') . ')';
126 }
127
128 $params[':packageId'] = $packageId;
129
130 try {
131 $statement = $this->connection->prepare(
132 "DELETE FROM {$this->table} WHERE 1 = 1 {$services} AND packageId = :packageId"
133 );
134
135 return $statement->execute($params);
136 } catch (\Exception $e) {
137 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
138 }
139 }
140 }
141