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 / PackageServiceRepository.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
PackageServiceRepository.php
135 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 public 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 $statement->execute($params);
49 } catch (\Exception $e) {
50 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
51 }
52
53 return $this->connection->lastInsertId();
54 }
55
56 /**
57 * @param int $id
58 * @param PackageService $entity
59 *
60 * @return mixed
61 * @throws QueryExecutionException
62 */
63 public function update($id, $entity)
64 {
65 $data = $entity->toArray();
66
67 $params = [
68 ':quantity' => $data['quantity'],
69 ':minimumScheduled' => $data['minimumScheduled'],
70 ':maximumScheduled' => $data['maximumScheduled'],
71 ':allowProviderSelection' => $data['allowProviderSelection'] ? 1 : 0,
72 ':id' => $id,
73 ':position' => $data['position'],
74 ];
75
76
77 try {
78 $statement = $this->connection->prepare(
79 "UPDATE {$this->table}
80 SET
81 `quantity` = :quantity,
82 `minimumScheduled` = :minimumScheduled,
83 `maximumScheduled` = :maximumScheduled,
84 `allowProviderSelection` = :allowProviderSelection,
85 `position` = :position
86 WHERE
87 id = :id"
88 );
89
90 $statement->execute($params);
91
92 return true;
93 } catch (\Exception $e) {
94 throw new QueryExecutionException('Unable to save data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
95 }
96 }
97
98 /**
99 *
100 * It will delete all relations for one package except ones that are sent in services array
101 *
102 * @param array $servicesIds
103 * @param int $packageId
104 *
105 * @return bool
106 * @throws QueryExecutionException
107 */
108 public function deleteAllNotInServicesArrayForPackage($servicesIds, $packageId)
109 {
110 $services = ' ';
111
112 if (!empty($servicesIds)) {
113 foreach ($servicesIds as $index => $value) {
114 ++$index;
115 $services .= ':serviceId' . $index . ', ';
116 $params[':serviceId' . $index] = (int)$value;
117 }
118 $services = 'AND `serviceId` NOT IN (' . rtrim($services, ', ') . ')';
119 }
120
121 $params[':packageId'] = $packageId;
122
123 try {
124 $statement = $this->connection->prepare(
125 "DELETE FROM {$this->table} WHERE 1 = 1 {$services} AND packageId = :packageId"
126 );
127
128 $statement->execute($params);
129 return true;
130 } catch (\Exception $e) {
131 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
132 }
133 }
134 }
135