PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 months ago
GetEntitiesCommandHandler.php
665 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 if (
316 $currentUser === null ||
317 $currentUser->getType() === AbstractUser::USER_ROLE_CUSTOMER ||
318 !$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES)
319 ) {
320 foreach ($resultData['employees'] as &$employee) {
321 unset(
322 $employee['appleCalendarId'],
323 $employee['googleCalendarId'],
324 $employee['googleCalendar'],
325 $employee['outlookCalendar'],
326 $employee['stripeConnect'],
327 $employee['birthday'],
328 $employee['email'],
329 $employee['externalId'],
330 $employee['phone'],
331 $employee['note'],
332 $employee['employeeAppleCalendar'],
333 );
334
335 if (isset($params['page']) && $params['page'] !== Entities::CALENDAR) {
336 unset(
337 $employee['weekDayList'],
338 $employee['specialDayList'],
339 $employee['dayOffList']
340 );
341 }
342 }
343 }
344 }
345
346 $resultData[Entities::APPOINTMENTS] = [
347 'futureAppointments' => [],
348 ];
349
350 if (in_array(Entities::APPOINTMENTS, $params['types'], true)) {
351 $userParams = [
352 'dates' => [null, null]
353 ];
354
355 if (!$command->getPermissionService()->currentUserCanReadOthers(Entities::APPOINTMENTS)) {
356 if ($currentUser->getId() === null) {
357 $userParams[$currentUser->getType() . 'Id'] = 0;
358 } else {
359 $userParams[$currentUser->getType() . 'Id'] =
360 $currentUser->getId()->getValue();
361 }
362 }
363
364 /** @var AppointmentRepository $appointmentRepo */
365 $appointmentRepo = $this->container->get('domain.booking.appointment.repository');
366
367 $appointments = $appointmentRepo->getFiltered($userParams);
368
369 $resultData[Entities::APPOINTMENTS] = [
370 'futureAppointments' => $appointments->toArray(),
371 ];
372 }
373
374 /** Custom Fields */
375 if (
376 in_array(Entities::CUSTOM_FIELDS, $params['types'], true) ||
377 in_array('customFields', $params['types'], true)
378 ) {
379 $customFields = $customFieldAS->getAll();
380
381 if (!empty($params['lite'])) {
382 $resultData['customFields'] = [];
383
384 /** @var CustomField $customField */
385 foreach ($customFields->getItems() as $customField) {
386 $item = array_merge(
387 $customField->toArray(),
388 [
389 'services' => [],
390 'events' => [],
391 ]
392 );
393
394 /** @var Service $service */
395 foreach ($customField->getServices()->getItems() as $service) {
396 $item['services'][] = [
397 'id' => $service->getId()->getValue()
398 ];
399 }
400
401 /** @var Event $event */
402 foreach ($customField->getEvents()->getItems() as $event) {
403 $item['events'][] = [
404 'id' => $event->getId()->getValue()
405 ];
406 }
407
408 $resultData['customFields'][] = $item;
409 }
410 } else {
411 $resultData['customFields'] = $customFields->toArray();
412 }
413 }
414
415 /** Coupons */
416 if (
417 in_array(Entities::COUPONS, $params['types'], true) &&
418 $this->getContainer()->getPermissionsService()->currentUserCanRead(Entities::COUPONS)
419 ) {
420 $coupons = $couponAS->getAll();
421
422 /** @var CouponRepository $couponRepository */
423 $couponRepository = $this->container->get('domain.coupon.repository');
424
425 /** @var EventRepository $eventRepository */
426 $eventRepository = $this->container->get('domain.booking.event.repository');
427
428 /** @var PackageRepository $packageRepository */
429 $packageRepository = $this->container->get('domain.bookable.package.repository');
430
431 if ($coupons->length()) {
432 foreach ($couponRepository->getCouponsServicesIds($coupons->keys()) as $ids) {
433 /** @var Coupon $coupon */
434 $coupon = $coupons->getItem($ids['couponId']);
435
436 if ($coupon->getAllServices() && $coupon->getAllServices()->getValue()) {
437 $coupon->setServiceList(new Collection($allServices->getItems()));
438 continue;
439 }
440
441 $coupon->getServiceList()->addItem(
442 $allServices->getItem($ids['serviceId']),
443 $ids['serviceId']
444 );
445 }
446
447 $allEvents = $eventRepository->getAllIndexedById();
448
449 foreach ($couponRepository->getCouponsEventsIds($coupons->keys()) as $ids) {
450 /** @var Coupon $coupon */
451 $coupon = $coupons->getItem($ids['couponId']);
452
453 if ($coupon->getAllEvents() && $coupon->getAllEvents()->getValue()) {
454 $coupon->setEventList(new Collection($allEvents->getItems()));
455 continue;
456 }
457
458 if ($allEvents->keyExists($ids['eventId'])) {
459 $coupon->getEventList()->addItem(
460 $allEvents->getItem($ids['eventId']),
461 $ids['eventId']
462 );
463 }
464 }
465
466 $allPackages = $packageRepository->getAllIndexedById();
467
468 foreach ($couponRepository->getCouponsPackagesIds($coupons->keys()) as $ids) {
469 /** @var Coupon $coupon */
470 $coupon = $coupons->getItem($ids['couponId']);
471
472 if ($coupon->getAllPackages() && $coupon->getAllPackages()->getValue()) {
473 $coupon->setPackageList(new Collection($allPackages->getItems()));
474 continue;
475 }
476
477 if ($allPackages->keyExists($ids['packageId'])) {
478 $coupon->getPackageList()->addItem(
479 $allPackages->getItem($ids['packageId']),
480 $ids['packageId']
481 );
482 }
483 }
484 }
485
486 if (!empty($params['lite'])) {
487 $resultData['coupons'] = [];
488
489 /** @var Coupon $coupon */
490 foreach ($coupons->getItems() as $coupon) {
491 $item = array_merge(
492 $coupon->toArray(),
493 [
494 'serviceList' => [],
495 'eventList' => [],
496 'packageList' => [],
497 ]
498 );
499
500 /** @var Service $service */
501 foreach ($coupon->getServiceList()->getItems() as $service) {
502 $item['serviceList'][] = [
503 'id' => $service->getId()->getValue()
504 ];
505 }
506
507 /** @var Event $event */
508 foreach ($coupon->getEventList()->getItems() as $event) {
509 $item['eventList'][] = [
510 'id' => $event->getId()->getValue()
511 ];
512 }
513
514 /** @var Package $package */
515 foreach ($coupon->getPackageList()->getItems() as $package) {
516 $item['packageList'][] = [
517 'id' => $package->getId()->getValue()
518 ];
519 }
520
521 $resultData['coupons'][] = $item;
522 }
523 } else {
524 $resultData['coupons'] = $coupons->toArray();
525 }
526 }
527
528 /** Settings */
529 if (in_array(Entities::SETTINGS, $params['types'], true)) {
530 /** @var HelperService $helperService */
531 $helperService = $this->container->get('application.helper.service');
532
533 $languages = $helperService->getLanguages();
534
535 usort(
536 $languages,
537 function ($x, $y) {
538 return strcasecmp($x['name'], $y['name']);
539 }
540 );
541
542 $languagesSorted = [];
543
544 foreach ($languages as $language) {
545 $languagesSorted[$language['wp_locale']] = $language;
546 }
547
548 /** @var \AmeliaBooking\Application\Services\Settings\SettingsService $settingsAS*/
549 $settingsAS = $this->container->get('application.settings.service');
550
551 $daysOff = $settingsAS->getDaysOff();
552
553 $squareLocations = [];
554 if (
555 !empty($settingsDS->getSetting('payments', 'square')['accessToken']['access_token'])
556 && in_array('squareLocations', $params['types'])
557 ) {
558 /** @var SquareService $squareService */
559 $squareService = $this->container->get('infrastructure.payment.square.service');
560
561 try {
562 $squareLocations = $squareService->getLocations();
563 } catch (\Exception $e) {
564 }
565 }
566
567 $mailchimpLists = [];
568 if (
569 $settingsDS->isFeatureEnabled('mailchimp') &&
570 !empty($settingsDS->getSetting('mailchimp', 'accessToken')) &&
571 in_array('mailchimpLists', $params['types'])
572 ) {
573 /** @var AbstractMailchimpService $mailchimpService */
574 $mailchimpService = $this->container->get('infrastructure.mailchimp.service');
575
576 try {
577 $mailchimpLists = $mailchimpService->getLists();
578
579 $mailchimpSettings = $settingsDS->getCategorySettings('mailchimp');
580 if (!empty($mailchimpLists) && !$mailchimpSettings['list']) {
581 $mailchimpSettings['list'] = $mailchimpLists[0];
582 $settingsDS->setCategorySettings('mailchimp', $mailchimpSettings);
583 }
584 } catch (\Exception $e) {
585 }
586 }
587
588 $resultData['settings'] = [
589 'general' => [
590 'usedLanguages' => $settingsDS->getSetting('general', 'usedLanguages'),
591 ],
592 'languages' => $languagesSorted,
593 'daysOff' => $daysOff,
594 'squareLocations' => $squareLocations,
595 'mailchimpLists' => $mailchimpLists,
596 ];
597 }
598
599 /** Packages */
600 if (in_array(Entities::PACKAGES, $params['types'], true)) {
601 /** @var AbstractPackageApplicationService $packageApplicationService */
602 $packageApplicationService = $this->container->get('application.bookable.package');
603
604 $resultData['packages'] = $packageApplicationService->getPackagesArray();
605 }
606
607 /** Resources */
608 if (in_array(Entities::RESOURCES, $params['types'], true)) {
609 /** @var AbstractResourceApplicationService $resourceApplicationService */
610 $resourceApplicationService = $this->container->get('application.resource.service');
611
612 $resources = $resourceApplicationService->getAll([]);
613
614 $resultData['resources'] = $resources->toArray();
615 }
616
617 /** Taxes */
618 if (in_array(Entities::TAXES, $params['types'], true)) {
619 /** @var TaxApplicationService $taxApplicationService */
620 $taxApplicationService = $this->container->get('application.tax.service');
621
622 $taxes = $taxApplicationService->getAll();
623
624 $resultData['taxes'] = $taxes->toArray();
625 }
626
627 /** Lesson Spaces */
628 if (
629 in_array('lessonSpace_spaces', $params['types'], true) ||
630 in_array('spaces', $params['types'], true)
631 ) {
632 $lessonSpaceApiKey = $settingsDS->getSetting('lessonSpace', 'apiKey');
633 $lessonSpaceEnabled = $settingsDS->getSetting('lessonSpace', 'enabled');
634 $lessonSpaceCompanyId = $settingsDS->getSetting('lessonSpace', 'companyId');
635
636 if ($lessonSpaceEnabled && $lessonSpaceApiKey) {
637 /** @var AbstractLessonSpaceService $lessonSpaceService */
638 $lessonSpaceService = $this->container->get('infrastructure.lesson.space.service');
639
640 if (empty($lessonSpaceCompanyId)) {
641 $companyDetails = $lessonSpaceService->getCompanyId($lessonSpaceApiKey);
642 $lessonSpaceCompanyId = !empty($companyDetails) && !empty($companyDetails['id']) ? $companyDetails['id'] : null;
643 }
644
645 $resultData['spaces'] = $lessonSpaceService->getAllSpaces(
646 $lessonSpaceApiKey,
647 $lessonSpaceCompanyId,
648 !empty($params['lessonSpaceSearch']) ? $params['lessonSpaceSearch'] : null
649 );
650 }
651 }
652
653
654 $resultData = apply_filters('amelia_get_entities_filter', $resultData);
655
656 do_action('amelia_get_entities', $resultData);
657
658 $result->setResult(CommandResult::RESULT_SUCCESS);
659 $result->setMessage('Successfully retrieved entities');
660 $result->setData($resultData);
661
662 return $result;
663 }
664 }
665