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 / Application / Services / Calendar / CalendarProviderService.php
ameliabooking / src / Application / Services / Calendar Last commit date
CalendarProviderService.php 1 month ago
CalendarProviderService.php
78 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Services\Calendar;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Domain\Entity\User\Provider;
7 use AmeliaBooking\Domain\ValueObjects\String\Status;
8 use AmeliaBooking\Infrastructure\Common\Container;
9 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
10 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
11
12 class CalendarProviderService
13 {
14 /** @var Container */
15 private $container;
16
17 public function __construct(Container $container)
18 {
19 $this->container = $container;
20 }
21
22 /**
23 * Returns providers visible in calendar context with the same criteria used by calendar slots.
24 *
25 * @param array $queryParams
26 * @param bool $includeDatesAsRange
27 *
28 * @return Provider[]
29 * @throws InvalidArgumentException
30 * @throws QueryExecutionException
31 */
32 public function getVisibleProviders(array $queryParams, bool $includeDatesAsRange = false): array
33 {
34 $locationRepository = $this->container->get('domain.locations.repository');
35 /** @var ProviderRepository $providerRepository */
36 $providerRepository = $this->container->get('domain.users.providers.repository');
37
38 $queryParams['locations'] = array_map(
39 static fn($location) => $location['id'],
40 $locationRepository->getFiltered(
41 ['status' => !empty($queryParams['providers']) ? null : Status::VISIBLE],
42 0
43 )->toArray()
44 );
45
46 if ($includeDatesAsRange) {
47 $queryParams['dates'] = [$queryParams['calendarStartDate'], $queryParams['calendarEndDate']];
48 }
49
50 $criteria = ['providerStatus' => !empty($queryParams['providers']) ? null : Status::VISIBLE];
51 foreach ($queryParams as $key => $value) {
52 if ($key !== 'providerStatus') {
53 $criteria[$key] = $value;
54 }
55 }
56
57 return $providerRepository->getWithSchedule($criteria)->getItems();
58 }
59
60 /**
61 * @param array $queryParams
62 *
63 * @return int[]
64 * @throws InvalidArgumentException
65 * @throws QueryExecutionException
66 */
67 public function getVisibleProviderIds(array $queryParams): array
68 {
69 $providerIds = [];
70
71 foreach ($this->getVisibleProviders($queryParams, true) as $provider) {
72 $providerIds[] = $provider->getId()->getValue();
73 }
74
75 return $providerIds;
76 }
77 }
78