PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / PackageServiceProviderRepository.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 1 year ago ResourceEntitiesRepository.php 2 years ago ResourceRepository.php 2 years ago ServiceRepository.php 2 years ago
PackageServiceProviderRepository.php
91 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Bookable\Service;
4
5 use AmeliaBooking\Domain\Entity\Location\Location;
6 use AmeliaBooking\Domain\Entity\User\Provider;
7 use AmeliaBooking\Domain\Factory\Bookable\Service\PackageServiceFactory;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10
11 /**
12 * Class PackageServiceProviderRepository
13 *
14 * @package AmeliaBooking\Infrastructure\Repository\Bookable\Service
15 */
16 class PackageServiceProviderRepository extends AbstractRepository
17 {
18 const FACTORY = PackageServiceFactory::class;
19
20 /**
21 * @param Provider $entity
22 * @param int $packageServiceId
23 *
24 * @return int
25 * @throws QueryExecutionException
26 */
27 public function add($entity, $packageServiceId)
28 {
29 $data = $entity->toArray();
30
31 $params = [
32 ':packageServiceId' => $packageServiceId,
33 ':userId' => $data['id'],
34 ];
35
36 try {
37 $statement = $this->connection->prepare(
38 "INSERT INTO {$this->table}
39 (`packageServiceId`, `userId`)
40 VALUES
41 (:packageServiceId, :userId)"
42 );
43
44 $res = $statement->execute($params);
45 if (!$res) {
46 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
47 }
48 } catch (\Exception $e) {
49 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
50 }
51
52 return $this->connection->lastInsertId();
53 }
54
55 /**
56 *
57 * It will delete all relations for one package service except ones that are sent in providers array
58 *
59 * @param array $providersIds
60 * @param int $packageServiceId
61 *
62 * @return bool
63 * @throws QueryExecutionException
64 */
65 public function deleteAllNotInProvidersServicesArrayForPackage($providersIds, $packageServiceId)
66 {
67 $providers = ' ';
68
69 if (!empty($providersIds)) {
70 foreach ($providersIds as $index => $value) {
71 ++$index;
72 $providers .= ':userId' . $index . ', ';
73 $params[':userId' . $index] = (int)$value;
74 }
75 $providers = 'AND `userId` NOT IN (' . rtrim($providers, ', ') . ')';
76 }
77
78 $params[':packageServiceId'] = $packageServiceId;
79
80 try {
81 $statement = $this->connection->prepare(
82 "DELETE FROM {$this->table} WHERE 1 = 1 {$providers} AND packageServiceId = :packageServiceId"
83 );
84
85 return $statement->execute($params);
86 } catch (\Exception $e) {
87 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
88 }
89 }
90 }
91