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