src/Controller/ConventionController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\CanonicalRedirectHelper;
  4. use App\Twig\LinkGenerator;
  5. use Carbon\Carbon;
  6. use Elements\Bundle\CmsToolsBundle\Tool\Helper\FunctionsHelper;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Pimcore\Model\DataObject\ConventionIncentive;
  9. use Pimcore\Model\DataObject\ConventionPartner;
  10. use Pimcore\Model\DataObject\ConventionPartnerCategory;
  11. use Pimcore\Model\DataObject\DemiInfrastructure;
  12. use Pimcore\Model\DataObject\DemiInfrastructureTopic;
  13. use Pimcore\Model\DataObject\Region;
  14. use Pimcore\Model\DataObject\SiteConfig;
  15. use Pimcore\Model\WebsiteSetting;
  16. use Pimcore\Translation\Translator;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class ConventionController extends AbstractController
  23. {
  24.     /**
  25.      * @var LinkGenerator
  26.      */
  27.     private $linkGenerator;
  28.     /**
  29.      * @var array
  30.      */
  31.     private array $mapIds = [];
  32.     private Translator $translator;
  33.     public function __construct(  LinkGenerator $linkGeneratorTranslator $translator)
  34.     {
  35.         $this->linkGenerator $linkGenerator;
  36.         $this->translator $translator;
  37.     }
  38.     public function portalAction(): ?\Symfony\Component\HttpFoundation\Response
  39.     {
  40.         return $this->render("Convention/portal.html.twig");
  41.     }
  42.     public function conventionIncentiveDetailAction(Request $requestLinkGenerator $linkGeneratorCanonicalRedirectHelper $redirectHelper) {
  43.         $incentive ConventionIncentive::getById($request->get('id'0));
  44.         if (!$incentive || !$incentive->isPublished()){
  45.             throw new NotFoundHttpException("the requested object doesn't exist anymore");
  46.         }
  47.         if (CanonicalRedirectHelper::ENABLE_CANONICAL_REDIRECT && $redirect $redirectHelper->canonicalRedirect($incentive)) {
  48.             return $redirect;
  49.         }
  50.         $formSendData = [];
  51.         if ($request->get('isSend'0) && $request->getMethod() == 'POST' ) {
  52.             $formSendData $this->sendContactRequest($request, [$incentive]);
  53.             if($formSendData && $formSendData['redirect']) {
  54.                 return $formSendData['redirect'];
  55.             }
  56.         }
  57.         $partnerTeaser $this->getRandomPartnerForTeaser($incentive$linkGenerator);
  58.         return $this->renderTemplate('Convention/conventionIncentiveDetail.html.twig', [
  59.             'incentive' => $incentive,
  60.             'partnerTeaser' => $partnerTeaser,
  61.             'formSendData' => $formSendData
  62.         ]);
  63.     }
  64.     public function conventionPartnerDetailAction(Request $requestLinkGenerator $linkGeneratorCanonicalRedirectHelper $redirectHelper) {
  65.         $convention ConventionPartner::getById($request->get('id'0));
  66.         if (!$convention || !$convention->isPublished()){
  67.             throw new NotFoundHttpException("the requested object doesn't exist anymore");
  68.         }
  69.         if (CanonicalRedirectHelper::ENABLE_CANONICAL_REDIRECT && $redirect $redirectHelper->canonicalRedirect($convention)) {
  70.             return $redirect;
  71.         }
  72.         $formSendData = [];
  73.         if ($request->get('isSend'0) && $request->getMethod() == 'POST' ) {
  74.             $formSendData $this->sendContactRequest($request, [$convention]);
  75.             if($formSendData && $formSendData['redirect']) {
  76.                 return $formSendData['redirect'];
  77.             }
  78.         }
  79.         $info $this->prepareInfoblocks($convention);
  80.         $incentiveTeaser $this->getRandomIncentivesForTeaser($convention$linkGenerator);
  81.         $demiInfrastructure $this->getDemiInfrastructureTeasers($convention$linkGenerator);
  82.         return $this->renderTemplate('Convention/conventionPartnerDetail.html.twig', [
  83.             'convention' => $convention,
  84.             'info' => $info,
  85.             'incentiveTeaser' => $incentiveTeaser,
  86.             'demiInfrastructure' => $demiInfrastructure,
  87.             'formSendData' => $formSendData
  88.         ]);
  89.     }
  90.     public function eventplannerAction(Request $requestPaginatorInterface $paginator): JsonResponse|\Symfony\Component\HttpFoundation\Response
  91.     {
  92.         $conventionCategories = new ConventionPartnerCategory\Listing();
  93.         $conventionCategories->addConditionParam("notShowInEventplannerFilter is null or notShowInEventplannerFilter = 0");
  94.         $excludedIds $this->getExcludedConventionCategoryIds();
  95.         $conventionPartners = new ConventionPartner\Listing();
  96.         //if locations use category => default every category
  97.         $partnerId null;
  98.         if(($partnerId $request->get('convention-partner')) && $request->get('convention-partner') != 'locations') {
  99.             $conventionPartners->addConditionParam('partnerType__id = :partnerId', ['partnerId' => (int)$partnerId]);
  100.         }
  101.         if(!empty($excludedIds)) {
  102.             $conventionPartners->addConditionParam("partnerType__id NOT IN (" implode(","$excludedIds) . ")");
  103.         }
  104.         $location null;
  105.         if($partnerId == 'locations') {
  106. //            if($location = $request->get('location')) {
  107. //                $conventionPartners->addConditionParam('', ['locations' => $location]);
  108. //            }
  109.             if($category $request->get('category')) {
  110.                 $conventionPartners->addConditionParam('partnerType__id = :category', ['category' => (int)$category]);
  111.             }
  112.             if($q $request->get('keyword')) {
  113.                 $conventionPartners->addConditionParam('name like :q or contactName like :q or city like :q or street like :q or zip like :q or firstname like :q or lastname like :q', ['q' => '%' $q '%']);
  114.             }
  115.             $partnerIds $this->checkCapacityAndSaalStyle($conventionPartners$request);
  116.             if(!empty($partnerIds)) {
  117.                 $conventionPartners->addConditionParam('o_id IN (' implode(','$partnerIds) . ')');
  118.             }
  119.             if($seminarrooms $request->get('seminarrooms')) {
  120.                 $conventionPartners->addConditionParam("length(saele) - length(replace(saele, ',', '')) > :seminarrooms", ['seminarrooms' => $seminarrooms]);
  121.             }
  122.             if($rooms $request->get('rooms')) {
  123.                 $conventionPartners->addConditionParam("roomCount >= :rooms", ['rooms' => (int)$rooms]);
  124.             }
  125.             if($request->get('pkw-checkbox')) {
  126.                 $conventionPartners->addConditionParam("pkwReachable = 1");
  127.             }
  128.         }
  129.         $preparedCategories $this->getConventionCategoriesSelect($conventionCategories$partnerId);
  130.         if ($request->isXmlHttpRequest() && $request->get('pois'false)) {
  131.             return $this->getMapdata($conventionPartners);
  132.         }
  133.         $numTeaser = (int)$this->getDocumentEditable('numeric''teaserPerPage')->getData();
  134.         if($numTeaser 4) {
  135.             $numTeaser 8;
  136.         }
  137.         $pagination $paginator->paginate($conventionPartners$request->get('page'1), $numTeaser);
  138. //        $pagination->setPageRange(5); is default
  139.         if($request->get('ajax') && $request->isXmlHttpRequest() && !$request->get('pois')) {
  140.             $response =[
  141.                 "success" => true,
  142.                 "content" => [
  143.                     'result-main' => $this->render('Convention/Includes/eventplanner-list.html.twig', [
  144.                         'items' => $pagination,
  145.                     ])->getContent(),
  146.                     'result-paging' => $this->renderView('Navigation/paging.html.twig', [
  147.                         'styleModifier' => 'justify-content-center',
  148.                         'ajaxClass' => 'js-ajax-form-map__link',
  149.                         'ajaxPaging' => true,
  150.                         'paginator' => $pagination
  151.                     ]),
  152.                     'result-paging2' => $this->renderView('Navigation/paging.html.twig', [
  153.                         'styleModifier' => 'justify-content-center',
  154.                         'ajaxClass' => 'js-ajax-form-map__link',
  155.                         'ajaxPaging' => true,
  156.                         'paginator' => $pagination
  157.                     ]),
  158.                 ],
  159.             ];
  160.             return new JsonResponse($response);
  161.         }
  162.         $activeWishlistIds array_values(array_map('intval'$request->getSession()->get('wishlistIds', [])));
  163.         return $this->renderTemplate('Convention/eventplanner.html.twig', [
  164.             'partners' => $conventionPartners,
  165.             'conventionCategories' => $conventionCategories,
  166.             'conventionCategoriesSelect' => $preparedCategories['select'],
  167.             'conventionAllCategoriesSelect' => $preparedCategories['selectAll'],
  168.             'locationCategories' => $preparedCategories['locations'],
  169.             'paginator' => $pagination,
  170.             'regionSelect' => [], //$this->getRegionSelectData($location),
  171.             'partnerId' => $partnerId,
  172.             'activeWishlistIds' => $activeWishlistIds
  173.         ]);
  174.     }
  175.     public function conventionFormAction(Request $request) {
  176.         $partnerId $request->get('convention-partner'null);
  177.         $location $request->get('location'null);
  178.         if ($request->getMethod() == 'POST') {
  179.             $formSendData $this->processContactForm($request);
  180.             if($formSendData && $formSendData['redirect']) {
  181.                 return $formSendData['redirect'];
  182.             }
  183.         }
  184.         $conventionCategories = new ConventionPartnerCategory\Listing();
  185.         $preparedCategories $this->getConventionCategoriesSelect($conventionCategories$partnerId);
  186.         return $this->renderTemplate('Convention/conventionForm.html.twig', [
  187.             'conventionCategoriesSelect' => $preparedCategories['select'],
  188.             'regionSelect' => $this->getRegionSelectData($location),
  189.             'conventionAllCategoriesSelect' => $preparedCategories['selectAll'],
  190.             'params' => $request->request->all() ?? [],
  191.         ]);
  192.     }
  193.     public function wishlistEnquiryAction(Request $request) {
  194.         if($request->get('removeAllFromWishlist') !== null) {
  195.             $request->getSession()->set('wishlistIds', []);
  196.         }
  197.         $sessionIds $request->getSession()->get('wishlistIds', []);
  198.         $partners = [];
  199.         if(!empty($sessionIds)) {
  200.             foreach ($sessionIds as $id) {
  201.                 if($partner ConventionPartner::getById($id)) {
  202.                     $partners[] = $partner;
  203.                 }
  204.             }
  205.         }
  206.         if ($request->get('isSend'0) && $request->getMethod() == 'POST' ) {
  207.             $conventions = [];
  208.             foreach($request->get('pool-enquiries') as $enquiry) {
  209.                 if($convention ConventionPartner::getById($enquiry)) {
  210.                     $conventions[] = $convention;
  211.                 }
  212.             }
  213.             $formSendData $this->sendContactRequest($request$conventions);
  214.             if($formSendData && $formSendData['redirect']) {
  215.                 return $formSendData['redirect'];
  216.             }
  217.         }
  218.         return $this->renderTemplate('Convention/wishlistEnquiry.html.twig', [
  219.             'partners' => $partners,
  220.         ]);
  221.     }
  222.     public function incentivesOverviewAction(Request $requestPaginatorInterface $paginator): JsonResponse|\Symfony\Component\HttpFoundation\Response
  223.     {
  224.         $locationId $request->get('location');
  225.         $incentivesListing = new ConventionIncentive\Listing();
  226.         if($locationId) {
  227.             $incentivesListing->addConditionParam('region__id = :locationId', ['locationId' => $locationId]);
  228.         }
  229.         if($this->getDocumentEditable('checkbox''randomize') && $this->getDocumentEditable('checkbox''randomize')->getData()) {
  230.             $incentivesListing->setOrderKey('RAND(CURDATE())'false);
  231.         }
  232.         $numTeaser = (int)$this->getDocumentEditable('numeric''teaserPerPage')->getData();
  233.         if($numTeaser 4) {
  234.             $numTeaser 8;
  235.         }
  236.         $pagination $paginator->paginate($incentivesListing$request->get('page'1), $numTeaser);
  237.         if( $request->isXmlHttpRequest()) {
  238.             $response =[
  239.                 "success" => true,
  240.                 "content" => [
  241.                     'result-main' => $this->render('Convention/Includes/incentives-list.html.twig', [
  242.                         'items' => $pagination,
  243.                     ])->getContent(),
  244.                     'result-paging' => $this->renderView('Navigation/paging.html.twig', [
  245.                         'styleModifier' => 'justify-content-center',
  246.                         'ajaxClass' => 'js-ajax-form-map__link',
  247.                         'ajaxPaging' => true,
  248.                         'paginator' => $pagination
  249.                     ]),
  250.                 ],
  251.             ];
  252.             return new JsonResponse($response);
  253.         }
  254.         return $this->renderTemplate('Convention/incentivesOverview.html.twig', [
  255.             'paginator' => $pagination,
  256.             'regionSelect' => $this->getRegionSelectData($locationId),
  257.         ]);
  258.     }
  259.     private function getConventionCategoriesSelect(ConventionPartnerCategory\Listing $conventionCategories$partnerId null) : array{
  260.         $conventionCategoriesSelect $conventionAllCategoriesSelect = [[
  261.             "label" => "",
  262.             "value" => "",
  263.             "disabled" => true,
  264.             "selected" =>  !$partnerId,
  265.             "class" => "sr-only"
  266.         ]];
  267.         $locationNames = [];
  268.         $locations = [];
  269.         foreach ($conventionCategories as $category) {
  270.             if($category->getIsLocation()) {
  271.                 $locationNames[] = $category->getName();
  272.                 $locations[] = $category;
  273.                 $conventionAllCategoriesSelect[] = [
  274.                     "label" => $category->getName(),
  275.                     "value" => $category->getId(),
  276.                     "selected" =>  false,
  277.                     "class" => ""
  278.                 ];
  279.             } else {
  280.                 $conventionCategoriesSelect[] = $conventionAllCategoriesSelect[] = [
  281.                     "label" => $category->getName(),
  282.                     "value" => $category->getId(),
  283.                     "selected" =>  ($partnerId && $partnerId == $category->getId()),
  284.                     "class" => ""
  285.                 ];
  286.             }
  287.         }
  288.         $conventionCategoriesSelect[] = [
  289.             "label" => implode(', '$locationNames),
  290.             "value" => 'locations',
  291.             "class" => "",
  292.             "selected" =>  $partnerId && $partnerId === 'locations',
  293.         ];
  294.         return [
  295.             'select' => $conventionCategoriesSelect,
  296.             'selectAll' => $conventionAllCategoriesSelect,
  297.             'locations' => $locations,
  298.         ];
  299.     }
  300.     private function getRandomIncentivesForTeaser(ConventionPartner $partnerLinkGenerator $linkGenerator$numOfTeaser 3) : array {
  301.         $incentives $partner->getDetailRelatedincentives();
  302.         if(empty($incentives)) {
  303.             $incentives = new ConventionIncentive\Listing();
  304.             if($partner->getDetailRadius()) {
  305.                 $functionsHelper = new FunctionsHelper();
  306.                 $distance $functionsHelper->getGeoDistanceQuery($partner->getGeoposition(), 'geoposition');
  307.                 $incentives->addConditionParam('(:distance) <= :detailRadius', ['distance' => $distance'detailRadius' => $partner->getDetailRadius()]);
  308.             }
  309.             $incentives->setOrderKey(['name']);
  310.             $incentives->setOrder(['ASC']);
  311.         }
  312.         $count 0;
  313.         $teaserdata = [];
  314.         foreach ($incentives as $inc) {
  315.             $text '';
  316.             foreach($inc->getTeaserBullets() as $bullet) {
  317.                 $text .= '<li>' $bullet['item']->getData() . '</li>';
  318.             }
  319.             $teaserdata[] = [
  320.                 'title' => $inc->getName(),
  321.                 'badgeText' => $inc->getCity(),
  322.                 'image' => $inc->getTeaserimage(),
  323.                 'wysiwyg' => '<ul>' $text '</ul>',
  324.                 'link' => $linkGenerator->generate($inc),
  325.                 'linktext' => $this->translator->trans('convention-detail.Mehr anzeigen'),
  326.             ];
  327.             $count++;
  328.             if($count >= $numOfTeaser) break;
  329.         }
  330.         return $teaserdata;
  331.     }
  332.     private function getDemiInfrastructureTeasers(ConventionPartner $partnerLinkGenerator $linkGenerator$numOfTeaser 3) : array {
  333.         if($partner->getDetailRelated() && !empty($partner->getDetailRelated())) {
  334.             $demiInfrastructures $partner->getDetailRelated();
  335.         } else {
  336.             $demiInfrastructures DemiInfrastructure::getList();
  337.             $demiInfrastructures->addConditionParam('name is not null and name != ""');
  338.             if($partner->getDetailRadius()) {
  339.                 $functionsHelper = new FunctionsHelper();
  340.                 $distance $functionsHelper->getGeoDistanceQuery($partner->getGeoposition(), 'position');
  341.                 $demiInfrastructures->addConditionParam('(' $distance ') <= :detailRadius', [ 'detailRadius' => $partner->getDetailRadius()]);
  342.             }
  343.             $topics = [];
  344.             if(($infraTypes $partner->getDetailRadiusTypes()) && !empty($infraTypes)) {
  345.                 foreach($infraTypes as $type) {
  346.                     foreach($type->getChildren() as $child) {
  347.                         if($child instanceof DemiInfrastructureTopic) {
  348.                             $topics[] = $child->getId();
  349.                         }
  350.                     }
  351.                 }
  352.             }
  353.             if(($infraTopics $partner->getDetailRadiusTopics()) && !empty($infraTopics)) {
  354.                 foreach ($infraTopics as $topic) {
  355.                     $topics[] = $topic->getId();
  356.                 }
  357.             }
  358.             if(!empty($topics)) {
  359.                 $topics array_unique($topics);
  360.                 $subcondition = [];
  361.                 foreach ($topics as $topic) {
  362.                     $subcondition[] = 'topics LIKE "%,' $topic ',%"';
  363.                     $subcondition[] = 'subTopics LIKE "%,' $topic ',%"';
  364.                 }
  365.                 $demiInfrastructures->addConditionParam('(' implode(' OR '$subcondition) . ')');
  366.             }
  367.             $demiInfrastructures->setOrderKey("RAND()"false);
  368.             $demiInfrastructures->setLimit(3);
  369.         }
  370.         //prepare img-teasers
  371.         $count 0;
  372.         $teaserdata = [];
  373.         foreach ($demiInfrastructures as $infra) {
  374.             $teaserdata[] = [
  375.                 "title" => $infra->getName(),
  376.                 "href" => $this->linkGenerator->generate($infra),
  377.                 "image" => $infra->getFirstImage(),
  378. //                "badgeText" =>  $infra->get(),
  379.                 "isInNav" =>  false,
  380.                 "isSearchTeaser" =>  false,
  381.                 "ratio" =>  null
  382.             ];
  383.             $count++;
  384.             if($count >= $numOfTeaser) break;
  385.         }
  386.         return $teaserdata;
  387.     }
  388.     private function getRegionSelectData($location null): array
  389.     {
  390.         $regions = new Region\Listing();
  391.         $regions->setOrderKey('sorting');
  392.         $regionsSelect = [[
  393.             "label" => "",
  394.             "value" =>  "",
  395.             "disabled" => true,
  396.             "selected" => !$location,
  397.             "class"=>  "sr-only"
  398.         ]];
  399.         foreach ($regions as $region) {
  400.             $regionsSelect[] = [
  401.                 "label" => $region->getName(),
  402.                 "value" => $region->getId(),
  403.                 "class" => "",
  404.                 "selected" => $location && $location == $region->getId(),
  405.             ];
  406.         }
  407.         return $regionsSelect;
  408.     }
  409.     private function prepareInfoblocks(ConventionPartner $convention) : array {
  410.         $infos = ['hotel' => [], 'convention' => []];
  411.         if(!empty($convention->getRoomInfo())) {
  412.             $infos['hotel']['roominfo'] = [
  413.                 "icon" => "bed",
  414.                 "title" => $this->translator->trans("convention-detail.Zimmer"),
  415.                 'data' => [],
  416.             ];
  417.             foreach($convention->getRoomInfo() as $item) {
  418.                 $infos['hotel']['roominfo']['data'][] = $item['item']->getData();
  419.             }
  420.         }
  421.         if(!empty($convention->getHotelInfo())) {
  422.             $infos['hotel']['hotelinfo'] = [
  423.                 "icon" => "house",
  424.                 "title" => $this->translator->trans("convention-detail.Hoteleinrichtungen"),
  425.                 'data' => [],
  426.             ];
  427.             foreach($convention->getHotelInfo() as $item) {
  428.                 $infos['hotel']['hotelinfo']['data'][] = $item['item']->getData();
  429.             }
  430.         }
  431.         if(!empty($convention->getDayroomInfo())) {
  432.             $infos['hotel']['dayrooms'] = [
  433.                 "icon" => "calendar",
  434.                 "title" => $this->translator->trans("convention-detail.Tagungsräume"),
  435.                 'data' => [],
  436.             ];
  437.             foreach($convention->getDayroomInfo() as $item) {
  438.                 $infos['hotel']['dayrooms']['data'][] = $item['item']->getData();
  439.             }
  440.         }
  441.         if(!empty($convention->getGastronomyInfo())) {
  442.             $infos['hotel']['gastronomy'] = [
  443.                 "icon" => "cutlery",
  444.                 "title" => $this->translator->trans("convention-detail.Gastronomie"),
  445.                 'data' => [],
  446.             ];
  447.             foreach($convention->getGastronomyInfo() as $item) {
  448.                 $infos['hotel']['gastronomy']['data'][] = $item['item']->getData();
  449.             }
  450.         }
  451.         if(!empty($convention->getFreetimeInfo())) {
  452.             $infos['hotel']['freetime'] = [
  453.                 "icon" => "shoe",
  454.                 "title" => $this->translator->trans("convention-detail.Freizeiteinrichtungen"),
  455.                 'data' => [],
  456.             ];
  457.             foreach($convention->getFreetimeInfo() as $item) {
  458.                 $infos['hotel']['freetime']['data'][] = $item['item']->getData();
  459.             }
  460.         }
  461.         if(!empty($convention->getSpecialInfo())) {
  462.             $infos['hotel']['special'] = [
  463.                 "icon" => "star",
  464.                 "title" => $this->translator->trans("convention-detail.Besonderheiten"),
  465.                 'data' => [],
  466.             ];
  467.             foreach($convention->getSpecialInfo() as $item) {
  468.                 $infos['hotel']['special']['data'][] = $item['item']->getData();
  469.             }
  470.         }
  471.         if(!empty($convention->getSaele())) {
  472.             foreach ($convention->getSaele() as $saal) {
  473.                 $infos['convention'][$saal->getName()] = [
  474.                     "title" => $saal->getName(),
  475.                     'data' => [],
  476.                     'bestuhlung' => [],
  477.                 ];
  478.                 $infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Personen(maximal)') . ': ' max($saal->getCapacityBankett(), $saal->getCapacityTheater(), $saal->getCapacityParlament(), $saal->getCapacityUStyle(), $saal->getCapacityReception());
  479.                 $infos['convention'][$saal->getName()]['data'][] =  $this->translator->trans('convention-detail.saal.Größe') . ': ' $saal->getSize();
  480.                 $infos['convention'][$saal->getName()]['data'][]= $this->translator->trans('convention-detail.saal.Tageslicht') . ': ' . ($saal->getDaylight() ? $this->translator->trans('generic.yes') : $this->translator->trans('generic.no'));
  481.                 if($saal->getSpecials()) {
  482.                     $infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Bodenbelag') . ': ' $saal->getFloorType();
  483.                     $infos['convention'][$saal->getName()]['data'][] = $this->translator->trans('convention-detail.saal.Besonderheiten') . ': ' $saal->getSpecials();
  484.                 }
  485.                 if($saal->getCapacityBankett() > 0) {
  486.                     $infos['convention'][$saal->getName()]['bestuhlung'][] = [
  487.                         'icon' => 'bankett',
  488.                         'text' =>  $this->translator->trans('convention-detail.saal.Bankett') .  ': ' $saal->getCapacityBankett()
  489.                     ];
  490.                 }
  491.                 if($saal->getCapacityTheater() > 0) {
  492.                     $infos['convention'][$saal->getName()]['bestuhlung'][] = [
  493.                         'icon' => 'theater',
  494.                         'text' =>  $this->translator->trans('convention-detail.saal.Theater') .  ': ' $saal->getCapacityTheater()
  495.                     ];
  496.                 }
  497.                 if($saal->getCapacityParlament() > 0) {
  498.                     $infos['convention'][$saal->getName()]['bestuhlung'][] = [
  499.                         'icon' => 'parliament',
  500.                         'text' =>  $this->translator->trans('convention-detail.saal.Parlament') .  ': ' $saal->getCapacityParlament()
  501.                     ];
  502.                 }
  503.                 if($saal->getCapacityUStyle() > 0) {
  504.                     $infos['convention'][$saal->getName()]['bestuhlung'][] = [
  505.                         'icon' => 'u-style',
  506.                         'text' =>  $this->translator->trans('convention-detail.saal.U-Style') .  ': ' $saal->getCapacityUStyle()
  507.                     ];
  508.                 }
  509.                 if($saal->getCapacityReception() > 0) {
  510.                     $infos['convention'][$saal->getName()]['bestuhlung'][] = [
  511.                         'icon' => 'cocktail',
  512.                         'text' =>  $this->translator->trans('convention-detail.saal.Empfang') .  ': ' $saal->getCapacityReception()
  513.                     ];
  514.                 }
  515.             }
  516.         }
  517.         return $infos;
  518.     }
  519.     private function sendContactRequest(Request $request, array $partners) {
  520.         if ($request->get('isSend'0) && !empty($partners) ) {
  521.             $requiredParams = [
  522.                 'arrival' => Carbon::createFromFormat('Y-m-d H:i:s'str_replace('T'''$request->get('arrival')))->format('d.m.Y') ?? null,
  523.                 'departure' => Carbon::createFromFormat('Y-m-d H:i:s',  str_replace('T'''$request->get('departure')))->format('d.m.Y') ?? null,
  524.                 'company' => $request->get('company'),
  525.                 'participants' => $request->get('participants'),
  526.                 'salutation' => $request->get('salutation'),
  527.                 'firstname' => $request->get('firstname'),
  528.                 'lastname' => $request->get('lastname'),
  529.                 'street' => $request->get('street'),
  530.                 'zip' => $request->get('zip'),
  531.                 'city' => $request->get('city'),
  532.                 'country' => $request->get('country'),
  533.                 'phone' => $request->get('phone'),
  534.                 'email' => $request->get('email'),
  535.             ];
  536.             $optionalParams = [
  537.                 'contactType phone' => $request->get('contactType') && $request->get('contactType') == '1' 'checked' 'not checked',
  538.                 'contactType mail' => $request->get('contactType') && $request->get('contactType') == '2''checked' 'not checked',
  539.                 'message' => $request->get('message'),
  540.                 'title' => $request->get('title'),
  541.             ];
  542.             $errors = [];
  543.             foreach ($requiredParams as $key => $param) {
  544.                 if(empty($param)) {
  545.                     $errors[] = $key;
  546.                 }
  547.             }
  548.             foreach ($optionalParams as $key => $param) {
  549.                 if(empty($param)) {
  550.                     unset($optionalParams[$key]);
  551.                 }
  552.             }
  553.             if(!$requiredParams['email'] || !filter_var($requiredParams['email'], FILTER_VALIDATE_EMAIL) ) {
  554.                 $errors[] = 'no valid email';
  555.             }
  556.             $websiteSetting WebsiteSetting::getByName('DefaultSiteConfig');
  557.             if ($websiteSetting instanceof WebsiteSetting) {
  558.                 $config $websiteSetting->getData();
  559.             }
  560.             $success false;
  561.             if(empty($errors) && $config && $config instanceof SiteConfig) {
  562.                 foreach ($partners as $partner) {
  563.                     //build param
  564.                     $params array_merge($requiredParams$optionalParams);
  565.                     $params['items'] = [];
  566.                     if ($partner instanceof ConventionPartner) {
  567.                         $params array_merge($params, ['hotels' => $partner->getName()]); //is overridden later
  568.                         $params['items'] = array_merge($params['items'], ['hotels']);
  569.                     } elseif($partner instanceof ConventionIncentive) {
  570.                         $params array_merge($params, ['incentives' => $partner->getName()]);
  571.                         $params['items'] = array_merge($params['items'], ['incentives']);
  572.                     }
  573.                     $params['items'] = array_merge($params['items'], [
  574.                         'arrival''departure''company''participants''salutation''title',
  575.                         'firstname''lastname',
  576.                         'street''zip''city''country''phone''email',
  577.                         'contactType phone''contactType mail''message'
  578.                     ]);
  579.                     $docs $this->getEmailDocuments($partner$config$request->getLocale());
  580.                     $adminMailDoc $docs['adminMail'];
  581.                     $userMailDoc $docs['userMail'];
  582.                     $successPage $docs['successPage'];
  583.                     if($adminMailDoc) {
  584.                         $adminmail = new \Pimcore\Mail();
  585.                         $adminmail->setDocument($adminMailDoc);
  586.                         if($partner instanceof ConventionPartner && !empty($partner->getEmail())) {
  587.                             $adminmail->addTo($partner->getEmail());
  588.                         } elseif($partner instanceof ConventionIncentive && $partner->getEmail()) {
  589.                             $adminmail->addTo($partner->getEmail());
  590.                         }
  591.                         $adminmail->addReplyTo($requiredParams['email']);
  592.                         $adminmail->setParams($params);
  593.                         $adminmail->send();
  594.                     }
  595.                     if($userMailDoc) {
  596.                         $usermail = new \Pimcore\Mail();
  597.                         $usermail->setDocument($userMailDoc);
  598.                         $usermail->addTo$requiredParams['email']);
  599.                         $usermail->setParams($params);
  600.                         $usermail->send();
  601.                         $success true;
  602.                     }
  603.                     if($successPage) {
  604.                         $redirect = new RedirectResponse($successPage->getFullPath());
  605.                     }
  606.                 }
  607.             }
  608.         }
  609.         return [
  610.             'errors' => $errors ?? [],
  611.             'success' => $success ?? false,
  612.             'redirect' => $redirect ?? null,
  613.         ];
  614.     }
  615.     private function checkCapacityAndSaalStyle(ConventionPartner\Listing $conventionPartnersRequest $request): array
  616.     {
  617.         $idList = [];
  618.         $participant $request->get('participant'); // is a required field
  619.         $any = !($request->get('bankett') | $request->get('theater') | $request->get('parliament') | $request->get('u-style') | $request->get('cocktail'));
  620.         foreach($conventionPartners as $partner) {
  621.             $capacities = [];
  622.             $roomcount $maxAmount 0;
  623.             $bankett $theater $parliament $u_style $cocktail false;
  624.             if (!empty($partner->getSaele())) {
  625.                 foreach ($partner->getSaele() as $saal) {
  626.                     if ($request->get('daylight') && !$saal->getDaylight()) {
  627.                         continue;
  628.                     }
  629.                     $saalmax 0;
  630.                     if($request->get('bankett') || $any) {
  631.                         $saalmax $saal->getCapacityBankett();
  632.                     }
  633.                     if($request->get('theater') || $any) {
  634.                         $saalmax max($saal->getCapacityTheater(), $saalmax);
  635.                     }
  636.                     if($request->get('parliament') || $any) {
  637.                         $saalmax max($saal->getCapacityParlament(), $saalmax);
  638.                     }
  639.                     if($request->get('u_style') || $any) {
  640.                         $saalmax max($saal->getCapacityUStyle(), $saalmax);
  641.                     }
  642.                     if($request->get('cocktail') || $any) {
  643.                         $saalmax max($saal->getCapacityReception(), $saalmax);
  644.                     }
  645.                     $capacities[] = $saalmax;
  646.                     $roomcount++;
  647.                 }
  648.             }
  649.             rsort($capacities);
  650.             for ($i 0$i count($capacities); $i++) {
  651.                 $maxAmount += intval($capacities[$i]);
  652.             }
  653.             if($maxAmount >= $participant ) {
  654.                 $idList[] = $partner->getId();
  655.             }
  656.         }
  657.         return $idList;
  658.     }
  659.     private function processContactForm(Request $request): array
  660.     {
  661.         $requiredParams = [
  662.             "participant" =>  $request->get('participant'),
  663.             "seminarrooms" =>  $request->get('seminarrooms'),
  664.             "rooms" =>  $request->get('rooms'),
  665.             "company" =>  $request->get('company'),
  666.             "salutation" =>  $request->get('salutation'),
  667.             "firstname" =>  $request->get('firstname'),
  668.             "lastname" =>  $request->get('lastname'),
  669.             "street" =>  $request->get('street'),
  670.             "zip" =>  $request->get('zip'),
  671.             "city" =>  $request->get('city'),
  672.             "country" =>  $request->get('country'),
  673.             "email" =>  $request->get('email'),
  674.         ];
  675.         if($request->get('location')) {
  676.             $region Region::getById$request->get('location'));
  677.         }
  678.         if($request->get('category')) {
  679.             $partnerCategory ConventionPartnerCategory::getById($request->get('category'));
  680.         }
  681.         $optionalParams = [
  682.             "convention-partner" =>  $request->get('convention-partner'),
  683.             "region" => $region $region->getName() : null,
  684.             "keyword" =>  $request->get('keyword'),
  685.             "category" =>  $partnerCategory $partnerCategory->getName() : null,
  686.             "bankett" =>  $request->get('bankett') ? 'Checked' 'Not Checked',
  687.             "theater" =>  $request->get('theater') ? 'Checked' 'Not Checked',
  688.             "parliament" =>  $request->get('parliament') ? 'Checked' 'Not Checked',
  689.             "u-style" =>  $request->get('u-style') ? 'Checked' 'Not Checked',
  690.             "cocktail" =>  $request->get('cocktail') ? 'Checked' 'Not Checked',
  691.             "daylight" =>  $request->get"daylight-checkbox") ? 'Checked' 'Not Checked',
  692.             "pkw-available" =>  $request->get('pkw-checkbox') ? 'Checked' 'Not Checked',
  693.             'arrival' => $request->get('arrival') ?  Carbon::createFromFormat('Y-m-d H:i:s'str_replace('T'' '$request->get('arrival')))->format('d.m.Y') : null,
  694.             'departure' => $request->get('departure') ? Carbon::createFromFormat('Y-m-d H:i:s'str_replace('T'' '$request->get('departure')))->format('d.m.Y') : null,
  695.             'title' => $request->get('title'),
  696.             'phone' => $request->get('phone'),
  697.             'contactType phone' => $request->get('contactType') && $request->get('contactType') == '1'  'Checked' 'Not Checked',
  698.             'contactType mail' => $request->get('contactType') && $request->get('contactType') == '2'  'Checked' 'Not Checked',
  699.             'message' => $request->get('message'),
  700.         ];
  701.         $errors = [];
  702.         foreach ($requiredParams as $key => $param) {
  703.             if(empty($param)) {
  704.                 $errors[] = $key;
  705.             }
  706.         }
  707.         if(!$requiredParams['email'] || !filter_var($requiredParams['email'], FILTER_VALIDATE_EMAIL) ) {
  708.             $errors[] = 'no valid email';
  709.         }
  710.         $success false;
  711.         $config $this->document->getProperty('siteConfig');
  712.         if(empty($errors) && $config && $config instanceof SiteConfig) {
  713.             $adminMailDoc $this->getDocumentEditable('relation''adminmail')->getElement();
  714.             $userMailDoc $this->getDocumentEditable('relation''usermail')->getElement();
  715.             $successPage $this->getDocumentEditable('relation''successpage')->getElement();
  716.             $params array_merge($requiredParams$optionalParams);
  717.             $params['items'] = ['salutation''firstname''lastname''category''participant''seminarrooms''bankett''theater''parliament''u-style''cocktail''daylight''pkw-available''rooms''region''keyword''company''street''zip''city''country''phone''email''contactType phone''contactType mail''arrival''departure''message'];
  718.             if($adminMailDoc) {
  719.                 $adminmail = new \Pimcore\Mail();
  720.                 $adminmail->setDocument($adminMailDoc);
  721.                 $adminmail->setReplyTo($requiredParams['email']);
  722.                 $adminmail->setParams($params);
  723.                 $adminmail->send();
  724.             }
  725.             if($userMailDoc) {
  726.                 $usermail = new \Pimcore\Mail();
  727.                 $usermail->setDocument($userMailDoc);
  728.                 $usermail->addTo$requiredParams['email']);
  729.                 $usermail->setParams($params);
  730.                 $usermail->send();
  731.             }
  732.             if($successPage) {
  733.                 $redirect = new RedirectResponse($successPage->getFullPath());
  734.             }
  735.             $success true;
  736.         }
  737.         return [
  738.             'errors' => $errors ?? [],
  739.             'success' => $success ?? false,
  740.             'redirect' => $redirect ?? null,
  741.         ];
  742.     }
  743.     private function getRandomPartnerForTeaser(ConventionIncentive $incentiveLinkGenerator $linkGenerator$numOfTeaser 3) : array {
  744.         //see if manual incentive
  745.         //if not take radom
  746.             //if detailradius
  747.             //if detailradiusCategories
  748.             //if detailradiusClassifications
  749.         $partners = [];
  750.         if($incentive->getDetailRelated() && !empty($incentive->getDetailRelated())) {
  751.             $partners $incentive->getDetailRelated();
  752.         } else {
  753.             $partners = new ConventionPartner\Listing();
  754.             $partners->addConditionParam('name is not null and name != ""');
  755.             if($incentive->getDetailRadius()) {
  756.                 $functionsHelper = new FunctionsHelper();
  757.                 $distance $functionsHelper->getGeoDistanceQuery($incentive->getGeoposition(), 'geoposition');
  758.                 $partners->addConditionParam('(:distance) <= :detailRadius', ['distance' => $distance'detailRadius' => $incentive->getDetailRadius()]);
  759.             }
  760.             $partners $partners->getObjects();
  761.             shuffle($partners);
  762.         }
  763.         //prepare img-teasers
  764.         $count 0;
  765.         $teaserdata = [];
  766.         foreach ($partners as $partner) {
  767.             $teaserdata[] = [
  768.                 "title" => $partner->getName(),
  769.                 "href" => $linkGenerator->generate($partner),
  770.                 "image" => $partner->getTeaserimage(),
  771.                 "badgeText" =>  $partner->getCity(),
  772.                 "isInNav" =>  false,
  773.                 "isSearchTeaser" =>  false,
  774.                 "ratio" =>  null
  775.             ];
  776.             $count++;
  777.             if($count >= $numOfTeaser) break;
  778.         }
  779.         return $teaserdata;
  780.     }
  781.     private function getMailFromDemi(ConventionPartner $partner)
  782.     {
  783.         if (!empty($mails) && method_exists($partner'getDemiAccommodation') && $partner->getDemiAccommodation()) {
  784.             $addressPriorities = ['Venue''Object''ExternalAddress''Organizer''Owner'];
  785.             $addresses $partner->getDemiAccommodation() ? $partner->getDemiAccommodation()->getAddresses() : [];
  786.             foreach ($addresses as $address) {
  787.                 $addressType $address->getAddressType();
  788.                 if (in_array($addressType$addressPriorities)) {
  789.                     $mainAddress $address;
  790.                     break;
  791.                 }
  792.             }
  793.             if ($mainAddress && $mainAddress->getEmail()) {
  794.                 return $mainAddress->getEmail();
  795.             }
  796.         }
  797.         return null;
  798.     }
  799.     /**
  800.      * @Route("/{_locale}/interactive-map-info-box", name="interactive-map-info-box")
  801.      */
  802.     public function getMapInfoBox(Request $requestLinkGenerator $linkGenerator) {
  803.         $partner ConventionPartner::getById($request->get('id'null));
  804.         $document $this->document;
  805.         $locale $document->getProperty('language') ?? $request->getLocale();
  806.         if($partner) {
  807.             $wysiwyg '<ul>';
  808.             foreach($partner->getTeaserBullets($locale) as $bulletpoint) {
  809.                 $wysiwyg .= '<li>'  $bulletpoint['item']->getData() . '</li>';
  810.             }
  811.             $wysiwyg .= '</ul>';
  812.             return $this->json([
  813.                 'success' => true,
  814.                 'html' => $this->renderView('Convention/Includes/interactive-map-info-box.html.twig', [
  815.                     'image' => $partner->getTeaserimage(),
  816.                     'subtitle' => $partner->getShortdescription($locale),
  817.                     'title' => $partner->getName($locale),
  818.                     'wysiwyg' => $wysiwyg,
  819.                     'link' => $linkGenerator->generate($partner, ['document' => $document]),
  820.                     'id' => $request->get('id')
  821.                 ])
  822.             ]);
  823.         }
  824.     }
  825.     public function getMapdata($items): JsonResponse
  826.     {
  827.         $geoData = [];
  828.         foreach ($items as $partner) {
  829.             if($partner) {
  830.                 $geo $partner->getGeoposition();
  831.                 if($geo) {
  832.                     $geoData[] = [
  833.                         "id" => $partner->getId(),
  834.                         "lat" => $geo->getLatitude(),
  835.                         "lng" => $geo->getLongitude(),
  836.                         "detailInfoBoxUrl" => $this->generateUrl('interactive-map-info-box',[
  837.                             'id' => $partner->getId(),
  838.                             ])
  839.                     ];
  840.                 }
  841.             }
  842.         }
  843.         return new JsonResponse([
  844.             "success" => true,
  845.             "pois" => $geoData
  846.         ]);
  847.     }
  848.     /**
  849.      * @Route("/{_locale}/add-to-wishlist", name="add-to-wishlist")
  850.      */
  851.     public function addToWishlist(Request $request): JsonResponse
  852.     {
  853.         $id $request->get('id');
  854.         $wishlistId $request->get('wishlistId');
  855.         $sessionIds $request->getSession()->get('wishlistIds', []);
  856.         $sessionIds[] = $id;
  857.         $request->getSession()->set('wishlistIds'$sessionIds);
  858.         $returnArr['ids'] = $sessionIds;
  859.         $url $this->document->getProperty('siteConfig') ? ($this->document->getProperty('siteConfig')->getWatchlistOverview() ?: '#') : '#';
  860.         return new JsonResponse([
  861.             "success" => true,
  862.             "activeIds" => array_values(array_map('intval',$sessionIds)),
  863.             "__alertNotification" => [
  864.                 "type" => "notification-default",
  865.                 "content" =>  $this->renderView('Convention/Includes/add-wishlist-notification-content.html.twig', [
  866.                     'url' => $url
  867.                 ])
  868.             ]
  869.         ]);
  870.     }
  871.     /**
  872.      * @Route("/{_locale}/remove-from-wishlist", name="remove-from-wishlist")
  873.      */
  874.     public function removeFromWishlist(Request $request): JsonResponse
  875.     {
  876.         $id $request->get('id');
  877.         $wishlistId $request->get('wishlistId');
  878.         $sessionIds $request->getSession()->get('wishlistIds', []);
  879.         if (($key array_search($id$sessionIds)) !== false) {
  880.             unset($sessionIds[$key]);
  881.         }
  882.         $request->getSession()->set('wishlistIds'$sessionIds);
  883.         $returnArr['ids'] = $sessionIds;
  884.         $url $this->document->getProperty('siteConfig') ? ($this->document->getProperty('siteConfig')->getWatchlistOverview() ?: '#') : '#';
  885.         return new JsonResponse([
  886.             "success" => true,
  887.             "activeIds" =>  array_values(array_map('intval',$sessionIds)),
  888.             "__alertNotification" => [
  889.                 "type" => "notification-default",
  890.                 "content" =>  $this->renderView('Convention/Includes/remove-wishlist-notification-content.html.twig', [
  891.                     'url' => $url,
  892.                 ])
  893.             ]
  894.         ]);
  895.     }
  896.     private function getExcludedConventionCategoryIds()
  897.     {
  898.         $excludedCategories = new ConventionPartnerCategory\Listing();
  899.         $excludedCategories->addConditionParam("notShowInEventplannerFilter is not null and notShowInEventplannerFilter = 1");
  900.         $ids = [];
  901.         if($excludedCategories->getCount() > 0) {
  902.             $ids array_map(function ($cat) {
  903.                 return $cat->getId();
  904.             }, $excludedCategories->getObjects());
  905.         }
  906.         return $ids;
  907.     }
  908.     /**
  909.      * @param mixed $partner
  910.      * @param SiteConfig $fallbackConfig
  911.      * @param string $locale
  912.      * @return array
  913.      */
  914.     private function getEmailDocuments(mixed $partnerSiteConfig $fallbackConfigstring $locale)
  915.     {
  916.         //initalize with fallback values
  917.         $adminmail =  $fallbackConfig->getConventionPartnerDetailContactFormAdminMail($locale);
  918.         $usermail =  $fallbackConfig->getConventionPartnerDetailContactFormUserMail($locale);
  919.         $successPage =  $fallbackConfig->getConventionPartnerDetailContactFormSuccessPage($locale);
  920.         $regionconfig null;
  921.         if($partner instanceof ConventionPartner && count($partner->getRegions()) > && ($region $partner->getRegions()[0]) && $region->getSiteConfig() && $region->getSiteConfig()->getId() !== $fallbackConfig->getId()) {
  922.             $regionconfig $region->getSiteConfig();
  923.         } elseif( $partner instanceof ConventionIncentive && ($region $partner->getRegion()) &&  $region->getSiteConfig() && $region->getSiteConfig()->getId() !== $fallbackConfig->getId()) {
  924.             $regionconfig $region->getSiteConfig();
  925.         }
  926.         if($regionconfig) {
  927.             if($regionconfig->getConventionPartnerDetailContactFormAdminMail($locale)) {
  928.                 $adminmail $regionconfig->getConventionPartnerDetailContactFormAdminMail($locale);
  929.             }
  930.             if($regionconfig->getConventionPartnerDetailContactFormUserMail($locale)) {
  931.                 $usermail =  $regionconfig->getConventionPartnerDetailContactFormUserMail($locale);
  932.             }
  933.             if($regionconfig->getConventionPartnerDetailContactFormSuccessPage($locale)) {
  934.                 $successPage $regionconfig->getConventionPartnerDetailContactFormSuccessPage($locale);
  935.             }
  936.         }
  937.         return [
  938.             'adminMail' => $adminmail,
  939.             'userMail' => $usermail,
  940.             'successPage' => $successPage,
  941.         ];
  942.     }
  943. }