PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.3
Booking for Appointments and Events Calendar – Amelia v2.3
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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 / Application / Commands / Entities / GetEntitiesCommandHandler.php
ameliabooking / src / Application / Commands / Entities Last commit date
GetEntitiesCommand.php 1 year ago GetEntitiesCommandHandler.php 4 months ago
GetEntitiesCommandHandler.php
710 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Entities;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Application\Services\Bookable\BookableApplicationService;
9 use AmeliaBooking\Application\Services\Bookable\AbstractPackageApplicationService;
10 use AmeliaBooking\Application\Services\Booking\EventApplicationService;
11 use AmeliaBooking\Application\Services\Coupon\AbstractCouponApplicationService;
12 use AmeliaBooking\Application\Services\CustomField\AbstractCustomFieldApplicationService;
13 use AmeliaBooking\Application\Services\Helper\HelperService;
14 use AmeliaBooking\Application\Services\Location\AbstractLocationApplicationService;
15 use AmeliaBooking\Application\Services\Resource\AbstractResourceApplicationService;
16 use AmeliaBooking\Application\Services\Tax\TaxApplicationService;
17 use AmeliaBooking\Application\Services\User\ProviderApplicationService;
18 use AmeliaBooking\Application\Services\User\UserApplicationService;
19 use AmeliaBooking\Domain\Collection\Collection;
20 use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException;
21 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
22 use AmeliaBooking\Domain\Entity\Bookable\Service\Package;
23 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
24 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
25 use AmeliaBooking\Domain\Entity\Coupon\Coupon;
26 use AmeliaBooking\Domain\Entity\CustomField\CustomField;
27 use AmeliaBooking\Domain\Entity\Entities;
28 use AmeliaBooking\Domain\Entity\User\AbstractUser;
29 use AmeliaBooking\Domain\Entity\User\Customer;
30 use AmeliaBooking\Domain\Entity\User\Provider;
31 use AmeliaBooking\Domain\Services\Booking\EventDomainService;
32 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
33 use AmeliaBooking\Domain\Services\Settings\SettingsService;
34 use AmeliaBooking\Domain\Services\User\ProviderService;
35 use AmeliaBooking\Domain\ValueObjects\String\Status;
36 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
37 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
38 use AmeliaBooking\Infrastructure\Licence\Licence as Licence;
39 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\CategoryRepository;
40 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\PackageRepository;
41 use AmeliaBooking\Infrastructure\Repository\Bookable\Service\ServiceRepository;
42 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\AppointmentRepository;
43 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
44 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
45 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventTagsRepository;
46 use AmeliaBooking\Infrastructure\Repository\Coupon\CouponRepository;
47 use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository;
48 use AmeliaBooking\Infrastructure\Repository\User\UserRepository;
49 use AmeliaBooking\Infrastructure\Services\LessonSpace\AbstractLessonSpaceService;
50 use AmeliaBooking\Infrastructure\Services\Mailchimp\AbstractMailchimpService;
51 use AmeliaBooking\Infrastructure\Services\Payment\SquareService;
52
53 class GetEntitiesCommandHandler extends CommandHandler
54 {
55 /**
56 * @throws AccessDeniedException
57 * @throws InvalidArgumentException
58 * @throws NotFoundException
59 * @throws QueryExecutionException
60 */
61 public function handle(GetEntitiesCommand $command): CommandResult
62 {
63 /** @var UserApplicationService $userAS */
64 $userAS = $this->container->get('application.user.service');
65
66 /** @var EventDomainService $eventDS */
67 $eventDS = $this->container->get('domain.booking.event.service');
68
69 /** @var ProviderApplicationService $providerAS */
70 $providerAS = $this->container->get('application.user.provider.service');
71
72 /** @var AbstractCustomFieldApplicationService $customFieldAS */
73 $customFieldAS = $this->container->get('application.customField.service');
74
75 /** @var AbstractLocationApplicationService $locationAS */
76 $locationAS = $this->container->get('application.location.service');
77
78 /** @var AbstractCouponApplicationService $couponAS */
79 $couponAS = $this->container->get('application.coupon.service');
80
81 /** @var ProviderService $providerService */
82 $providerService = $this->container->get('domain.user.provider.service');
83
84 try {
85 /** @var AbstractUser $currentUser */
86 $currentUser = $command->getUserApplicationService()->authorization(
87 $command->getPage() === 'cabinet' ? $command->getToken() : null,
88 $command->getCabinetType()
89 );
90 } catch (AuthorizationException $e) {
91 $currentUser = null;
92 }
93
94 $params = $command->getField('params');
95
96 $params['types'] = !empty($params['types']) ? $params['types'] : [];
97
98 $result = new CommandResult();
99
100 $this->checkMandatoryFields($command);
101
102 $allServices = new Collection();
103 $services = new Collection();
104 $locations = new Collection();
105 $categories = new Collection();
106 $events = new Collection();
107
108 $resultData = [];
109
110 /** @var SettingsService $settingsDS */
111 $settingsDS = $this->container->get('domain.settings.service');
112
113 $rolesSettings = $settingsDS->getCategorySettings('roles');
114
115 /** Events */
116 if (in_array(Entities::EVENTS, $params['types'], true)) {
117 /** @var EventApplicationService $eventAS */
118 $eventAS = $this->container->get('application.booking.event.service');
119
120 $events = $eventAS->getEventsByCriteria(
121 [
122 'dates' => [DateTimeService::getNowDateTime()],
123 'page' => 1,
124 ],
125 [
126 'fetchEventsPeriods' => true,
127 ],
128 $settingsDS->getSetting('general', 'eventsFilterLimit') ?: 1000
129 );
130
131 $resultData['events'] = $eventDS->getShortcodeForEventList($this->container, $events->toArray());
132 }
133
134 /** Event Tags */
135 if (in_array(Entities::TAGS, $params['types'], true)) {
136 /** @var EventTagsRepository $eventTagsRepository */
137 $eventTagsRepository = $this->container->get('domain.booking.event.tag.repository');
138
139 $eventsTags = $eventTagsRepository->getAllDistinctByCriteria(
140 $events->length() ? ['eventIds' => array_column($events->toArray(), 'id')] : []
141 );
142
143 $resultData['tags'] = $eventsTags->toArray();
144 }
145
146 if (
147 in_array(Entities::LOCATIONS, $params['types'], true) ||
148 in_array(Entities::EMPLOYEES, $params['types'], true)
149 ) {
150 $locations = $locationAS->getAllOrderedByName();
151 }
152
153 /** Locations */
154 if (in_array(Entities::LOCATIONS, $params['types'], true)) {
155 $resultData['locations'] = $locations->toArray();
156 }
157
158 if (
159 in_array(Entities::CATEGORIES, $params['types'], true) ||
160 in_array(Entities::EMPLOYEES, $params['types'], true) ||
161 in_array(Entities::COUPONS, $params['types'], true)
162 ) {
163 /** @var ServiceRepository $serviceRepository */
164 $serviceRepository = $this->container->get('domain.bookable.service.repository');
165 /** @var CategoryRepository $categoryRepository */
166 $categoryRepository = $this->container->get('domain.bookable.category.repository');
167 /** @var BookableApplicationService $bookableAS */
168 $bookableAS = $this->container->get('application.bookable.service');
169
170 $allServices = $serviceRepository->getAllArrayIndexedById();
171
172 /** @var Service $service */
173 foreach ($allServices->getItems() as $service) {
174 if ($settingsDS->isFeatureEnabled('customPricing') === false) {
175 $service->setCustomPricing(null);
176 }
177
178 if (
179 $service->getStatus()->getValue() === Status::VISIBLE ||
180 Licence::isPremium() ||
181 ($currentUser && $currentUser->getType() === AbstractUser::USER_ROLE_ADMIN)
182 ) {
183 $services->addItem($service, $service->getId()->getValue());
184 }
185 }
186
187 $categories = $categoryRepository->getAllIndexedById();
188
189 $bookableAS->addServicesToCategories($categories, $services);
190 }
191
192 /** Categories */
193 if (in_array(Entities::CATEGORIES, $params['types'], true)) {
194 $resultData['categories'] = $categories->toArray();
195 }
196
197
198 $resultData['customers'] = [];
199
200 /** Customers */
201 if (in_array(Entities::CUSTOMERS, $params['types'], true)) {
202 /** @var UserRepository $userRepo */
203 $userRepo = $this->getContainer()->get('domain.users.repository');
204
205 $resultData['customers'] = [];
206
207 if ($currentUser) {
208 switch ($currentUser->getType()) {
209 case (AbstractUser::USER_ROLE_CUSTOMER):
210 if ($currentUser->getId()) {
211 /** @var Customer $customer */
212 $customer = $userRepo->getById($currentUser->getId()->getValue());
213
214 $resultData['customers'] = [$customer->toArray()];
215 }
216
217 break;
218
219 case (AbstractUser::USER_ROLE_PROVIDER):
220 /** @var Collection $customers */
221 $customers = empty($rolesSettings['allowReadAllCustomers'])
222 ? $userRepo->getProviderAllowedCustomers(
223 $currentUser->getId()->getValue()
224 )
225 : $userRepo->getAllWithAllowedBooking();
226
227 $resultData['customers'] = $customers->toArray();
228
229 break;
230
231 default:
232 /** @var Collection $customers */
233 $customers = $userRepo->getAllWithAllowedBooking();
234
235 $resultData['customers'] = $customers->toArray();
236 }
237 }
238
239 $noShowTagEnabled = $settingsDS->isFeatureEnabled('noShowTag');
240
241 if ($noShowTagEnabled && $resultData['customers']) {
242 /** @var CustomerBookingRepository $bookingRepository */
243 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
244
245 $usersIds = array_map(
246 function ($user) {
247 return $user['id'];
248 },
249 $resultData['customers']
250 );
251
252 $customersNoShowCount = $bookingRepository->countByNoShowStatus($usersIds);
253
254 $customersNoShowCount = $customersNoShowCount ? array_values($customersNoShowCount) : [];
255
256 foreach ($resultData['customers'] as $key => $customer) {
257 $resultData['customers'][$key]['noShowCount'] = $customersNoShowCount[$key]['count'];
258 }
259 }
260 }
261
262 /** Providers */
263 if (in_array(Entities::EMPLOYEES, $params['types'], true)) {
264 /** @var ProviderRepository $providerRepository */
265 $providerRepository = $this->container->get('domain.users.providers.repository');
266
267 $providers = $providerRepository->getWithSchedule(
268 [
269 'dates' => !empty($params['dates']) ? $params['dates'] : [
270 DateTimeService::getNowDateTimeObject()->modify('-1 days')->format('Y-m-d H:i:s')
271 ],
272 'fetchCalendars' => $currentUser && $currentUser->getType() === AbstractUser::USER_ROLE_ADMIN,
273 ]
274 );
275
276 /** @var Provider $provider */
277 foreach ($providers->getItems() as $provider) {
278 $providerService->setProviderServices($provider, $services, true);
279 }
280
281 if (
282 array_key_exists('page', $params) &&
283 in_array($params['page'], [Entities::CALENDAR, Entities::APPOINTMENTS]) &&
284 $userAS->isAdminAndAllowedToBookAtAnyTime()
285 ) {
286 $providerService->setProvidersAlwaysAvailable($providers);
287 }
288
289 $resultData['entitiesRelations'] = [];
290
291 /** @var Provider $provider */
292 foreach ($providers->getItems() as $providerId => $provider) {
293 if ($data = $providerAS->getProviderServiceLocations($provider, $locations, $services)) {
294 $resultData['entitiesRelations'][$providerId] = $data;
295 }
296 }
297
298 $resultData['employees'] = $providerAS->removeAllExceptUser(
299 $providers->toArray(),
300 (array_key_exists('page', $params) && $params['page'] === Entities::BOOKING) ?
301 null : $currentUser
302 );
303
304 // Add calendar list to each provider's Google Calendar data
305 $settingsDS->getSetting('general', 'googleCalendar');
306 $googleCalendar = $settingsDS->getSetting('googleCalendar', 'accessToken');
307 $calendarList = [];
308
309 if ($googleCalendar) {
310 try {
311 $googleCalendarMiddlewareService = $this->container->get('infrastructure.google.calendar.middleware.service');
312
313 $accessToken = json_decode($googleCalendar, true);
314 if (is_array($accessToken)) {
315 $calendarList = $googleCalendarMiddlewareService->getCalendarList($accessToken);
316 }
317 } catch (\Throwable $e) {
318 $calendarList = [];
319 }
320 }
321
322 foreach ($resultData['employees'] as &$employee) {
323 if ($employee['googleCalendar'] && $employee['googleCalendar']['token']) {
324 continue;
325 }
326
327 $employee['googleCalendarList'] = $calendarList;
328 }
329
330 $outlookCalendar = $settingsDS->getSetting('outlookCalendar', 'accessToken');
331 $calendarList = [];
332
333 if ($outlookCalendar) {
334 try {
335 $outlookCalendarMiddlewareService = $this->container->get('infrastructure.outlook.calendar.middleware.service');
336
337 $accessToken = json_decode($outlookCalendar, true);
338 if (is_array($accessToken)) {
339 $calendarList = $outlookCalendarMiddlewareService->getCalendarList($accessToken);
340 }
341 } catch (\Throwable $e) {
342 $calendarList = [];
343 }
344 }
345
346 foreach ($resultData['employees'] as &$employee) {
347 if ($employee['outlookCalendar'] && $employee['outlookCalendar']['token']) {
348 continue;
349 }
350
351 $employee['outlookCalendarList'] = $calendarList;
352 }
353
354 if (
355 $currentUser === null ||
356 $currentUser->getType() === AbstractUser::USER_ROLE_CUSTOMER ||
357 !$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES)
358 ) {
359 foreach ($resultData['employees'] as &$employee) {
360 unset(
361 $employee['appleCalendarId'],
362 $employee['googleCalendarId'],
363 $employee['googleCalendar'],
364 $employee['outlookCalendar'],
365 $employee['outlookCalendarId'],
366 $employee['stripeConnect'],
367 $employee['birthday'],
368 $employee['email'],
369 $employee['externalId'],
370 $employee['phone'],
371 $employee['note'],
372 $employee['employeeAppleCalendar'],
373 );
374
375 if (isset($params['page']) && $params['page'] !== Entities::CALENDAR) {
376 unset(
377 $employee['weekDayList'],
378 $employee['specialDayList'],
379 $employee['dayOffList']
380 );
381 }
382 }
383 }
384 }
385
386 $resultData[Entities::APPOINTMENTS] = [
387 'futureAppointments' => [],
388 ];
389
390 if (in_array(Entities::APPOINTMENTS, $params['types'], true)) {
391 $userParams = [
392 'dates' => [null, null]
393 ];
394
395 if (!$command->getPermissionService()->currentUserCanReadOthers(Entities::APPOINTMENTS)) {
396 if ($currentUser->getId() === null) {
397 $userParams[$currentUser->getType() . 'Id'] = 0;
398 } else {
399 $userParams[$currentUser->getType() . 'Id'] =
400 $currentUser->getId()->getValue();
401 }
402 }
403
404 /** @var AppointmentRepository $appointmentRepo */
405 $appointmentRepo = $this->container->get('domain.booking.appointment.repository');
406
407 $appointments = $appointmentRepo->getFiltered($userParams);
408
409 $resultData[Entities::APPOINTMENTS] = [
410 'futureAppointments' => $appointments->toArray(),
411 ];
412 }
413
414 /** Custom Fields */
415 if (
416 in_array(Entities::CUSTOM_FIELDS, $params['types'], true) ||
417 in_array('customFields', $params['types'], true)
418 ) {
419 $customFields = $customFieldAS->getAll();
420
421 if (!empty($params['lite'])) {
422 $resultData['customFields'] = [];
423
424 /** @var CustomField $customField */
425 foreach ($customFields->getItems() as $customField) {
426 $item = array_merge(
427 $customField->toArray(),
428 [
429 'services' => [],
430 'events' => [],
431 ]
432 );
433
434 /** @var Service $service */
435 foreach ($customField->getServices()->getItems() as $service) {
436 $item['services'][] = [
437 'id' => $service->getId()->getValue()
438 ];
439 }
440
441 /** @var Event $event */
442 foreach ($customField->getEvents()->getItems() as $event) {
443 $item['events'][] = [
444 'id' => $event->getId()->getValue()
445 ];
446 }
447
448 $resultData['customFields'][] = $item;
449 }
450 } else {
451 $resultData['customFields'] = $customFields->toArray();
452 }
453 }
454
455 /** Coupons */
456 // Deprecated for backend use; replaced by `/coupons` endpoint.
457 // Retained for public `/entities` route and API access.
458 if (
459 in_array(Entities::COUPONS, $params['types'], true) &&
460 $this->getContainer()->getPermissionsService()->currentUserCanRead(Entities::COUPONS)
461 ) {
462 /** @var CouponRepository $couponRepository */
463 $couponRepository = $this->container->get('domain.coupon.repository');
464
465 /** @var EventRepository $eventRepository */
466 $eventRepository = $this->container->get('domain.booking.event.repository');
467
468 /** @var PackageRepository $packageRepository */
469 $packageRepository = $this->container->get('domain.bookable.package.repository');
470
471 $coupons = $couponRepository->getFiltered(
472 ['page' => 1],
473 100
474 );
475
476 if ($coupons->length()) {
477 foreach ($couponRepository->getCouponsServicesIds($coupons->keys()) as $ids) {
478 /** @var Coupon $coupon */
479 $coupon = $coupons->getItem($ids['couponId']);
480
481 if ($coupon->getAllServices() && $coupon->getAllServices()->getValue()) {
482 $coupon->setServiceList(new Collection($allServices->getItems()));
483 continue;
484 }
485
486 $coupon->getServiceList()->addItem(
487 $allServices->getItem($ids['serviceId']),
488 $ids['serviceId']
489 );
490 }
491
492 $allEvents = $eventRepository->getAllIndexedById();
493
494 foreach ($couponRepository->getCouponsEventsIds($coupons->keys()) as $ids) {
495 /** @var Coupon $coupon */
496 $coupon = $coupons->getItem($ids['couponId']);
497
498 if ($coupon->getAllEvents() && $coupon->getAllEvents()->getValue()) {
499 $coupon->setEventList(new Collection($allEvents->getItems()));
500 continue;
501 }
502
503 if ($allEvents->keyExists($ids['eventId'])) {
504 $coupon->getEventList()->addItem(
505 $allEvents->getItem($ids['eventId']),
506 $ids['eventId']
507 );
508 }
509 }
510
511 $allPackages = $packageRepository->getAllIndexedById();
512
513 foreach ($couponRepository->getCouponsPackagesIds($coupons->keys()) as $ids) {
514 /** @var Coupon $coupon */
515 $coupon = $coupons->getItem($ids['couponId']);
516
517 if ($coupon->getAllPackages() && $coupon->getAllPackages()->getValue()) {
518 $coupon->setPackageList(new Collection($allPackages->getItems()));
519 continue;
520 }
521
522 if ($allPackages->keyExists($ids['packageId'])) {
523 $coupon->getPackageList()->addItem(
524 $allPackages->getItem($ids['packageId']),
525 $ids['packageId']
526 );
527 }
528 }
529 }
530
531 if (!empty($params['lite'])) {
532 $resultData['coupons'] = [];
533
534 /** @var Coupon $coupon */
535 foreach ($coupons->getItems() as $coupon) {
536 $item = array_merge(
537 $coupon->toArray(),
538 [
539 'serviceList' => [],
540 'eventList' => [],
541 'packageList' => [],
542 ]
543 );
544
545 /** @var Service $service */
546 foreach ($coupon->getServiceList()->getItems() as $service) {
547 $item['serviceList'][] = [
548 'id' => $service->getId()->getValue()
549 ];
550 }
551
552 /** @var Event $event */
553 foreach ($coupon->getEventList()->getItems() as $event) {
554 $item['eventList'][] = [
555 'id' => $event->getId()->getValue()
556 ];
557 }
558
559 /** @var Package $package */
560 foreach ($coupon->getPackageList()->getItems() as $package) {
561 $item['packageList'][] = [
562 'id' => $package->getId()->getValue()
563 ];
564 }
565
566 $resultData['coupons'][] = $item;
567 }
568 } else {
569 $resultData['coupons'] = $coupons->toArray();
570 }
571 }
572
573 /** Settings */
574 if (in_array(Entities::SETTINGS, $params['types'], true)) {
575 /** @var HelperService $helperService */
576 $helperService = $this->container->get('application.helper.service');
577
578 $languages = $helperService->getLanguages();
579
580 usort(
581 $languages,
582 function ($x, $y) {
583 return strcasecmp($x['name'], $y['name']);
584 }
585 );
586
587 $languagesSorted = [];
588
589 foreach ($languages as $language) {
590 $languagesSorted[$language['wp_locale']] = $language;
591 }
592
593 /** @var \AmeliaBooking\Application\Services\Settings\SettingsService $settingsAS*/
594 $settingsAS = $this->container->get('application.settings.service');
595
596 $daysOff = $settingsAS->getDaysOff();
597
598 $squareLocations = [];
599 if (
600 !empty($settingsDS->getSetting('payments', 'square')['accessToken']['access_token'])
601 && in_array('squareLocations', $params['types'])
602 ) {
603 /** @var SquareService $squareService */
604 $squareService = $this->container->get('infrastructure.payment.square.service');
605
606 try {
607 $squareLocations = $squareService->getLocations();
608 } catch (\Exception $e) {
609 }
610 }
611
612 $mailchimpLists = [];
613 if (
614 $settingsDS->isFeatureEnabled('mailchimp') &&
615 !empty($settingsDS->getSetting('mailchimp', 'accessToken')) &&
616 in_array('mailchimpLists', $params['types'])
617 ) {
618 /** @var AbstractMailchimpService $mailchimpService */
619 $mailchimpService = $this->container->get('infrastructure.mailchimp.service');
620
621 try {
622 $mailchimpLists = $mailchimpService->getLists();
623
624 $mailchimpSettings = $settingsDS->getCategorySettings('mailchimp');
625 if (!empty($mailchimpLists) && !$mailchimpSettings['list']) {
626 $mailchimpSettings['list'] = $mailchimpLists[0];
627 $settingsDS->setCategorySettings('mailchimp', $mailchimpSettings);
628 }
629 } catch (\Exception $e) {
630 }
631 }
632
633 $resultData['settings'] = [
634 'general' => [
635 'usedLanguages' => $settingsDS->getSetting('general', 'usedLanguages'),
636 ],
637 'languages' => $languagesSorted,
638 'daysOff' => $daysOff,
639 'squareLocations' => $squareLocations,
640 'mailchimpLists' => $mailchimpLists,
641 ];
642 }
643
644 /** Packages */
645 if (in_array(Entities::PACKAGES, $params['types'], true)) {
646 /** @var AbstractPackageApplicationService $packageApplicationService */
647 $packageApplicationService = $this->container->get('application.bookable.package');
648
649 $resultData['packages'] = $packageApplicationService->getPackagesArray();
650 }
651
652 /** Resources */
653 if (in_array(Entities::RESOURCES, $params['types'], true)) {
654 /** @var AbstractResourceApplicationService $resourceApplicationService */
655 $resourceApplicationService = $this->container->get('application.resource.service');
656
657 $resources = $resourceApplicationService->getAll([]);
658
659 $resultData['resources'] = $resources->toArray();
660 }
661
662 /** Taxes */
663 if (in_array(Entities::TAXES, $params['types'], true)) {
664 /** @var TaxApplicationService $taxApplicationService */
665 $taxApplicationService = $this->container->get('application.tax.service');
666
667 $taxes = $taxApplicationService->getAll();
668
669 $resultData['taxes'] = $taxes->toArray();
670 }
671
672 /** Lesson Spaces */
673 if (
674 in_array('lessonSpace_spaces', $params['types'], true) ||
675 in_array('spaces', $params['types'], true)
676 ) {
677 $lessonSpaceApiKey = $settingsDS->getSetting('lessonSpace', 'apiKey');
678 $lessonSpaceEnabled = $settingsDS->getSetting('lessonSpace', 'enabled');
679 $lessonSpaceCompanyId = $settingsDS->getSetting('lessonSpace', 'companyId');
680
681 if ($lessonSpaceEnabled && $lessonSpaceApiKey) {
682 /** @var AbstractLessonSpaceService $lessonSpaceService */
683 $lessonSpaceService = $this->container->get('infrastructure.lesson.space.service');
684
685 if (empty($lessonSpaceCompanyId)) {
686 $companyDetails = $lessonSpaceService->getCompanyId($lessonSpaceApiKey);
687 $lessonSpaceCompanyId = !empty($companyDetails) && !empty($companyDetails['id']) ? $companyDetails['id'] : null;
688 }
689
690 $resultData['spaces'] = $lessonSpaceService->getAllSpaces(
691 $lessonSpaceApiKey,
692 $lessonSpaceCompanyId,
693 !empty($params['lessonSpaceSearch']) ? $params['lessonSpaceSearch'] : null
694 );
695 }
696 }
697
698
699 $resultData = apply_filters('amelia_get_entities_filter', $resultData);
700
701 do_action('amelia_get_entities', $resultData);
702
703 $result->setResult(CommandResult::RESULT_SUCCESS);
704 $result->setMessage('Successfully retrieved entities');
705 $result->setData($resultData);
706
707 return $result;
708 }
709 }
710