'); if (!$gutenberg && !$block_editor) { return false; } if (self::isClassicEditorPluginActive()) { $editor_option = get_option('classic-editor-replace'); $block_editor_active = array('no-replace', 'block'); return in_array($editor_option, $block_editor_active, true); } // Fix for conflict with Avada - Fusion builder and gutenberg blocks if ( class_exists( 'FusionBuilder' ) && !(isset( $_GET['gutenberg-editor']))){ return false; } return true; } /** * Check if Classic Editor plugin is active * * @return bool */ public static function isClassicEditorPluginActive() { if (!function_exists('is_plugin_active')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('classic-editor/classic-editor.php')) { return true; } return false; } /** * Set Amelia Container * * @param $container */ public static function setContainer($container) { self::$container = $container; } /** * Get entities data for front-end */ public static function getEntitiesData() { return (new self)->getAllEntitiesForGutenbergBlocks(); } /** * Get Entities for Gutenberg blocks */ public function getAllEntitiesForGutenbergBlocks() { try{ self::setContainer(require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php'); /** @var LocationRepository $locationRepository */ $locationRepository = self::$container->get('domain.locations.repository'); $locations = $locationRepository->getAllOrderedByName(); $resultData['locations'] = $locations->toArray(); /** @var ServiceRepository $serviceRepository */ $serviceRepository = self::$container->get('domain.bookable.service.repository'); /** @var CategoryRepository $categoryRepository */ $categoryRepository = self::$container->get('domain.bookable.category.repository'); /** @var BookableApplicationService $bookableAS */ $bookableAS = self::$container->get('application.bookable.service'); $services = $serviceRepository->getAllArrayIndexedById(); $categories = $categoryRepository->getAllIndexedById(); $bookableAS->addServicesToCategories($categories, $services); $resultData['categories'] = $categories->toArray(); $providerRepository = self::$container->get('domain.users.providers.repository'); /** @var ProviderApplicationService $providerAS */ $providerAS = self::$container->get('application.user.provider.service'); $providers = $providerRepository->getByCriteriaWithSchedule([]); $providerServicesData = $providerRepository->getProvidersServices(); foreach ($providerServicesData as $providerKey => $providerServices) { $provider = $providers->getItem($providerKey); $providerServiceList = new Collection(); foreach ((array)$providerServices as $serviceKey => $providerService) { $service = $services->getItem($serviceKey); if ($service && $provider) { $providerServiceList->addItem( ServiceFactory::create(array_merge($service->toArray(), $providerService)), $service->getId()->getValue() ); } } $provider->setServiceList($providerServiceList); } $resultData['employees'] = $providerAS->removeAllExceptCurrentUser($providers->toArray()); $finalData = self::getOnlyCatSerLocEmp($resultData); return ['data'=> $finalData]; } catch (Exception $exception) { return ['data'=> [ 'categories' => [], 'servicesList' => [], 'locations' => [], 'employees' => [] ]]; } } /** * Get only Categories, Services, Employees and Locations for Gutenberg blocks */ public static function getOnlyCatSerLocEmp ($resultData){ $data = []; if ($resultData['categories'] !== []){ for ( $i = 0; $i < count($resultData['categories']); $i++) { $data['categories'][] = [ 'id' => $resultData['categories'][$i]['id'], 'name' => $resultData['categories'][$i]['name'] ]; if ($resultData['categories'][$i]['serviceList'] !== []) { for ($j = 0; $j < count($resultData['categories'][$i]['serviceList']); $j++) { $data['servicesList'][] = [ 'id' => $resultData['categories'][$i]['serviceList'][$j]['id'], 'name' => $resultData['categories'][$i]['serviceList'][$j]['name'] ]; } } else { $data['servicesList'] = []; } } } else { $data['categories'] = []; $data['servicesList'] = []; } if ($resultData['locations'] !== []) { for ( $i = 0; $i < count($resultData['locations']); $i++) { $data['locations'][] = [ 'id' => $resultData['locations'][$i]['id'], 'name' => $resultData['locations'][$i]['name'] ]; } } else { $data['locations'] = []; } if ($resultData['employees'] !== []) { for ( $i = 0; $i < count($resultData['employees']); $i++) { $data['employees'][] = [ 'id' => $resultData['employees'][$i]['id'], 'firstName' => $resultData['employees'][$i]['firstName'], 'lastName' => $resultData['employees'][$i]['lastName'], ]; } } else { $data['employees'] = []; } return $data; } }