src/Controller/Menus/MainController.php line 22
<?phpnamespace App\Controller\Menus;use App\Controller\BaseController;use App\Repository\PropertyRepository;use Detection\MobileDetect;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class MainController extends BaseController{public function __construct(private \App\Repository\MenuRepository $menuRepository,private PropertyRepository $propertyRepository,private \Symfony\Contracts\Translation\TranslatorInterface $translator) {}#[Route('/{_locale<%app.supported_locales%>}/restaurants/{slug}/menus/main', name: 'restaurants.menus.main')]public function index(Request $request): Response{$currentMenu = [];$products = [];$isMobile = false;if (!empty($_SERVER['HTTP_USER_AGENT'])) {$mobileDetect = new MobileDetect();$mobileDetect->setUserAgent($_SERVER['HTTP_USER_AGENT']);$isMobile = $mobileDetect->isMobile();}$returnUrl = $request->get('returnUrl');$returnUrlHost = null;if (!empty($returnUrl)) {$returnUrlHost = parse_url($returnUrl, PHP_URL_HOST);}$capellaPlayHosts = ['www.capellaplay.bg', 'capellaplay.bg'];try {$propertyEntity = $this->propertyRepository->findOneBy(['slug' => $request->get('slug')]);if (empty($propertyEntity)) {throw new \ErrorException($this->translator->trans('Property not found'));}$currentMenuEntity = $this->menuRepository->findOneBy(['property' => $propertyEntity,'type' => 2,]);if (empty($currentMenuEntity)) {throw new \ErrorException($this->translator->trans('Menu not found'));}$customMenuDataDto = $this->menuRepository->getCustomMenuData($currentMenuEntity);$currentMenu = ['id' => $currentMenuEntity->getId(),'name' => $currentMenuEntity->getName(),'fromDate' => $currentMenuEntity->getFromDate()->format('d-m-Y'),'toDate' => $currentMenuEntity->getToDate()->format('d-m-Y'),];foreach ($customMenuDataDto->getProductsArray() as $product) {$productName = ('en' == $this->translator->getLocale()) ? (!empty($product['nameEn']) ? $product['nameEn'] : $product['name']) : $product['name'];$arrTemp = ['id' => $product['id'],'name' => $productName,'nameEn' => $product['nameEn'],'price' => number_format($product['price'], 2, '.', ''),'createDate' => $product['createDate']->format('Y-m-d H:i:s'),'weight' => $product['weight'],'category' => $product['category'],'components' => [],'allergens' => [],];$componentsArr = [];$allergensArr = [];foreach ($customMenuDataDto->getComponentsArray() as $component) {if ($component['toProductID'] == $product['id']) {$componentsArr[] = ['id' => $component[0]['id'],'name' => ('en' == $this->translator->getLocale()) ? (!empty($component[0]['nameEn']) ? $component[0]['nameEn'] : $component[0]['name']) : $component[0]['name'],];}}foreach ($customMenuDataDto->getAllergensArray() as $allergen) {if ($allergen['toProductID'] == $product['id']) {$allergensArr[] = ['id' => $allergen[0]['id'],'name' => ('en' == $this->translator->getLocale()) ? (!empty($allergen[0]['nameEn']) ? $allergen[0]['nameEn'] : $allergen[0]['name']) : $allergen[0]['name'],];}}$arrTemp['components'] = $componentsArr;$arrTemp['allergens'] = $allergensArr;$products[] = $arrTemp;}$currentMenuEntityArray = ['menu' => ['id' => $currentMenuEntity->getId(),'name' => $currentMenuEntity->getName(),'fromDate' => $currentMenuEntity->getFromDate()->format('d.m.Y'),'toDate' => $currentMenuEntity->getToDate()->format('d.m.Y'),'type' => $currentMenuEntity->getType(),],'property' => ['id' => $propertyEntity->getId(),'name' => $propertyEntity->getName(),'address' => $propertyEntity->getAddress(),'phone' => $propertyEntity->getPhone(),'slug' => $propertyEntity->getSlug(),],'returnUrl' => $returnUrl,'returnUrlHost' => $returnUrlHost,'capellaPlayHosts' => $capellaPlayHosts,'currentMenu' => $currentMenu,'products' => $products,'isMobile' => $isMobile,'error' => null,];return $this->render($this->getTemplatePath('menus/main.html.twig'), $currentMenuEntityArray);} catch (\ErrorException $e) {return $this->render($this->getTemplatePath('menus/main.html.twig'), ['menu' => null,'property' => null,'returnUrl' => $returnUrl,'returnUrlHost' => $returnUrlHost,'capellaPlayHosts' => $capellaPlayHosts,'error' => ['message' => $e->getMessage(),],'currentMenu' => $currentMenu,'products' => $products,'isMobile' => $isMobile,]);}}}