src/Controller/PageController.php line 372

Open in your IDE?
  1. <?php
  2. // src/Controller/HomeController.php
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Templating\EngineInterface;
  11. use App\Entity\Events;
  12. use App\Entity\EventSlugs;
  13. use App\Entity\Orders;
  14. use App\Entity\EventTickets;
  15. use App\Entity\Language;
  16. use App\Entity\Sites;
  17. use App\Entity\ShortUrl;
  18. use App\Entity\Pages;
  19. class PageController extends BaseController
  20. {
  21.     
  22.     private $googleData = array();
  23.     private $pageData = array();
  24.     
  25.     /**
  26.      * @Route("/css/{template}/{file}.{px}x.css", name="css_convert_px")
  27.      * @Route("/css/{template}/{file}.css", name="css_convert")
  28.      */
  29.     public function cssAction($template,$file,$px=false) {        
  30.         $response $this->getResponse();
  31.         $response->headers->set('Content-Type''text/css');
  32.         // replace this example code with whatever you need
  33.         return $this->render(
  34.             $template.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.$file.'.css.twig',
  35.             [
  36.                 'pixelratio' => $px
  37.             ],
  38.             $response
  39.         );   
  40.     }
  41.     
  42.     /**
  43.      * @Route("/postal/lookup", name="postal_lookup")
  44.      */
  45.     public function postalLookupAction() {
  46.         $result $this->getPostalService()->getResults();
  47.         
  48.         return new JsonResponse($result);
  49.     }
  50.     
  51.     /**
  52.      * @Route("/order/{order}/complete", name = "payment_complete")
  53.      * @Route("/order/{event}/complete/{order}", name = "payment_complete_event")
  54.      */
  55.     public function completeAction(Orders $order$event '')
  56.     {
  57.         // Welcome back....
  58.         // Process Payment state visually to the customer.
  59.         //return new Response("test");
  60.         $items $order->getItems();
  61.         $cntTickets 0;
  62.         $product false;
  63.         $this->googleData['transactionId'] = $order->getId();
  64.         $this->googleData['transactionAffiliation'] = $order->getSites()->getName();
  65.         $this->googleData['transactionTotal'] = $order->getTotal();
  66.         $this->googleData['transactionTax'] = $order->getTax();
  67.         
  68.         foreach($items as $item) {
  69.             if($item->getType() == 'ticket') {
  70.                 $cntTickets += $item->getAmount();
  71.                 $product $item->getProduct();
  72.                 if($product !== false) {
  73.                     // Handle all orders....
  74.                     $productObj $this->getDoctrine()
  75.                         ->getRepository(EventTickets::class)
  76.                         ->findOneBy(array('Id'=>array($product)),array('Id'=>'ASC'),1,0);                
  77.                     $this->googleData['transactionProducts'][] = array(
  78.                         'sku' => $productObj->getId(),
  79.                         'name' => $productObj->getFullIdent(),
  80.                         'price' => $productObj->getPrice(),
  81.                         'quantity' => $item->getAmount(),
  82.                     );
  83.                 }
  84.             }
  85.         }
  86.         
  87.         $this->googleData['amountTickets'] = $cntTickets;
  88.         $this->googleData['eventDateID'] = '';
  89.         
  90.         if($product !== false) {
  91.                     // Handle all orders....
  92.             $product $this->getDoctrine()
  93.                 ->getRepository(EventTickets::class)
  94.                 ->findOneBy(array('Id'=>array($product)),array('Id'=>'ASC'),1,0);
  95.             $event $product->getEvents();
  96.             $dates $product->getEventDates();
  97.             
  98.             $gtin $event->getId().'-'.$dates->getId();
  99.             $this->googleData['eventDateID'] = $gtin;
  100.             $this->googleData['eventID'] = $event->getId();
  101.         }
  102.         
  103.         
  104.         return $this->home();
  105.     }
  106.     
  107.     /**
  108.      * @Route("/contact/submit", name = "contact_submit")
  109.      */
  110.     public function submitAction()
  111.     {
  112.         // Handle form submission
  113.         
  114.         return new JsonResponse(array());
  115.     }
  116.     
  117.     private function toTrengo() {
  118.         
  119.     }
  120.     
  121.     /**
  122.      * @Route("/language/set/{language}", name = "language_set")
  123.      */
  124.     public function languageSetAction($language)
  125.     {
  126.         // Welcome back....
  127.         // Process Payment state visually to the customer.
  128.         //return new Response("test");
  129.                 
  130.         $manager $this->getDoctrine()->getManager();
  131.         $result $manager->getRepository(Language::class)->findOneBy(array("code"=>$language));
  132.         $language $result->getId();        
  133.         
  134.         $session $this->getSession();        
  135.         $session->set('language',$language);
  136.         
  137.         return $this->getJsonResponse(array('language'=>$language));
  138.     }
  139.     
  140.     /**
  141.      * Matches /pages/{id}/info exactly
  142.      *
  143.      * @Route("/pages/{page_id}/info", name="pages_info")
  144.      * @Route("/pages/{page_id}/info/{clean}", name="pages_info_clean")
  145.      */
  146.     public function page_info($page_id false$clean falseSessionInterface $sessionEngineInterface $twig)
  147.     {
  148.         $this->session $session;
  149.         $current_language_id = (null !== $session->get('language')) ? $session->get('language') : 1;
  150.         $langKey 'nl';
  151.         $langKey = ($current_language_id == 1) ? 'nl' $langKey;
  152.         $langKey = ($current_language_id == 2) ? 'en' $langKey;
  153.         $manager $this->getDoctrine()->getManager();
  154.         $result $manager->getRepository(Pages::class)->findOneBy(array("Id"=>$page_id));
  155.         $site $manager->getRepository(Sites::class)->findCurrentSite();
  156.         $tpl $site->getTemplateFolder();
  157.         $descs $result->getDescription();
  158.         $desc false;
  159.         foreach($descs as $descObj) {
  160.             if($descObj->getLanguage()->getId() == $current_language_id) {
  161.                 // Force current language for now...
  162.                 $desc $descObj->getDescription();
  163.             }
  164.         }
  165.         $page_message '';
  166.         // OK now the available dates..
  167.         $data = array('page_message'=>$page_message,'page_description'=>$desc'lang'=>$langKey'clean'=>$clean);
  168.         if($twig->exists($tpl.'/page_description'.$page_id.'.html.twig')) {
  169.             return $this->render($tpl.'/page_description'.$page_id.'.html.twig',$data);
  170.         }
  171.         return $this->render($tpl.'/page_description.html.twig',$data);
  172.     }
  173.     /**
  174.      * @Route("/pages/all/page", name = "page_load_all")
  175.      */
  176.     public function loadPagesAction()
  177.     {
  178.     $pageData = array();
  179.         $manager $this->getDoctrine()->getManager();
  180.         $site $manager->getRepository(Sites::class)->findCurrentSite();
  181.         if($site instanceof Sites) {
  182.             $result $manager->getRepository(Pages::class)->findBySite(array('site'=>$site));
  183.         foreach($result as $page) {
  184.             $data $this->getPageData($page);
  185.             $pageData[$page->getId()] = $data[$page->getId()];
  186.         }
  187.     }
  188. //      $pages[$page->getId()]['id'] = $page->getId();;
  189.         return new JsonResponse(array('pages'=>$pageData));
  190.     }
  191.     /**
  192.      * @Route("/pages/{id}/page", name = "page_load", requirements={"id"="\d+"})
  193.      */
  194.     public function loadPageAction(Pages $page)
  195.     {
  196.     $pageData $this->getPageData($page);
  197. //  $pages[$page->getId()]['id'] = $page->getId();;
  198.         return new JsonResponse(array('pages'=>$pageData));
  199.     }
  200.     /**
  201.      * @Route("/pages/{slug}/page", name = "page_load_slug")
  202.      */
  203.     public function loadPageSlugAction(Pages $page)
  204.     {
  205.         $pageData $this->getPageData($page);
  206. //      $pages[$page->getId()]['id'] = $page->getId();;
  207.         return new JsonResponse(array('pages'=>$pageData,'page_id'=>$page->getId()));
  208.     }
  209.     public function getPageData($page) {
  210.         $id $page->getId();
  211.         $pageData[$id]['id'] = $id;
  212.         $pageData[$id]['slug'] = $page->getSlug();
  213.         $pageData[$id]['slot'] = $page->getSlot();
  214.         $pageData[$id]['page_title'] = $page->getDescription()[0]->getTitle();
  215.         $pageData[$id]['special_title'] = $page->getDescription()[0]->getSpecialTitle();
  216.         if($pageData[$id]['special_title'] === null) {
  217.             $pageData[$id]['special_title'] = '';
  218.         }
  219.     
  220.         $pageData[$id]['header'] = array();
  221.         $headerObj $page->getPageHeader();
  222.         $imageObj $page->getImagesByType('page');
  223.         $image false;
  224.         foreach($imageObj as $x=>$image) {
  225.             if($image instanceof \App\Entity\PageImage) {
  226.                 if(substr($image->getFile(),-5) == '.webm') {
  227.                     //skip
  228.                 } elseif(substr($image->getFile(),-4) == '.mp4') {
  229.                     //skip
  230.                 } elseif(substr($image->getFile(),-4) == '.pdf') {
  231.                     //skip
  232.                 } else {
  233.                     if(!isSet($pageData[$id]['image'])) {
  234.                         $pageData[$id]['image'] = $image->getFile();
  235.                     }
  236.                 }
  237.             }
  238.         }
  239.     return $pageData;
  240.     }
  241.     /**
  242.      * Matches / exactly
  243.      *
  244.      * @Route("/", name="home",condition="request.headers.get('Host') matches '/www\./i'")
  245.      * @Route("/impersonate", name="page_slug")
  246.      * @Route("/{lang}", name="home_en", requirements={"lang"="en|fr|nl|de"},condition="request.headers.get('Host') matches '/www\./i'")
  247.      * @Route("/event/{slug}", name="home_event")
  248.      * @Route("/event/{slug}/", name="home_event_sl")
  249.      * @Route("/{lang}/event/{slug}", name="home_event_sl_lang", requirements={"lang"="en|fr|nl|de"},condition="request.headers.get('Host') matches '/www\./i'")
  250.      * @Route("/tour/{slug}", name="home_tour")
  251.      * @Route("/tour/{slug}/", name="home_tour_sl")
  252.      * @Route("/project/{slug}", name="home_project")
  253.      * @Route("/project/{slug}/", name="home_project_sl")
  254.      * @Route("/{lang}/tour/{slug}", name="home_tour_sl_lang",requirements={"lang"="en|fr|nl|de"},condition="request.headers.get('Host') matches '/www\./i'")
  255.      * @Route("/order/{slug}", name="home_order_event")
  256.      * @Route("/order/{slug}/", name="home_order_event_sl")
  257.      * @Route("/order/{slug}/{hiddencode}/{event}/", name="order_hidden_show")
  258.      * @Route("/{lang}/order/{slug}/", name="home_order_event_sl",requirements={"lang"="en|fr|nl|de"},condition="request.headers.get('Host') matches '/www\./i'")
  259.      * @Route("/{short}", name="short_url", methods={"GET"}, condition="request.headers.get('Host') matches '/www\./i'")
  260.      * @Route("/page/{short}", name="short_url_page", condition="request.headers.get('Host') matches '/www\./i'")
  261.      */
  262.     public function home($slug=false,$event=false,$hiddencode=false,$lang=false$short=false)
  263.     {
  264.         $eventUrl $event;
  265.         $event false;
  266.         $page false;
  267.         $result false;
  268.         $pFields = array();
  269.         if($short !== false) {
  270.             // Nothing else... Check the Short URL Database!
  271.             $manager $this->getDoctrine()->getManager();
  272.             $shortObj $manager->getRepository(ShortUrl::class)->findOneBy(array('url'=>$short));
  273.             if($shortObj instanceof ShortUrl) {
  274.                 $event $shortObj->getEvents();
  275.                 $url $this->generateUrl('home_event',array('slug'=>$event->getSlug()));
  276.                 return new RedirectResponse($url);
  277.             }
  278.             
  279.             // Not a short object... What is it then?
  280.             // It can be a page!
  281.             $pageObj $manager->getRepository(Pages::class)->findOneBy(array('slug'=>$short));
  282.             if($pageObj instanceof Pages) {
  283.                 $page $pageObj->getId();
  284.             }
  285.         }
  286.         if($slug !== false) {
  287.             // Fetch Event?
  288.             $manager $this->getDoctrine()->getManager();
  289.             $result $manager->getRepository(Events::class)->findOneBy(array("slug"=>$slug));
  290.             if($result) {
  291.                 // Event found.. Load single event page...
  292.                 $event $result->getId(); // Fill with event ID.... Twig does the rest...
  293.             }
  294.             if(!$result) {
  295.                 // Old slug maybe??
  296.                 $result $manager->getRepository(EventSlugs::class)->findOneBy(array("slug"=>$slug));
  297.                 if($result) {
  298.                     // Event found.. Load single event page...
  299.                     $event $result->getEvents()->getId(); // Fill with event ID.... Twig does the rest...
  300.                 }
  301.             }
  302.         }
  303.         
  304.         $manager $this->getDoctrine()->getManager();
  305.         
  306.         if($lang !== false) {
  307.             // We have a code...
  308.             $language $manager->getRepository(Language::class)->findOneBy(array('code'=>$lang));
  309.             if($language) {
  310.                 $lang $language->getId();
  311.             }
  312.         }
  313.         $site $manager->getRepository(Sites::class)->findCurrentSite();
  314.         if($site instanceof Sites) {
  315.             $site_id $site->getId();
  316.             $tpl $site->getTemplateFolder();
  317.             $sitename $site->getName();
  318.         } else {
  319.             $site_id 0;
  320.             $tpl 'default';
  321.             $sitename 'Default';
  322.         }        
  323.         
  324.         $session $this->getSession();
  325.         $sesslang false;
  326.         if($session->has('language')) {
  327.             $sesslang $session->get('language');
  328.         }
  329.         $current_language_id = (false !== ($sesslang)) ? $sesslang 1;
  330.         if($lang !== false && ($current_language_id != $lang || false === $sesslang)) {            
  331.             $session->set('language',$lang); // Set new language....
  332.             $current_language_id $lang// Override current language...
  333.         } elseif(false === $sesslang) {
  334.             $session->set('language',$current_language_id); // Set the language in session....
  335.         }
  336.         
  337.         $projects $manager->getRepository(Events::class)->findUpcomingProjects($site,$current_language_id);        
  338.         $pFields $this->generateFields($site_id);
  339.                
  340.         $templateData = array(
  341.             'event' => $event,
  342.             'page' => $page,
  343.             'site_name' => $sitename,
  344.             'eventUrl' => $eventUrl,
  345.             'hiddencode' => $hiddencode,
  346.             'eventdata' => $result,
  347.             'personal_fields' => $pFields,
  348.             'field_groups' => 3,
  349.             'cur_lang' => $current_language_id,
  350.             'projects' => $projects,
  351.             'googledata' => $this->googleData
  352.         );
  353.         
  354.         return $this->render($tpl.'/index.html.twig',$templateData);
  355.     }
  356.     
  357.     public function generateFields($site_id) {
  358.         $pFields = array();
  359.         $container 
  360.         $path $this->get('kernel')->getProjectDir()."/config/fields/";
  361.         if(file_exists($path.'site_'.$site_id.'.fields.php')) {
  362.             include_once($path.'site_'.$site_id.'.fields.php');
  363.         }
  364.         return $pFields;
  365.     }
  366. }