PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
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 1 year ago
GetEntitiesCommandHandler.php
667 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 use Interop\Container\Exception\ContainerException;
53
54 /**
55 * Class GetEntitiesCommandHandler
56 *
57 * @package AmeliaBooking\Application\Commands\Entities
58 */
59 class GetEntitiesCommandHandler extends CommandHandler
60 {
61 /**
62 * @param GetEntitiesCommand $command
63 *
64 * @return CommandResult
65 * @throws AccessDeniedException
66 * @throws ContainerException
67 * @throws InvalidArgumentException
68 * @throws NotFoundException
69 * @throws QueryExecutionException
70 */
71 public function handle(GetEntitiesCommand $command)
72 {
73 /** @var UserApplicationService $userAS */
74 $userAS = $this->container->get('application.user.service');
75
76 /** @var EventDomainService $eventDS */
77 $eventDS = $this->container->get('domain.booking.event.service');
78
79 /** @var ProviderApplicationService $providerAS */
80 $providerAS = $this->container->get('application.user.provider.service');
81
82 /** @var AbstractCustomFieldApplicationService $customFieldAS */
83 $customFieldAS = $this->container->get('application.customField.service');
84
85 /** @var AbstractLocationApplicationService $locationAS */
86 $locationAS = $this->container->get('application.location.service');
87
88 /** @var AbstractCouponApplicationService $couponAS */
89 $couponAS = $this->container->get('application.coupon.service');
90
91 /** @var ProviderService $providerService */
92 $providerService = $this->container->get('domain.user.provider.service');
93
94 try {
95 /** @var AbstractUser $currentUser */
96 $currentUser = $command->getUserApplicationService()->authorization(
97 $command->getPage() === 'cabinet' ? $command->getToken() : null,
98 $command->getCabinetType()
99 );
100 } catch (AuthorizationException $e) {
101 $currentUser = null;
102 }
103
104 $params = $command->getField('params');
105
106 $params['types'] = !empty($params['types']) ? $params['types'] : [];
107
108 $result = new CommandResult();
109
110 $this->checkMandatoryFields($command);
111
112 /** @var Collection $allServices */
113 $allServices = new Collection();
114
115 /** @var Collection $services */
116 $services = new Collection();
117
118 /** @var Collection $locations */
119 $locations = new Collection();
120
121 /** @var Collection $categories */
122 $categories = new Collection();
123
124 /** @var Collection $events */
125 $events = new Collection();
126
127 $resultData = [];
128
129 /** @var SettingsService $settingsDS */
130 $settingsDS = $this->container->get('domain.settings.service');
131
132
133 /** Events */
134 if (in_array(Entities::EVENTS, $params['types'], true)) {
135 /** @var EventApplicationService $eventAS */
136 $eventAS = $this->container->get('application.booking.event.service');
137
138 /** @var Collection $events */
139 $events = $eventAS->getEventsByCriteria(
140 [
141 'dates' => [DateTimeService::getNowDateTime()],
142 'page' => 1,
143 ],
144 [
145 'fetchEventsPeriods' => true,
146 ],
147 $settingsDS->getSetting('general', 'eventsFilterLimit') ?: 1000
148 );
149
150 $resultData['events'] = $eventDS->getShortcodeForEventList($this->container, $events->toArray());
151 }
152
153 /** Event Tags */
154 if (in_array(Entities::TAGS, $params['types'], true)) {
155 /** @var EventTagsRepository $eventTagsRepository */
156 $eventTagsRepository = $this->container->get('domain.booking.event.tag.repository');
157
158 /** @var Collection $eventsTags */
159 $eventsTags = $eventTagsRepository->getAllDistinctByCriteria(
160 $events->length() ? ['eventIds' => array_column($events->toArray(), 'id')] : []
161 );
162
163 $resultData['tags'] = $eventsTags->toArray();
164 }
165
166 if (
167 in_array(Entities::LOCATIONS, $params['types'], true) ||
168 in_array(Entities::EMPLOYEES, $params['types'], true)
169 ) {
170 /** @var Collection $locations */
171 $locations = $locationAS->getAllOrderedByName();
172 }
173
174 /** Locations */
175 if (in_array(Entities::LOCATIONS, $params['types'], true)) {
176 $resultData['locations'] = $locations->toArray();
177 }
178
179 if (
180 in_array(Entities::CATEGORIES, $params['types'], true) ||
181 in_array(Entities::EMPLOYEES, $params['types'], true) ||
182 in_array(Entities::COUPONS, $params['types'], true)
183 ) {
184 /** @var ServiceRepository $serviceRepository */
185 $serviceRepository = $this->container->get('domain.bookable.service.repository');
186 /** @var CategoryRepository $categoryRepository */
187 $categoryRepository = $this->container->get('domain.bookable.category.repository');
188 /** @var BookableApplicationService $bookableAS */
189 $bookableAS = $this->container->get('application.bookable.service');
190
191 /** @var Collection $allServices */
192 $allServices = $serviceRepository->getAllArrayIndexedById();
193
194 /** @var Service $service */
195 foreach ($allServices->getItems() as $service) {
196 if (
197 $service->getStatus()->getValue() === Status::VISIBLE ||
198 Licence::$premium ||
199 ($currentUser && $currentUser->getType() === AbstractUser::USER_ROLE_ADMIN)
200 ) {
201 $services->addItem($service, $service->getId()->getValue());
202 }
203 }
204
205 /** @var Collection $categories */
206 $categories = $categoryRepository->getAllIndexedById();
207
208 $bookableAS->addServicesToCategories($categories, $services);
209 }
210
211 /** Categories */
212 if (in_array(Entities::CATEGORIES, $params['types'], true)) {
213 $resultData['categories'] = $categories->toArray();
214 }
215
216
217 $resultData['customers'] = [];
218
219 /** Customers */
220 if (in_array(Entities::CUSTOMERS, $params['types'], true)) {
221 /** @var UserRepository $userRepo */
222 $userRepo = $this->getContainer()->get('domain.users.repository');
223
224 $resultData['customers'] = [];
225
226 if ($currentUser) {
227 switch ($currentUser->getType()) {
228 case (AbstractUser::USER_ROLE_CUSTOMER):
229 if ($currentUser->getId()) {
230 /** @var Customer $customer */
231 $customer = $userRepo->getById($currentUser->getId()->getValue());
232
233 $resultData['customers'] = [$customer->toArray()];
234 }
235
236 break;
237
238 case (AbstractUser::USER_ROLE_PROVIDER):
239 $resultData['customers'] = $providerAS->getAllowedCustomers($currentUser)->toArray();
240
241 break;
242
243 default:
244 /** @var Collection $customers */
245 $customers = $userRepo->getAllWithAllowedBooking();
246
247 $resultData['customers'] = $customers->toArray();
248 }
249 }
250
251 $noShowTagEnabled = $settingsDS->getSetting('roles', 'enableNoShowTag');
252
253 if ($noShowTagEnabled && $resultData['customers']) {
254 /** @var CustomerBookingRepository $bookingRepository */
255 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
256
257 $usersIds = array_map(
258 function ($user) {
259 return $user['id'];
260 },
261 $resultData['customers']
262 );
263
264 $customersNoShowCount = $bookingRepository->countByNoShowStatus($usersIds);
265
266 foreach ($resultData['customers'] as $key => $customer) {
267 $resultData['customers'][$key]['noShowCount'] = $customersNoShowCount[$key]['count'];
268 }
269 }
270 }
271
272 /** Providers */
273 if (in_array(Entities::EMPLOYEES, $params['types'], true)) {
274 /** @var ProviderRepository $providerRepository */
275 $providerRepository = $this->container->get('domain.users.providers.repository');
276
277 /** @var Collection $providers */
278 $providers = $providerRepository->getWithSchedule(
279 [
280 'dates' => !empty($params['dates']) ? $params['dates'] : [
281 DateTimeService::getNowDateTimeObject()->modify('-1 days')->format('Y-m-d H:i:s')
282 ],
283 'fetchCalendars' => $currentUser && $currentUser->getType() === AbstractUser::USER_ROLE_ADMIN,
284 ]
285 );
286
287 /** @var Provider $provider */
288 foreach ($providers->getItems() as $provider) {
289 $providerService->setProviderServices($provider, $services, true);
290 }
291
292 if (
293 array_key_exists('page', $params) &&
294 in_array($params['page'], [Entities::CALENDAR, Entities::APPOINTMENTS]) &&
295 $userAS->isAdminAndAllowedToBookAtAnyTime()
296 ) {
297 $providerService->setProvidersAlwaysAvailable($providers);
298 }
299
300 $resultData['entitiesRelations'] = [];
301
302 /** @var Provider $provider */
303 foreach ($providers->getItems() as $providerId => $provider) {
304 if ($data = $providerAS->getProviderServiceLocations($provider, $locations, $services)) {
305 $resultData['entitiesRelations'][$providerId] = $data;
306 }
307 }
308
309
310 $resultData['employees'] = $providerAS->removeAllExceptUser(
311 $providers->toArray(),
312 (array_key_exists('page', $params) && $params['page'] === Entities::BOOKING) ?
313 null : $currentUser
314 );
315
316 if (
317 $currentUser === null ||
318 $currentUser->getType() === AbstractUser::USER_ROLE_CUSTOMER ||
319 !$command->getPermissionService()->currentUserCanRead(Entities::EMPLOYEES)
320 ) {
321 foreach ($resultData['employees'] as &$employee) {
322 unset(
323 $employee['appleCalendarId'],
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 /** @var Collection $appointments */
368 $appointments = $appointmentRepo->getFiltered($userParams);
369
370 $resultData[Entities::APPOINTMENTS] = [
371 'futureAppointments' => $appointments->toArray(),
372 ];
373 }
374
375 /** Custom Fields */
376 if (
377 in_array(Entities::CUSTOM_FIELDS, $params['types'], true) ||
378 in_array('customFields', $params['types'], true)
379 ) {
380 /** @var Collection $customFields */
381 $customFields = $customFieldAS->getAll();
382
383 if (!empty($params['lite'])) {
384 $resultData['customFields'] = [];
385
386 /** @var CustomField $customField */
387 foreach ($customFields->getItems() as $customField) {
388 $item = array_merge(
389 $customField->toArray(),
390 [
391 'services' => [],
392 'events' => [],
393 ]
394 );
395
396 /** @var Service $service */
397 foreach ($customField->getServices()->getItems() as $service) {
398 $item['services'][] = [
399 'id' => $service->getId()->getValue()
400 ];
401 }
402
403 /** @var Event $event */
404 foreach ($customField->getEvents()->getItems() as $event) {
405 $item['events'][] = [
406 'id' => $event->getId()->getValue()
407 ];
408 }
409
410 $resultData['customFields'][] = $item;
411 }
412 } else {
413 $resultData['customFields'] = $customFields->toArray();
414 }
415 }
416
417 /** Coupons */
418 if (
419 in_array(Entities::COUPONS, $params['types'], true) &&
420 $this->getContainer()->getPermissionsService()->currentUserCanRead(Entities::COUPONS)
421 ) {
422 /** @var Collection $coupons */
423 $coupons = $couponAS->getAll();
424
425 /** @var CouponRepository $couponRepository */
426 $couponRepository = $this->container->get('domain.coupon.repository');
427
428 /** @var EventRepository $eventRepository */
429 $eventRepository = $this->container->get('domain.booking.event.repository');
430
431 /** @var PackageRepository $packageRepository */
432 $packageRepository = $this->container->get('domain.bookable.package.repository');
433
434 if ($coupons->length()) {
435 foreach ($couponRepository->getCouponsServicesIds($coupons->keys()) as $ids) {
436 /** @var Coupon $coupon */
437 $coupon = $coupons->getItem($ids['couponId']);
438
439 if ($coupon->getAllServices() && $coupon->getAllServices()->getValue()) {
440 $coupon->setServiceList(new Collection($allServices->getItems()));
441 continue;
442 }
443
444 $coupon->getServiceList()->addItem(
445 $allServices->getItem($ids['serviceId']),
446 $ids['serviceId']
447 );
448 }
449
450 /** @var Collection $allEvents */
451 $allEvents = $eventRepository->getAllIndexedById();
452
453 foreach ($couponRepository->getCouponsEventsIds($coupons->keys()) as $ids) {
454 /** @var Coupon $coupon */
455 $coupon = $coupons->getItem($ids['couponId']);
456
457 if ($coupon->getAllEvents() && $coupon->getAllEvents()->getValue()) {
458 $coupon->setEventList(new Collection($allEvents->getItems()));
459 continue;
460 }
461
462 $coupon->getEventList()->addItem(
463 $allEvents->getItem($ids['eventId']),
464 $ids['eventId']
465 );
466 }
467
468 /** @var Collection $allPackages */
469 $allPackages = $packageRepository->getAllIndexedById();
470
471 foreach ($couponRepository->getCouponsPackagesIds($coupons->keys()) as $ids) {
472 /** @var Coupon $coupon */
473 $coupon = $coupons->getItem($ids['couponId']);
474
475 if ($coupon->getAllPackages() && $coupon->getAllPackages()->getValue()) {
476 $coupon->setPackageList(new Collection($allPackages->getItems()));
477 continue;
478 }
479
480 $coupon->getPackageList()->addItem(
481 $allPackages->getItem($ids['packageId']),
482 $ids['packageId']
483 );
484 }
485 }
486
487 if (!empty($params['lite'])) {
488 $resultData['coupons'] = [];
489
490 /** @var Coupon $coupon */
491 foreach ($coupons->getItems() as $coupon) {
492 $item = array_merge(
493 $coupon->toArray(),
494 [
495 'serviceList' => [],
496 'eventList' => [],
497 'packageList' => [],
498 ]
499 );
500
501 /** @var Service $service */
502 foreach ($coupon->getServiceList()->getItems() as $service) {
503 $item['serviceList'][] = [
504 'id' => $service->getId()->getValue()
505 ];
506 }
507
508 /** @var Event $event */
509 foreach ($coupon->getEventList()->getItems() as $event) {
510 $item['eventList'][] = [
511 'id' => $event->getId()->getValue()
512 ];
513 }
514
515 /** @var Package $package */
516 foreach ($coupon->getPackageList()->getItems() as $package) {
517 $item['packageList'][] = [
518 'id' => $package->getId()->getValue()
519 ];
520 }
521
522 $resultData['coupons'][] = $item;
523 }
524 } else {
525 $resultData['coupons'] = $coupons->toArray();
526 }
527 }
528
529 /** Settings */
530 if (in_array(Entities::SETTINGS, $params['types'], true)) {
531 /** @var HelperService $helperService */
532 $helperService = $this->container->get('application.helper.service');
533
534 $languages = $helperService->getLanguages();
535
536 usort(
537 $languages,
538 function ($x, $y) {
539 return strcasecmp($x['name'], $y['name']);
540 }
541 );
542
543 $languagesSorted = [];
544
545 foreach ($languages as $language) {
546 $languagesSorted[$language['wp_locale']] = $language;
547 }
548
549 /** @var \AmeliaBooking\Application\Services\Settings\SettingsService $settingsAS*/
550 $settingsAS = $this->container->get('application.settings.service');
551
552 $daysOff = $settingsAS->getDaysOff();
553
554 $squareLocations = [];
555 if (
556 !empty($settingsDS->getSetting('payments', 'square')['accessToken']['access_token'])
557 && in_array('squareLocations', $params['types'])
558 ) {
559 /** @var SquareService $squareService */
560 $squareService = $this->container->get('infrastructure.payment.square.service');
561
562 try {
563 $squareLocations = $squareService->getLocations();
564 } catch (\Exception $e) {
565 }
566 }
567
568 $mailchimpLists = [];
569 if (
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 /** @var Collection $resources */
613 $resources = $resourceApplicationService->getAll([]);
614
615 $resultData['resources'] = $resources->toArray();
616 }
617
618 /** Taxes */
619 if (in_array(Entities::TAXES, $params['types'], true)) {
620 /** @var TaxApplicationService $taxApplicationService */
621 $taxApplicationService = $this->container->get('application.tax.service');
622
623 /** @var Collection $taxes */
624 $taxes = $taxApplicationService->getAll();
625
626 $resultData['taxes'] = $taxes->toArray();
627 }
628
629 /** Lesson Spaces */
630 if (
631 in_array('lessonSpace_spaces', $params['types'], true) ||
632 in_array('spaces', $params['types'], true)
633 ) {
634 $lessonSpaceApiKey = $settingsDS->getSetting('lessonSpace', 'apiKey');
635 $lessonSpaceEnabled = $settingsDS->getSetting('lessonSpace', 'enabled');
636 $lessonSpaceCompanyId = $settingsDS->getSetting('lessonSpace', 'companyId');
637
638 if ($lessonSpaceEnabled && $lessonSpaceApiKey) {
639 /** @var AbstractLessonSpaceService $lessonSpaceService */
640 $lessonSpaceService = $this->container->get('infrastructure.lesson.space.service');
641
642 if (empty($lessonSpaceCompanyId)) {
643 $companyDetails = $lessonSpaceService->getCompanyId($lessonSpaceApiKey);
644 $lessonSpaceCompanyId = !empty($companyDetails) && !empty($companyDetails['id']) ? $companyDetails['id'] : null;
645 }
646
647 $resultData['spaces'] = $lessonSpaceService->getAllSpaces(
648 $lessonSpaceApiKey,
649 $lessonSpaceCompanyId,
650 !empty($params['lessonSpaceSearch']) ? $params['lessonSpaceSearch'] : null
651 );
652 }
653 }
654
655
656 $resultData = apply_filters('amelia_get_entities_filter', $resultData);
657
658 do_action('amelia_get_entities', $resultData);
659
660 $result->setResult(CommandResult::RESULT_SUCCESS);
661 $result->setMessage('Successfully retrieved entities');
662 $result->setData($resultData);
663
664 return $result;
665 }
666 }
667