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