src/Controller/BuildingDetailController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Actualite;
  4. use App\Entity\Building;
  5. use App\Entity\BuildingType;
  6. use App\Entity\Town;
  7. use App\Security\EmailVerifier;
  8. use DateTime;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class BuildingDetailController extends AbstractController
  15. {
  16.     private $emailVerifier;
  17.     private $entityManager;
  18.     public function __construct(EmailVerifier $emailVerifierEntityManagerInterface $entityManager)
  19.     {
  20.         $this->emailVerifier $emailVerifier;
  21.         $this->entityManager $entityManager;
  22.     }
  23.     /**
  24.      * @Route("/building/detail", name="app_building_detail")
  25.      */
  26.     public function index(Request $request): Response
  27.     {
  28.      try{
  29.          $town=$request->get("destination");
  30.      }catch (\Exception $exception){
  31.          $this->addFlash('error',"Town not selected");
  32.          $this->redirectToRoute('app_home');
  33.      }
  34.         $buildingType=$request->get("buildingType");
  35.         $startDate=$request->get("startDate");
  36.         $endDate=$request->get("endDate");
  37.         $adult=$request->get("adult");
  38.         $child=$request->get("child");
  39.         $date1 = new DateTime($startDate);
  40.         $date2 = new DateTime($endDate);
  41.         $interval $date1->diff($date2);
  42.         $local=$request->getLocale();
  43.         $language="";
  44.         $onlinePath=$request->getBasePath();
  45.         $updateTown=$this->entityManager->getRepository(Town::class)->find($town);
  46.         if(!is_null($updateTown)){
  47.             $updateTown->setVues($updateTown->getVues()+1);
  48.             $this->entityManager->persist($updateTown);
  49.             $this->entityManager->flush();
  50.         }
  51.         if(strcmp($local,"fr")==0)  {
  52.             $language=" <a href=\"#!\" class=\"dropdown-button grey-text text-darken-1\" data-activates='choose_language' style=\"font-size: 18px\"><img src=\"".$onlinePath."/img/french_flag.png\" style=\"height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px\" alt=\"\"> Français</a>";
  53.             $body='
  54.                <li>  <a href="'.$onlinePath.'/change_locale/en" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_england.png" style="height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Anglais</a></li>
  55.                 <li> <a href="'.$onlinePath.'/change_locale/es" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_spanish.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Espagnol</a></li>
  56.                 <li> <a href="'.$onlinePath.'/change_locale/it" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/italiano_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Italien</a></li>
  57.                 <li> <a href="'.$onlinePath.'/change_locale/zh_CN" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/china_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Chinois</a></li>
  58.                 ';
  59.         }else   if(strcmp($local,"es")==0)   {
  60.             $language=" <a href=\"#!\" class=\"dropdown-button grey-text text-darken-1\" data-activates='choose_language' style=\"font-size: 18px\"><img src=\"".$onlinePath."/img/flag_spanish.png\" style=\"height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px\" alt=\"\"> Español</a>";
  61.             $body='
  62.                 <li> <a href="'.$onlinePath.'/change_locale/fr" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/french_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Francés</a></li>
  63.                 <li>  <a href="'.$onlinePath.'/change_locale/en" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_england.png" style="height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Inglés</a></li>
  64.                 <li> <a href="'.$onlinePath.'/change_locale/it" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/italiano_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Italiano</a></li>
  65.                 <li> <a href="'.$onlinePath.'/change_locale/zh_CN" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/china_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Chinise</a></li>
  66.                 ';
  67.         }else if  (strcmp($local,"en")==0)  {
  68.             $language=" <a href=\"#!\" class=\"dropdown-button grey-text text-darken-1\" data-activates='choose_language'style=\"font-size: 18px\"><img src=\"".$onlinePath."/img/flag_england.png\" style=\"height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px\" alt=\"\"> English</a>";
  69.             $body='
  70.                 <li> <a href="'.$onlinePath.'/change_locale/fr" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/french_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> French</a></li>
  71.                 <li> <a href="'.$onlinePath.'/change_locale/it" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/italiano_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Italiano</a></li>
  72.                 <li> <a href="'.$onlinePath.'/change_locale/zh_CN" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/china_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Chinise</a></li>
  73.                 <li>  <a href="'.$onlinePath.'/change_locale/es" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_spanish.png" style="height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Spanish</a></li>';
  74.         }else if  (strcmp($local,"it")==0)  {
  75.             $language=" <a href=\"#\" class=\"dropdown-button grey-text text-darken-1\" data-activates='choose_language'style=\"font-size: 18px\"><img src=\"".$onlinePath."/img/italiano_flag.png\" style=\"height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px\" alt=\"\"> Italiano</a>";
  76.             $body='
  77.                 <li> <a href="'.$onlinePath.'/change_locale/fr" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/french_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Francese</a></li>
  78.                 <li> <a href="'.$onlinePath.'/change_locale/en" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_england.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> inglese</a></li>
  79.                 <li> <a href="'.$onlinePath.'/change_locale/zh_CN" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/china_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Cinese</a></li>
  80.                 <li>  <a href="'.$onlinePath.'/change_locale/es" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_spanish.png" style="height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> Spagnolo</a></li>';
  81.         }else if  (strcmp($local,"zh_CN")==0)  {
  82.             $language=" <a href=\"#!\" class=\"dropdown-button grey-text text-darken-1\" data-activates='choose_language'style=\"font-size: 18px\"><img src=\"".$onlinePath."/img/china_flag.png\" style=\"height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px\" alt=\"\"> 中國人</a>";
  83.             $body='
  84.                 <li> <a href="'.$onlinePath.'/change_locale/fr" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/french_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> 法語</a></li>
  85.                 <li> <a href="'.$onlinePath.'/change_locale/it" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/italiano_flag.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> 意大利語</a></li>
  86.                 <li> <a href="'.$onlinePath.'/change_locale/en" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_england.png" style="height: 24px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> 中國人</a></li>
  87.                 <li>  <a href="'.$onlinePath.'/change_locale/es" class="grey-text text-darken-1" style="font-size: 18px"><img src="'.$onlinePath.'/img/flag_spanish.png" style="height: 27px; width: 24px;margin-right: 10px; margin-bottom: -6px" alt=""> 西班牙語</a></li>';
  88.         }
  89.         $news$this->entityManager->getRepository(Actualite::class)->findAll();
  90.         $towns$this->entityManager->getRepository(Town::class)->findBy(array(),array("vues"=>"DESC"));
  91.         $town=$this->entityManager->getRepository(Town::class)->find($town);
  92.         $town=$this->entityManager->getRepository(Town::class)->find($town);
  93.         $buildingTypes $this->entityManager->getRepository(BuildingType::class)->findAll();
  94.         $result$this->entityManager->getRepository(Building::class)->findAllDetailByTown($town->getId(),$buildingType);
  95.         return $this->render('building_detail/building_details_index.html.twig', [
  96.             'controller_name' => 'BuildingDetailController',
  97.             'companyName' => $this->getParameter("app_client"),
  98.             'languageChoose' => $body,
  99.             'onlinePath' => $onlinePath,
  100.             'language' => $language,
  101.             'towns' => $towns,
  102.             'buildingTypes' => $buildingTypes,
  103.             'buildingType' => $buildingType,
  104.             'news' =>$news,
  105.             'town' => $town,
  106.             'startDate' => $startDate,
  107.             'endDate' => $endDate,
  108.             'type' => $this->entityManager->getRepository(BuildingType::class)->find($buildingType),
  109.             'adult' => $adult,
  110.             'child' => $child,
  111.             'interval' => $interval,
  112.             'showItem' => 2,
  113.             'result' =>  $result,
  114.             'appUser' =>$this->getParameter('appUser'),
  115.             'host'=>$this->siteURL(),
  116.         ]);
  117.     }
  118.     function siteURL()
  119.     {
  120.         $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" "http://";
  121.         $domainName $_SERVER['HTTP_HOST'].'/';
  122.         if ($_SERVER['HTTP_HOST'] == "localhost") {
  123.             return $protocol.$domainName.$this->getParameter('localRepository')."/".$this->getParameter('apiLink');
  124.         }else{
  125.             return $protocol.$domainName.$this->getParameter('apiLink');
  126.         }
  127.     }
  128. }