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 / PackageServiceProviderRepository.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
PackageServiceProviderRepository.php
89 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 public 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 $statement->execute($params);
45 } catch (\Exception $e) {
46 throw new QueryExecutionException('Unable to add data in ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
47 }
48
49 return $this->connection->lastInsertId();
50 }
51
52 /**
53 *
54 * It will delete all relations for one package service except ones that are sent in providers array
55 *
56 * @param array $providersIds
57 * @param int $packageServiceId
58 *
59 * @return bool
60 * @throws QueryExecutionException
61 */
62 public function deleteAllNotInProvidersServicesArrayForPackage($providersIds, $packageServiceId)
63 {
64 $providers = ' ';
65
66 if (!empty($providersIds)) {
67 foreach ($providersIds as $index => $value) {
68 ++$index;
69 $providers .= ':userId' . $index . ', ';
70 $params[':userId' . $index] = (int)$value;
71 }
72 $providers = 'AND `userId` NOT IN (' . rtrim($providers, ', ') . ')';
73 }
74
75 $params[':packageServiceId'] = $packageServiceId;
76
77 try {
78 $statement = $this->connection->prepare(
79 "DELETE FROM {$this->table} WHERE 1 = 1 {$providers} AND packageServiceId = :packageServiceId"
80 );
81
82 $statement->execute($params);
83 return true;
84 } catch (\Exception $e) {
85 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
86 }
87 }
88 }
89