src/Trinity/ProjectssitesBundle/Controller/ProjectssitesController.php line 729

Open in your IDE?
  1. <?php
  2. namespace App\Trinity\ProjectssitesBundle\Controller;
  3. use DateTime;
  4. use PHPUnit\Exception;
  5. use Doctrine\ORM\EntityManager;
  6. use App\CmsBundle\Entity\Media;
  7. use App\CmsBundle\Classes\Postcode;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use App\CmsBundle\Controller\StorageController;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use App\Trinity\ProjectssitesBundle\Entity\Config;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. use App\Trinity\ProjectssitesBundle\classes\RealEstate;
  16. use App\Trinity\ProjectssitesBundle\classes\RealEstateOption;
  17. use App\Trinity\ProjectssitesBundle\classes\RealEstateMap;
  18. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  19. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  22. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  24. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  25. use App\Trinity\ProjectssitesBundle\Entity\RealEstate as RealEstateEntity;
  26. use App\Trinity\ProjectssitesBundle\Entity\RealEstateOption as RealEstateOptionEntity;
  27. use App\Trinity\ProjectssitesBundle\Entity\RealEstateMap as RealEstateMapEntity;
  28. /**
  29.  * Class ProjectensitesController
  30.  * @package App\Trinity\ProjectssitesBundle\Controller
  31.  */
  32. class ProjectssitesController extends StorageController
  33. {
  34.     /**
  35.      * @Route("/admin/realestate", name="admin_mod_projectssites")
  36.      * @Template()
  37.      */
  38.     public function index(Request $request){
  39.         // Initialize StorageController
  40.         parent::init($request);
  41.         $this->breadcrumbs->addRouteItem('Configuratie''admin_mod_projectssites_config');
  42.         $this->breadcrumbs->addRouteItem('Real Estate Bundle''admin_mod_projectssites');
  43.         $realEstates $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->findBy([
  44.             'language'=> $this->language,
  45.             'settings'=> $this->Settings]);
  46.         foreach($realEstates as $realEstate){
  47.             $realEstate->realEstateOptions $realEstate->getRealEstateOptions();;
  48.         }
  49.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  50.         return $this->render('@TrinityProjectssites/backend/realestate/overview.html.twig'$this->attributes([
  51.             'realEstates' => $realEstates,
  52.             'config' => $config,
  53.             'settings' => $this->Settings,
  54.         ]));
  55.     }
  56.     /**
  57.      * @Route("/admin/realestateoptions", name="admin_mod_realestateoptions")
  58.      * @Template()
  59.      */
  60.     public function realEstateOptions(Request $request){
  61.         // Initialize StorageController
  62.         parent::init($request);
  63.         $this->breadcrumbs->addRouteItem('Configuratie''admin_mod_projectssites_config');
  64.         $this->breadcrumbs->addRouteItem('Real Estate Bundle''admin_mod_projectssites');
  65.         $realEstateOptions $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')->findBy([
  66.             'language'=> $this->language,
  67.             'settings'=> $this->Settings]);
  68.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  69.         return $this->render('@TrinityProjectssites/backend/realestateoption/overview.html.twig'$this->attributes([
  70.             'realEstateOptions' => $realEstateOptions,
  71.             'config' => $config,
  72.             'settings' => $this->Settings,
  73.         ]));
  74.     }
  75.     
  76.     /**
  77.      * Return link data when required within the link form
  78.      *
  79.      * @param object  Doctrine object
  80.      *
  81.      * @return array   Array with config options
  82.      */
  83.     public function getLinkData($em){
  84.         return [
  85.             // Return data to link form
  86.         ];
  87.     }
  88.     /**
  89.      * Show dashboard blocks
  90.      *
  91.      * @return array List of blocks
  92.      */
  93.     public function dashboardBlocks(){
  94.         // Return block data to show on Trinity dashboard in the following format.
  95.         // You can do whatever you want in this function, just return data as below.
  96.         return [
  97.             [
  98.                 'title' => 'Mijn lege module',
  99.                 'class' => '',
  100.                 'content' => '<div style="text-align:center;padding:20px;">Lege module</div>'
  101.             ]
  102.         ];
  103.     }
  104.     /**
  105.      * @Route("/admin/projects/config", name="admin_mod_projectssites_config")
  106.      * @Template()
  107.      */
  108.     public function editConfig(Request $requestEntityManagerInterface $em$id null){
  109.         // Initialize StorageController
  110.         parent::init($request);
  111.         $this->breadcrumbs->addRouteItem('Real Estate Bundle''admin_mod_projectssites');
  112.         $this->breadcrumbs->addRouteItem('Configuratie''admin_mod_projectssites_config');
  113.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  114.         if (empty($config)) {
  115.             $config = new Config();
  116.             $config->setLanguage($this->language);
  117.             $config->setSettings($this->Settings);
  118.         }
  119.         $errors = [];
  120.         $Form $this->createFormBuilder($config);
  121.         $pageChoises = [];
  122.         $pages $this->getDoctrine()->getRepository('CmsBundle:Page')->findBy(['language' => $this->language'settings' => $this->Settings]);
  123.         foreach($pages as $page){
  124.             $pageChoises[$page->getTitle()] = $page;
  125.         }
  126.         $Form->add('overview_page'ChoiceType::class, array(
  127.             'choices' => array_merge(['Kies overzichtspagina' => ''],$pageChoises),
  128.             'attr' => ['class' => 'validate'], 'label' => 'Kies overzichtspagina *'
  129.             ,'row_attr' => ['class' => 'form-floating']));
  130.         $Form->add('detail_page_root'ChoiceType::class, array(
  131.             'choices' => array_merge(['Kies pagina detail root pagina' => ''],$pageChoises),
  132.             'attr' => ['class' => 'validate'], 'label' => 'Kies pagina detail root pagina *'
  133.             ,'row_attr' => ['class' => 'form-floating']));
  134.         $Form->add('google_maps_zoom'ChoiceType::class, array(
  135.             'choices' => array_merge(['Kies Google maps zoom level' => ''],array("Level 1"=>1,"Level 2"=>2,"Level 3"=>3,"Level 4"=>4,"Level 5"=>5,"Level 6"=>6,"Level 7"=>7,"Level 8"=>8,"Level 9"=>9,"Level 10"=>10,"Level 11"=>11,"Level 12"=>12,"Level 13"=>13,"Level 14"=>14,"Level 15"=>15,"Level 16"=>16,"Level 17"=>17,"Level 18"=>18)),
  136.             'attr' => array('placeholder' => 'Google maps zoom level'),
  137.             'row_attr' => ['class' => 'form-floating number']));
  138.         $Form->add('is_single_project'CheckboxType::class, array('label' => 'Enkel project''required' => false));
  139.         $Form->add('submit'SubmitType::class, ['label' => 'Opslaan','row_attr' => ['class' => 'none'], 'attr' => ['class' => 'btn btn-primary']]);
  140.         
  141.         $Form $Form->getForm();
  142.         $Form->handleRequest($request);
  143.         if ($Form->isSubmitted() && $Form->isValid()) {
  144.             $em->persist($config);
  145.             $em->flush($config);
  146.             return $this->redirectToRoute('admin_mod_projectssites_config');
  147.         }
  148.         return $this->render('@TrinityProjectssites/backend/config/edit.html.twig'$this->attributes([
  149.             'config' => $config,
  150.             'form' => $Form->createView()
  151.         ]));
  152.     }
  153.     
  154.     /**
  155.      * @Route("/admin/realestate/maps", name="admin_mod_projectssites_real_estate_map")
  156.      * @Template()
  157.      */
  158.     public function realEstateMap(Request $request){
  159.         // Initialize StorageController
  160.         parent::init($request);
  161.         $this->breadcrumbs->addRouteItem('Real Estate Bundle''admin_mod_projectssites');
  162.         $this->breadcrumbs->addRouteItem('Kavels mappen''admin_mod_projectssites_real_estate_map');
  163.         $realEstateMaps $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateMap')->findBy(['language' => $this->language'settings' => $this->Settings]);
  164.         return $this->render('@TrinityProjectssites/backend/realestatemap/index.html.twig'$this->attributes([
  165.             'realEstateMaps' => $realEstateMaps
  166.         ]));
  167.     }
  168.     /**
  169.      * @Route("/admin/realestate/map/add/", name="admin_mod_realestate_map_add")
  170.      * @Route("/admin/realestate/map/edit/{id}", name="admin_mod_realestate_map_edit")
  171.      * @Template()
  172.      */
  173.     public function editRealEstateMap(Request $request$id null){
  174.         // Initialize StorageController
  175.         parent::init($request);
  176.         $this->breadcrumbs->addRouteItem('Kavels''admin_mod_projectssites');
  177.         $this->breadcrumbs->addRouteItem('Kavels map Wijzigen''admin_mod_realestate_map_edit');
  178.         $em $this->getDoctrine()->getManager();
  179.         
  180.         $realEstateMap = new RealEstateMapEntity();
  181.         $realEstateMapClass = new RealEstateMap();
  182.         $realEstateMapClass->setLanguage($this->language)
  183.             ->setSettings($this->Settings)
  184.             ->setRequest($request)
  185.             ->setLanguage($this->language)
  186.             ->setSettings($this->Settings)
  187.             ->setDoctrine($em);
  188.         $Form $this->createFormBuilder($realEstateMap); 
  189.         if(!empty($id)){
  190.             $realEstateMap $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateMap')->find($id);
  191.             if(empty($realEstateMap)){
  192.                 return $this->redirectToRoute('admin_mod_projectssites_real_estate_map');
  193.             }
  194.             $Form $this->createFormBuilder($realEstateMap); 
  195.             if($realEstateMap->getSettings()->getId() != $this->Settings->getId()){
  196.                 return $this->redirectToRoute('admin_mod_projectssites_real_estate_map');
  197.             }
  198.         }
  199.         
  200.         $Form $realEstateMapClass->setCurrentForm($Form)->getForm();
  201.         if(!empty($request)){
  202.             if ($Form->isSubmitted() && $Form->isValid()){
  203.                 if ($realEstateMapClass->getMessageType() == 'success'){
  204.                     if($_POST["action"] == "submit"){
  205.                         return $this->redirectToRoute('admin_mod_realestate_map_edit',["id" => $realEstateMap->getId()]);
  206.                     }else{
  207.                         return $this->redirectToRoute('admin_mod_projectssites_real_estate_map');
  208.                     }
  209.                     
  210.                 }
  211.                 $this->addFlash($realEstateMapClass->getMessageType(), $realEstateMapClass->getMessage());
  212.             }
  213.         }
  214.         return $this->render('@TrinityProjectssites/backend/realestatemap/edit.html.twig'$this->attributes([
  215.             'realEstateMap' => $realEstateMap,
  216.             'form' => $Form->createView(),
  217.             'maxFileSize' => 10,
  218.             'maxMediaFileSize' => $this->Settings->getMaxMediaSizeInKB()
  219.         ]));
  220.     }
  221.     
  222.     /**
  223.     * @Route("/admin/realestatemap/{id}/delete", name="admin_realestate_map_remove")
  224.     */
  225.     public function deleteRealEstateMap(Request $request$id null){
  226.        parent::init($request);
  227.        $em $this->getDoctrine()->getManager();
  228.        $realestate $this->getDoctrine()->getRepository('TrinityProjectenBundle:RealEstateMap')->find($id);
  229.        $em->remove($realestate);
  230.        $em->flush();
  231.        return $this->redirectToRoute('admin_mod_projectssites_real_estate_map');
  232.     }
  233.     /**
  234.      * @Route("/ajax/get/address/", name="admin_mod_ajax_get_address")
  235.      */
  236.     public function getAddressInfo(Request $request){
  237.         parent::init($request);
  238.         $addresssInfo = [];
  239.         if(isset($_POST['postcode']) && isset($_POST['housenumber'])){
  240.             $postcode $_POST['postcode'];
  241.             $housenumber $_POST['housenumber'];
  242.             $postcodeApi = new Postcode($this->Settings);
  243.             $addresssInfo $postcodeApi->fetch($postcode$housenumber);
  244.         }
  245.         return new JsonResponse($addresssInfo);
  246.     }
  247.     /**
  248.      * @Route("/ajax/get/konva/", name="admin_mod_ajax_get_konva")
  249.      */
  250.     public function ajaxGetMapKonva(Request $request){
  251.         parent::init($request);
  252.         if(!empty($_POST["mapId"])){
  253.             $mapId $_POST["mapId"];
  254.             $realEstateMap $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateMap')->find($mapId);
  255.             
  256.             $convaHtml $this->renderView('@TrinityProjectssites/frontend/realestate/konva.html.twig'$this->attributes([
  257.                 'realestatemap' => $realEstateMap,                
  258.             ]));
  259.             return new JsonResponse(['status' => true,'realestatemap' => "/".$realEstateMap->getMapimage()->getWebPath(),'convaHtml'=> $convaHtml]);
  260.         }
  261.         return new JsonResponse(['status' => false]);
  262.     }
  263.     /**
  264.      * @Route("/admin/realestate/add/", name="admin_mod_realestate_add")
  265.      * @Route("/admin/realestate/edit/{id}", name="admin_mod_realestate_edit")
  266.      * @Template()
  267.     */
  268.     public function editRealEstate(Request $request$id null){
  269.         // Initialize StorageController
  270.         parent::init($request);
  271.         $this->breadcrumbs->addRouteItem('Kavels''admin_mod_projectssites');
  272.         if(!empty($id)){
  273.             $this->breadcrumbs->addRouteItem('Kavel Wijzigen''admin_mod_realestate_edit');
  274.         }else{
  275.             $this->breadcrumbs->addRouteItem('Kavel Toevoegen''admin_mod_realestate_add');
  276.         }
  277.         $em $this->getDoctrine()->getManager();
  278.         $realEstate = new RealEstateEntity();
  279.         $realEstateClass = new RealEstate();
  280.         $realEstateClass->setLanguage($this->language)
  281.             ->setSettings($this->Settings)
  282.             ->setId($id)
  283.             ->setRequest($request)
  284.             ->setLanguage($this->language)
  285.             ->setSettings($this->Settings)
  286.             ->setDoctrine($em);
  287.         $Form $this->createFormBuilder($realEstate); 
  288.         
  289.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  290.         if(!empty($id)){
  291.             $realEstate $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->find($id);
  292.             if(empty($realEstate)){
  293.                 return $this->redirectToRoute('admin_mod_projectssites');
  294.             }
  295.             $Form $this->createFormBuilder($realEstate); 
  296.             if($realEstate->getSettings()->getId() != $this->Settings->getId()){
  297.                 return $this->redirectToRoute('admin_mod_projectssites');
  298.             }
  299.         }
  300.         $Form $realEstateClass->setCurrentForm($Form)->getForm();
  301.         if(!empty($request)){
  302.             if ($Form->isSubmitted() && $Form->isValid()){
  303.                 if ($realEstateClass->getMessageType() == 'success'){                    
  304.                     if($_POST["action"] == "submit"){
  305.                         return $this->redirectToRoute('admin_mod_realestate_edit',["id" => $realEstate->getId()]);
  306.                     }else{
  307.                         return $this->redirectToRoute('admin_mod_projectssites');
  308.                     }
  309.                 }
  310.                 $this->addFlash($realEstateClass->getMessageType(), $realEstateClass->getMessage());
  311.             }
  312.         }     
  313.         $realEstateMap null;
  314.         if(!empty($id)){
  315.             $realEstateMap $realEstate->getRealEstateMap(); 
  316.         }
  317.         $realEstateOptionPrices $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionPrice')->findBy(['real_estate' => $id]);
  318.         
  319.         return $this->render('@TrinityProjectssites/backend/realestate/edit.html.twig'$this->attributes([
  320.             'realestate' => $realEstate,
  321.             'realEstateMap' => $realEstateMap,
  322.             'form' => $Form->createView(),
  323.             'maxFileSize' => 10,
  324.             'maxMediaFileSize' => $this->Settings->getMaxMediaSizeInKB(),
  325.             'config' => $config,
  326.             'realEstateOptionPrices' => $realEstateOptionPrices,
  327.         ]));
  328.     } 
  329.     /**
  330.      * @Route("/admin/realestateoption/add", name="admin_mod_realestate_option_add")
  331.      * @Route("/admin/realestateoption/edit/{id}", name="admin_mod_realestate_option_edit")
  332.      * @Template()
  333.      */
  334.     public function editRealEstateOption(Request $request,$id null){
  335.         // Initialize StorageController
  336.         parent::init($request);
  337.         $this->breadcrumbs->addRouteItem('Kavels''admin_mod_projectssites');
  338.         $this->breadcrumbs->addRouteItem('Kavel optie Wijzigen''admin_mod_realestate_edit');
  339.         $em $this->getDoctrine()->getManager();
  340.         $realEstateOption = new RealEstateOptionEntity();
  341.         $realEstateOptionContent = [];
  342.         $realEstateOptionDownload = [];
  343.         $realEstateAttribute = [];
  344.         $realEstateOptionClass = new RealEstateOption();
  345.         $realEstateOptionClass->setLanguage($this->language)
  346.             ->setSettings($this->Settings)
  347.             ->setRequest($request)
  348.             ->setLanguage($this->language)
  349.             ->setSettings($this->Settings)
  350.             ->setDoctrine($em);
  351.         $Form $this->createFormBuilder($realEstateOption); 
  352.         if(!empty($id)){
  353.             $realEstateOption $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')->find($id);
  354.             if(empty($realEstateOption)){
  355.                 return $this->redirectToRoute('admin_mod_realestateoptions');
  356.             }
  357.             $Form $this->createFormBuilder($realEstateOption); 
  358.             if($realEstateOption->getSettings()->getId() != $this->Settings->getId()){
  359.                 return $this->redirectToRoute('admin_mod_realestateoptions');
  360.             }
  361.             $realEstateOptionContent $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionContent')->findBy(['real_estate_option' => $id]);
  362.             $realEstateOptionDownload $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionDownload')->findBy(['real_estate_option' => $id]);
  363.             $realEstateAttribute $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateAttribute')->findBy(['real_estate_option' => $id]);
  364.         }
  365.         $Form $realEstateOptionClass->setCurrentForm($Form)->getForm();
  366.         if(!empty($request)){
  367.             if ($Form->isSubmitted() && $Form->isValid()){
  368.                 if ($realEstateOptionClass->getMessageType() == 'success'){
  369.                     if($_POST["action"] == "submit"){
  370.                         return $this->redirectToRoute('admin_mod_realestate_option_edit',["id" => $realEstateOption->getId()]);
  371.                     }else{
  372.                         return $this->redirectToRoute('admin_mod_realestateoptions');
  373.                     }
  374.                     
  375.                 }
  376.                 $this->addFlash($realEstateOptionClass->getMessageType(), $realEstateOptionClass->getMessage());
  377.             }
  378.         }
  379.         $realEstateOption $realEstateOptionClass->setFotos($realEstateOption);
  380.         
  381.         
  382.         return $this->render('@TrinityProjectssites/backend/realestateoption/edit.html.twig'$this->attributes([
  383.             'realEstateOption' => $realEstateOption,
  384.             'realEstateOptionContent' => $realEstateOptionContent,
  385.             'realEstateOptionDownload' => $realEstateOptionDownload,
  386.             'realEstateAttribute' => $realEstateAttribute,
  387.             'form' => $Form->createView(),
  388.             'maxFileSize' => 10,
  389.             'maxMediaFileSize' => $this->Settings->getMaxMediaSizeInKB()
  390.         ]));
  391.     } 
  392.     /**
  393.      * Handle uploaded files
  394.      *
  395.      * @Route("/trinity/projects/upload/", name="trinity_mod_projects_upload")
  396.      */
  397.     public function uploadAction(Request $request){
  398.         parent::init($request);
  399.         if (!empty($_FILES['file'])) {
  400.             $file $_FILES['file'];
  401.             $uploadedfile = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], (int)$file['error']);
  402.             $em $this->getDoctrine()->getManager();
  403.             $mediadir $this->getDoctrine()->getRepository('CmsBundle:Mediadir')->findPathByName($em, (!empty($this->Settings->getHost()) ? $this->Settings->getHost() . '/' '') .
  404.                 $this->trans('Instructor', [], 'neutral'), $this->language);
  405.             $mediafile = new Media();
  406.             $mediafile->setParent($mediadir);
  407.             $mediafile->setLabel($file['name']);
  408.             $mediafile->setDateAdd();
  409.             $mediafile->setFile($uploadedfile);
  410.             $mediafile->preUpload();
  411.             $mediafile->upload();
  412.             $em->persist($mediafile);
  413.             $em->flush($mediafile);
  414.             $mediafile->webPath $mediafile->getWebPath();
  415.             $mediafile->createWebP($this->Settings$mediafile->getPath(), true);
  416.             return new JsonResponse([
  417.                 'status' => true,
  418.                 'mediaid' => $mediafile->getId(),
  419.                 'webpath' => $mediafile->getWebpath(),
  420.             ]);
  421.         }
  422.         if (!empty($_FILES['media'])) {
  423.             $file $_FILES['media'];
  424.             $uploadedfile = new UploadedFile($file['tmp_name'][0], $file['name'][0], $file['type'][0], (int)$file['error'][0]);
  425.             $em $this->getDoctrine()->getManager();
  426.             $mediadir $this->getDoctrine()->getRepository('CmsBundle:Mediadir')->findPathByName($em, (!empty($this->Settings->getHost()) ? $this->Settings->getHost() . '/' '') .
  427.                 $this->trans('Instructor', [], 'neutral'), $this->language);
  428.             $mediafile = new Media();
  429.             $mediafile->setParent($mediadir);
  430.             $mediafile->setLabel($file['name'][0]);
  431.             $mediafile->setDateAdd();
  432.             $mediafile->setFile($uploadedfile);
  433.             $mediafile->preUpload();
  434.             $mediafile->upload();
  435.             $em->persist($mediafile);
  436.             $em->flush($mediafile);
  437.             $mediafile->webPath $mediafile->getWebPath();
  438.             $mediafile->createWebP($this->Settings$mediafile->getPath(), true);
  439.             return new JsonResponse([
  440.                 'status' => true,
  441.                 'mediaid' => $mediafile->getId(),
  442.                 'webpath' => $mediafile->getWebpath(),
  443.             ]);
  444.         }
  445.         return new JsonResponse([
  446.             'status' => false,
  447.             '_FILES' => (!empty($_FILES) ? $_FILES : []),
  448.             '_POST' => (!empty($_POST) ? $_POST : []),
  449.             'error' => 'No file given',
  450.         ]);
  451.     }
  452.     
  453.     /**
  454.      * @Route("/admin/realestate/{id}/delete", name="admin_realestate_remove")
  455.     */
  456.     public function deleteRealEstate(Request $request$id null){
  457.        parent::init($request);
  458.        $em $this->getDoctrine()->getManager();
  459.        $realEstate $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->find($id);
  460.        $em->remove($realEstate);
  461.        $em->flush();
  462.        return $this->redirectToRoute('admin_mod_projectssites');
  463.     } 
  464.     
  465.     /**
  466.      * @Route("/admin/realestateoption/{id}/delete", name="admin_realestate_option_remove")
  467.     */
  468.     public function deleteRealEstateOption(Request $request$id null){
  469.        parent::init($request);
  470.        $em $this->getDoctrine()->getManager();
  471.        $realEstateOption $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')->find($id);
  472.        $em->remove($realEstateOption);
  473.        $em->flush();
  474.        return $this->redirectToRoute('admin_mod_realestateoptions');
  475.     }
  476.     
  477.     /**
  478.      * @Route("/admin/realestateoptioncontent/{optionId}/{id}/delete", name="admin_mod_realestatecontent_delete")
  479.      */
  480.     public function deleteRealEstateOptionContent(Request $request$realEstateId$optionId$id null){
  481.         parent::init($request);
  482.         $em $this->getDoctrine()->getManager();
  483.         $realestateOptionContent $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionContent')->find($id);
  484.         $em->remove($realestateOptionContent);
  485.         $em->flush();
  486.  
  487.         return $this->redirectToRoute('admin_mod_realestate_option_edit',["id" => $optionId]);
  488.      }
  489.    
  490.     
  491.     /**
  492.      * @Route("/admin/realestateoption/deletemedia/{optionId}/{mediaid}",
  493.      *      name="admin_mod_realestateoption_media_delete",
  494.      *      requirements = {
  495.      *          "id" = "\d+",
  496.      *          "mediaid" = "\d+"
  497.      *      }
  498.      * )
  499.      */
  500.     public function deleteMediaAction(Request $request$optionId null$mediaid null){
  501.         $em $this->getDoctrine()->getManager();
  502.         $realEstateOption $em->getRepository('TrinityProjectssitesBundle:RealEstateOption')->find($optionId);
  503.         if(!empty($realEstateOption)){
  504.             if(!empty($realEstateOption->getHeader()) && $realEstateOption->getHeader()->getId() == $mediaid){
  505.                 $realEstateOption->setHeader(null);
  506.             }elseif(!empty($realEstateOption->getThumbnail()) && $realEstateOption->getThumbnail()->getId() == $mediaid){
  507.                 $realEstateOption->setThumbnail(null);
  508.             }else{
  509.                 $media $em->getRepository('CmsBundle:Media')->find($mediaid);
  510.                 $ids $realEstateOption->removeMediaId($media);
  511.                 $realEstateOption->emptyFotoGallery();
  512.                 foreach ($ids as $id) {
  513.                     $realEstateOption->addFotoGalleryItem($em->getRepository('CmsBundle:Media')->find($id));
  514.                 }
  515.                 $realEstateOption->setFotoGallery($realEstateOption->getFotoGalleryCollection());
  516.             }
  517.             $em->persist($realEstateOption);
  518.             $em->flush();
  519.         }
  520.         return $this->redirectToRoute('admin_mod_realestate_option_edit', ['id' => $optionId]);
  521.     }   
  522.    
  523.     /**
  524.       * @Route("/admin/realestatemap/deletemedia/{mapId}/{mediaId}",
  525.       *      name="admin_mod_realestate_map_media_delete",
  526.       *      requirements = {
  527.       *          "id" = "\d+",
  528.       *          "mediaid" = "\d+"
  529.       *      }
  530.       * )
  531.      */
  532.     public function deleteMediaRealEstateMapAction(Request $request$mapId null$mediaId null){
  533.          $em $this->getDoctrine()->getManager();
  534.          $realEstateMap $em->getRepository('TrinityProjectssitesBundle:RealEstateMap')->find($mapId);
  535.  
  536.          if(!empty($realEstateMap) && !empty($mediaId)){
  537.              if(!empty($realEstateMap->getMapImage()) && $realEstateMap->getMapImage()->getId() == $mediaId){
  538.                  $realEstateMap->setMapImage(null);
  539.                  //$media = $em->getRepository('CmsBundle:Media')->find($mediaId);
  540.                  //$realEstateMap->removeMediaId($media);
  541.              }else{
  542.                 $media $em->getRepository('CmsBundle:Media')->find($mediaId);
  543.                 $em->remove($media);
  544.              }
  545.  
  546.              $em->persist($realEstateMap);
  547.              $em->flush();
  548.          }
  549.          return $this->redirectToRoute('admin_mod_realestate_map_edit', ["id"=> $mapId]);
  550.     } 
  551.     
  552.     /**
  553.      * @Route("/admin/realestateoptiondownload/{optionId}/{id}/delete", name="admin_mod_realestatedownload_delete")
  554.       */
  555.     public function deleteMediaRealEstateDownload(Request $request$optionId$id null){
  556.         parent::init($request);
  557.         $em $this->getDoctrine()->getManager();
  558.         $realestateOptionDownload $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionDownload')->find($id);
  559.         $em->remove($realestateOptionDownload);
  560.         $em->flush();
  561.  
  562.         return $this->redirectToRoute('admin_mod_realestate_option_edit',["id" => $optionId]);
  563.     }
  564.     
  565.     /**
  566.      * @Route("/admin/realestatecontent/deletemedia/{id}/{mediaid}",
  567.      *      name="admin_mod_realestatecontent_media_delete",
  568.      *      requirements = {
  569.      *          "id" = "\d+",
  570.      *          "mediaid" = "\d+"
  571.      *      }
  572.      * )
  573.      */
  574.     public function deleteMediaRealEstateContentAction(Request $request$id null$mediaid null){
  575.         $em $this->getDoctrine()->getManager();
  576.         $realEstateContent $em->getRepository('TrinityProjectssitesBundle:RealEstateOptionContent')->find($id);
  577.         if(!empty($realEstateContent)){
  578.             if(!empty($realEstateContent->getImage()) && $realEstateContent->getImage()->getId() == $mediaid){
  579.                 $realEstateContent->setImage(null);
  580.                 $media $em->getRepository('CmsBundle:Media')->find($mediaid);
  581.                 $em->remove($media);
  582.             }
  583.             $em->persist($realEstateContent);
  584.             $em->flush();
  585.         }
  586.         return $this->redirectToRoute('admin_mod_realestate_edit', ['id' => $id]);
  587.     }  
  588.     
  589.     /**
  590.      * @Route("/admin/realestateattribute/{optionId}/{id}/delete", name="admin_mod_realestateattribute_delete")
  591.       */
  592.     public function deleteRealEstateAttribute(Request $request$optionId$id null){
  593.         parent::init($request);
  594.         $em $this->getDoctrine()->getManager();
  595.         $realestateAttribute $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateAttribute')->find($id);
  596.         $em->remove($realestateAttribute);
  597.         $em->flush();
  598.  
  599.         return $this->redirectToRoute('admin_mod_realestate_option_edit',["id" => $optionId]);
  600.     }
  601.     
  602.     private function getPriceRange($priceFrom null$priceTo null){                
  603.         $priceRange $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')
  604.             ->getPriceRange($this->language,$this->Settings);
  605.         if(!empty($priceRange)){
  606.             $prices $priceRange[0];
  607.             $priceRange = [0,number_format($prices['max_price'],0,',','.')];
  608.         }   
  609.         if(!empty($priceFrom)){
  610.             $priceRange = [number_format(floor($priceFrom),0,',','.'), number_format(ceil($prices['max_price']),0,',','.')];
  611.         }elseif(!empty($priceTo)){
  612.             $priceRange = [0number_format(ceil($priceTo),0,',','.')];
  613.         }
  614.         return $priceRange;
  615.     }
  616.     /**
  617.      * Show bundle content to front
  618.      *
  619.      * @param array $config Array with configuration options
  620.      * @param array $params Additional parameters
  621.      *
  622.      * @return string         HTML
  623.      */
  624.     public function showAction($config$params = [], $request){
  625.         parent::init($request);
  626.         if(isset($config["realestatesmapswidget"]) && $config["realestatesmapswidget"] == "on"){
  627.             return $this->widgetMaps($request);
  628.         }
  629.         if(isset($config["projectssitegooglemapswidget"]) && $config["projectssitegooglemapswidget"] == "on"){
  630.             return $this->widgetOverview($request);
  631.         }
  632.         if(isset($config["projectwidget"]) && $config["projectwidget"] == "on"){
  633.             return $this->widgetDetail($request$params);
  634.         }
  635.         if(isset($config["realestateswidget"]) && $config["realestateswidget"] == "on"){
  636.             return $this->widgetRealEstates($request$params);
  637.         }
  638.         if(isset($config["realestateOptionswidget"]) && $config["realestateOptionswidget"] == "on"){
  639.             return $this->widgetRealEstateOptions($request$params);
  640.         }
  641.     }
  642.     private function widgetOverview($request){
  643.         $realEstateEntity = new RealEstateEntity();
  644.         $realEstateClass = new RealEstate();
  645.         $realEstateOptionClass = new RealEstateOption();
  646.         
  647.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  648.         $response $this->realEstateFilter(nullnullnullnullnull301);
  649.         $realEstates $response['realestates'];
  650.         $realEstateMap null;
  651.         $realEstateOptionPrices = [];
  652.         $index 0;
  653.         foreach ($realEstates as $realEstate) {
  654.             $realEstate $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->findOneBy(['id' => $realEstate->getId()]);
  655.             $realestateOptions $realEstate->getRealEstateOptions();
  656.             $realEstateMap $realEstate->getRealEstateMap();
  657.             
  658.             if($config->getIsSingleProject()){
  659.                 $realEstate->category_txt $realEstate->getCategories(true)[$realEstate->getCategory()];
  660.                 $response['realestate_hydrated'][$index]['category_txt'] = $realEstate->category_txt;
  661.                 $realEstate->status_txt $realEstate->getStatusses(true)[$realEstate->getStatus()];
  662.                 $response['realestate_hydrated'][$index]['status_txt'] = $realEstate->status_txt;
  663.             }
  664.             if(!empty($realestateOptions)){
  665.                 $realEstate->options $realestateOptions;
  666.                 foreach($realestateOptions as $realestateOption){
  667.                     $realestateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($realestateOption);
  668.                     $realEstateOptionPrice $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionPrice')->findOneBy([
  669.                         'real_estate' => $realEstate->getId(), 'real_estate_option' => $realestateOption->getId()]);
  670.                     if(!empty($realEstateOptionPrice)){
  671.                         $realEstateOptionPrices[$realEstate->getId()][$realestateOption->getId()] = $realEstateOptionPrice->getCost();
  672.                         //dump($realEstate->getId()." ".$realestateOption->getId()." ".$realEstateOptionPrice->getCost());
  673.                         //dump($realEstates);
  674.                     }
  675.                 }
  676.                 if(!empty($realestateOptions[0])){
  677.                     $response['realestate_hydrated'][$index]['slug'] = $realestateOptions[0]->getSlug();
  678.                     $realEstate->foto $realestateOptions[0]->getThumbnail();
  679.                     if(!empty($realestateOptions[0]->getThumbnail())){
  680.                         $response['realestate_hydrated'][$index]['foto'] = $realestateOptions[0]->getThumbnail()->getWebPath();
  681.                     }
  682.                 }               
  683.                 //$images = $realestateOptions[0]->getFotoGalleryCollection();
  684.                 //if(!empty($images)){
  685.                     //$realEstate->foto = $images[0];
  686.                 //}
  687.             }
  688.             $index++;
  689.         }
  690.         //die();
  691.         
  692.         $priceRange $this->getPriceRange();
  693.         
  694.         $latitude 0;
  695.         $longitude 0;
  696.         
  697.         $coords $this->getCoords("Nederland");
  698.         $latitude $coords['lat'];
  699.         $longitude $coords['long'];
  700.         $bundlePath $this->container->get('kernel')->locateResource('@TrinityProjectssitesBundle');
  701.         $projectPath $this->get('kernel')->getProjectDir();
  702.         $marker '/bundles/trinityprojectssites/img/marker.png';
  703.         if(file_exists($projectPath."/public/img/placeholder.jpg")){
  704.             $marker "/img/marker.png";
  705.         }
  706.         $vars = [
  707.             'count' => $response['totalCount'],
  708.             'realestate_hydrated' => $response['realestate_hydrated'],
  709.             'realestates' => $realEstates,
  710.             'marker' => $marker,
  711.             'realEstateEntity' => $realEstateEntity,
  712.             'config' => $config,
  713.             'priceRange' => $priceRange,
  714.             'search_lat' => $latitude
  715.             'search_long' => $longitude,
  716.             'googleMapsZoomLvl' => $config->getGoogleMapsZoom(),
  717.             'realEstateOptionPrices' => $realEstateOptionPrices,
  718.         ];
  719.         $vars['realestatemap'] = $realEstateMap;
  720.         return $this->renderView('@TrinityProjectssites/frontend/realestate/widget_overview.html.twig'$vars);
  721.     }
  722.     private function widgetMaps($request){
  723.         $realEstateEntity = new RealEstateEntity();
  724.         $realEstateClass = new RealEstate();
  725.         $realEstateOptionClass = new RealEstateOption();
  726.         
  727.         $response $this->realEstateFilter(nullnullnullnullnull301);
  728.         $realEstates $response['realestates'];
  729.         $index 0;
  730.         foreach ($realEstates as $realEstate) {
  731.             $realestateOptions $realEstate->getRealEstateOptions();
  732.             if(!empty($realestateOptions)){
  733.                 $realEstate->options $realestateOptions;
  734.                 foreach($realestateOptions as $realestateOption){
  735.                     $realestateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($realestateOption);
  736.                 }
  737.                 if(!empty($realestateOptions[0])){
  738.                     $response['realestate_hydrated'][$index]['slug'] = $realestateOptions[0]->getSlug();
  739.                     $realEstate->foto $realestateOptions[0]->getThumbnail();
  740.                     if(!empty($realestateOptions[0]->getThumbnail())){
  741.                         $response['realestate_hydrated'][$index]['foto'] = $realestateOptions[0]->getThumbnail()->getWebPath();
  742.                     }
  743.                 }
  744.                 //$images = $realestateOptions[0]->getFotoGalleryCollection();
  745.                 //if(!empty($images)){
  746.                     //$realEstate->foto = $images[0];
  747.                 //}
  748.             }
  749.             $index++;
  750.         }
  751.         
  752.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  753.         $priceRange $this->getPriceRange();
  754.         
  755.         $latitude 0;
  756.         $longitude 0;
  757.         
  758.         $coords $this->getCoords("Nederland");
  759.         $latitude $coords['lat'];
  760.         $longitude $coords['long'];
  761.         $bundlePath $this->container->get('kernel')->locateResource('@TrinityProjectssitesBundle');
  762.         $projectPath $this->get('kernel')->getProjectDir();
  763.         $marker '/bundles/trinityprojectssites/img/marker.png';
  764.         if(file_exists($projectPath."/public/img/marker.png")){
  765.             $marker "/img/marker.png";
  766.         }
  767.         $vars = [
  768.             'count' => $response['totalCount'],
  769.             'realestate_hydrated' => $response['realestate_hydrated'],
  770.             'realestates' => $realEstates,
  771.             'realEstateEntity' => $realEstateEntity,
  772.             'config' => $config,
  773.             'marker' => $marker,
  774.             'googleMapsZoomLvl' => $config->getGoogleMapsZoom(),
  775.             'priceRange' => $priceRange,
  776.             'search_lat' => $latitude
  777.             'search_long' => $longitude,
  778.         ];
  779.         //if($config->getIsSingleProject()){
  780.             $realestatemap $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateMap')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  781.             $vars['realestatemap'] = $realestatemap;
  782.         //}
  783.         return $this->renderView('@TrinityProjectssites/frontend/realestate/widget_maps.html.twig'$vars);
  784.     }    
  785.     function distance($lat1$lon1$lat2$lon2){
  786.         $theta $lon1 $lon2;
  787.         $dist sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  788.         $dist acos($dist);
  789.         $dist rad2deg($dist);
  790.         $miles $dist 60 1.1515;
  791.         return ($miles 1.609344);
  792.     }
  793.     public function realEstateFilter($place$province$priceStart$priceEnd$status$maxDistance$page null){
  794.         $latitude 0;
  795.         $longitude 0;
  796.         $errorMsg '';
  797.         if ($place !== "" && strlen($place) > 1) {
  798.             $coords $this->getCoords($place);
  799.             $latitude $coords['lat'];
  800.             $longitude $coords['long'];
  801.         }
  802.         $repo $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate');
  803.         $realEstateArray $repo->search($place$province$priceStart$priceEnd$statusnull,$this->language,$this->Settings);
  804.         $realestates $realEstateArray['realestates'];
  805.         $realestatemap null;
  806.         $maxDistance = (int)$maxDistance;
  807.         $counter 0;
  808.         foreach ($realestates as $realestate) {
  809.             $realestatemap $realestate->getRealEstateMap();    
  810.             $realestate $repo->findOneBy(["id" => $realestate->getId()]);
  811.             if ($maxDistance != "0" && $latitude !== 0) {
  812.                 $calculatedDistance $this->distance($latitude$longitude$realestate->getLatitude(), $realestate->getLongitude());
  813.                 if($calculatedDistance $maxDistance){
  814.                     unset($realestates[array_search($realestate$realestates)]);
  815.                     unset($realEstateArray['realestate_hydrated'][$counter]);
  816.                 }
  817.             }
  818.             $counter++;
  819.         }
  820.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  821.         $vars = [
  822.             'realestates' => $realestates,
  823.             'config' => $config,
  824.             'realestate_hydrated' => $realEstateArray['realestate_hydrated'],
  825.         ];
  826.         $konvaHtml $this->renderView('@TrinityProjectssites/frontend/realestate/konva.html.twig'$vars);
  827.         $vars = [
  828.             'realestatemap' => $realestatemap,
  829.             'konva' => $konvaHtml,
  830.             'realestates' => $realestates,
  831.             'realestate_hydrated' => $realEstateArray['realestate_hydrated'],
  832.             'errorMsg' => $errorMsg
  833.             'totalCount' => count($realestates), 
  834.             'search_lat' => $latitude
  835.             'search_long' => $longitude
  836.         ];
  837.         return $vars;
  838.     }
  839.     /**
  840.      * @Route("/ajax/realestate/search/{page}", name="admin_mod_ajax_realestate")
  841.      */
  842.     public function searchAction(Request $request$page 1){
  843.         parent::init($request);
  844.         
  845.         $realEstateEntity = new RealEstateEntity();
  846.         $realEstateClass = new RealEstate();
  847.         $realEstateOptionClass = new RealEstateOption();
  848.         $place $_POST['place'];
  849.         $province $_POST['province'];
  850.         $priceFrom $_POST['price_from'];
  851.         $priceTo $_POST['price_to'];
  852.         $dist $_POST['max_dist'];
  853.         $status $_POST['status'];
  854.         $priceRange $this->getPriceRange($priceFrom$priceTo);
  855.         $response $this->realEstateFilter($place$province$priceFrom$priceTo$status$dist$page);
  856.         $realestates $response['realestates'];
  857.         $index 0;
  858.         foreach ($realestates as $realEstate) {
  859.             $realestateOptions $realEstate->getRealEstateOptions();
  860.             
  861.             if(!empty($realestateOptions)){
  862.                 $realEstate->options $realestateOptions;
  863.                 foreach($realestateOptions as $realestateOption){
  864.                     $realestateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($realestateOption);
  865.                 }
  866.                 $realEstate->foto $realestateOptions[0]->getThumbnail();
  867.                 $response['realestate_hydrated'][$index]['foto'] = $realestateOptions[0]->getThumbnail()->getWebPath();
  868.                 //$images = $realestateOptions[0]->getFotoGalleryCollection();
  869.                 //if(!empty($images)){
  870.                     //$realEstate->foto = $images[0];
  871.                 //}
  872.             }
  873.             $index++; 
  874.         }
  875.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  876.         $html $this->renderView('@TrinityProjectssites/frontend/realestate/realestates.html.twig', [
  877.             'realestates' => $realestates,
  878.             'config' => $config,
  879.         ]);
  880.         
  881.         $vars = [
  882.             'konva' => $response['konva'],
  883.             'html' => $html,
  884.             'realestates' => $response['realestate_hydrated'],
  885.             'error' => $response['errorMsg'],
  886.             'count' => $response['totalCount'],
  887.             'search_lat' => $response['search_lat'],
  888.             'search_long' => $response['search_long'],
  889.             'priceRange' => $priceRange,
  890.         ];
  891.         //if($config->getIsSingleProject()){
  892.             $realestatemap $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateMap')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  893.             $vars['realestatemap'] = $realestatemap;
  894.         //}
  895.         return new JsonResponse($vars);
  896.     }
  897.     function getCoords($placename null){
  898.         $coords = [];
  899.         $uri 'https://maps.googleapis.com/maps/api/geocode/json?address=' $placename ',NL&key=AIzaSyC042fMu6ZYNvJfBtKOnhEvlPpAs5XNy18';
  900.         $curl curl_init();
  901.         curl_setopt($curlCURLOPT_URL$uri);
  902.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  903.         $response curl_exec($curl);
  904.         curl_close($curl);
  905.         $response json_decode($response1);
  906.         if(!empty($response['results'])){
  907.             $coords['lat'] = $response['results'][0]['geometry']['location']['lat'];
  908.             $coords['long'] = $response['results'][0]['geometry']['location']['lng'];
  909.         } else {
  910.             $coords['lat'] = 0;
  911.             $coords['long'] = 0;
  912.         }
  913.         return $coords;
  914.     }
  915.     /**
  916.      * @Route("/kavel/{slug}", name="admin_mod_realestate_detail")
  917.      */
  918.     private function widgetDetail(Request $request$slug null){        
  919.         $realEstateOptionEntity = new RealEstateOptionEntity();    
  920.         $realEstateEntity = new RealEstateEntity();
  921.         $realEstateOptionClass = new RealEstateOption();
  922.         $realEstateOption $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')->findOneBy([
  923.             'language'=> $this->language,
  924.             'settings'=> $this->Settings,
  925.             'slug' => $slug]);
  926.         if(empty($realEstateOption)){
  927.             return $this->widgetOverview($request);
  928.         }
  929.         $realEstateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($realEstateOption);        
  930.         $route $request->attributes->get('_route');
  931.         $parentPage $this->getDoctrine()->getRepository('CmsBundle:Page')->findOneBy(['slugkey' => $route]);
  932.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  933.         $realEstateOptionContent $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionContent')->findBy(['real_estate_option' => $realEstateOption->getId()]);
  934.         $realEstateOptionDownload $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionDownload')->findBy(['real_estate_option' => $realEstateOption->getId()]);
  935.         $realEstateAttributes $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateAttribute')->findBy(['real_estate_option' => $realEstateOption->getId()]);
  936.         
  937.         $vars = [
  938.             'realEstateAttributes' => $realEstateAttributes,
  939.             'realEstateOption' => $realEstateOption,
  940.             'realEstateOptionEntity' => $realEstateOptionEntity,
  941.             'realEstateEntity' => $realEstateEntity,
  942.             'parentPage' => $parentPage,
  943.             'config' => $config,
  944.             'realEstateOptionContent' => $realEstateOptionContent,
  945.             'realEstateOptionDownload' => $realEstateOptionDownload,
  946.         ];
  947.         //if($config->getIsSingleProject()){
  948.         $realEstatesHydrated $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->hydratedFindBy([
  949.             'language'=> $this->language,
  950.             'settings'=> $this->Settings]);
  951.         $realEstates $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->findBy([
  952.             'language'=> $this->language,
  953.             'settings'=> $this->Settings]);
  954.         $realEstatesCarousel = [];
  955.         foreach ($realEstates as $realEstate) {
  956.             $realEstateOptions $realEstate->getRealEstateOptions();
  957.             if(!empty($realEstateOptions)){
  958.                 $realEstate->options $realEstateOptions;
  959.                 $tmpOptions = [];
  960.                 $tmpRealEstate $realEstate;
  961.                 foreach($realEstateOptions as $tmpRealEstateOption){
  962.                     $tmpRealEstateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($tmpRealEstateOption);
  963.                     if($tmpRealEstateOption->getId() != $realEstateOption->getId()){
  964.                         $tmpOptions[] = $tmpRealEstateOption;
  965.                     }
  966.                 }
  967.                 if(count($tmpOptions) > 0){
  968.                     $tmpRealEstate->options $tmpOptions;
  969.                     $realEstatesCarousel[] = $tmpRealEstate;
  970.                 }
  971.                 
  972.                 if(!empty($realEstateOptions[0])){
  973.                     $images $realEstateOptions[0]->getFotoGalleryCollection();
  974.                     if(!empty($images)){
  975.                         //$realEstate->foto = $images[0];
  976.                         $realEstate->foto $realEstateOptions[0]->getThumbnail();
  977.                     }
  978.                 }
  979.             }
  980.         }
  981.         $vars['realEstatesCarousel'] = $realEstatesCarousel;
  982.         $vars['realestate_hydrated'] = $realEstatesHydrated;
  983.         $vars['realEstates'] = $realEstates;
  984.         return $this->renderView('@TrinityProjectssites/frontend/realestate/detail.html.twig'$vars);
  985.     }
  986.     /**
  987.      * @Route("/kavel/{slug}", name="admin_mod_realestate_detail")
  988.      */
  989.     private function widgetRealEstates(Request $request$slug null){
  990.         $realEstateOptionClass = new RealEstateOption();  
  991.         $realEstateOptionEntity = new RealEstateOptionEntity();
  992.         $realEstates $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstate')->findBy([
  993.             'language'=> $this->language,
  994.             'settings'=> $this->Settings]);
  995.             
  996.         $route $request->attributes->get('_route');
  997.         $parentPage $this->getDoctrine()->getRepository('CmsBundle:Page')->findOneBy(['slugkey' => $route]);
  998.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  999.         $vars = [
  1000.             'parentPage' => $parentPage,
  1001.             'config' => $config,
  1002.             'realEstateOption' => $realEstateOptionEntity,
  1003.         ];
  1004.         //if($config->getIsSingleProject()){
  1005.             foreach ($realEstates as $realEstate) {
  1006.                 $realestateOptions $realEstate->getRealEstateOptions();
  1007.                 if(!empty($realestateOptions)){
  1008.                     $realEstate->options $realestateOptions;
  1009.                     foreach($realestateOptions as $realestateOption){
  1010.                         $realestateOption $realEstateOptionClass->setDoctrine($this->getDoctrine())->setFotos($realestateOption);
  1011.                         //$realestateOptionPrice = $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionPrice')->get();
  1012.                         $realEstateOptionPrice $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOptionPrice')->findOneBy([
  1013.                             'real_estate' => $realEstate->getId(), 'real_estate_option' => $realestateOption->getId()]);
  1014.                         if(!empty($realEstateOptionPrice)){
  1015.                             $realestateOption->price $realEstateOptionPrice->getCost();
  1016.                         }
  1017.                     }
  1018.                     $images $realestateOptions[0]->getFotoGalleryCollection();
  1019.                     if(!empty($images)){
  1020.                         //$realEstate->foto = $images[0];
  1021.                         $realEstate->foto $realestateOptions[0]->getThumbnail();
  1022.                     }
  1023.                 }
  1024.             }
  1025.             $vars['realEstates'] = $realEstates;
  1026.         //}
  1027.         return $this->renderView('@TrinityProjectssites/frontend/realestate/widget_realestates.html.twig'$vars);
  1028.     }
  1029.     
  1030.     private function widgetRealEstateOptions(Request $request$slug null){
  1031.         $realEstateOptionClass = new RealEstateOption();  
  1032.         $realEstateOptionEntity = new RealEstateOptionEntity();
  1033.         $realEstateOptions $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:RealEstateOption')->findBy([
  1034.             'language'=> $this->language,
  1035.             'settings'=> $this->Settings]);
  1036.             
  1037.         $route $request->attributes->get('_route');
  1038.         $parentPage $this->getDoctrine()->getRepository('CmsBundle:Page')->findOneBy(['slugkey' => $route]);
  1039.         $config $this->getDoctrine()->getRepository('TrinityProjectssitesBundle:Config')->findOneBy(['language' => $this->language'settings' => $this->Settings]);
  1040.         $vars = [
  1041.             'parentPage' => $parentPage,
  1042.             'config' => $config,
  1043.             'realEstateOptionEntity' => $realEstateOptionEntity,
  1044.         ];
  1045.         //if($config->getIsSingleProject()){
  1046.             $vars['realEstateOptions'] = $realEstateOptions;
  1047.         //}
  1048.         return $this->renderView('@TrinityProjectssites/frontend/realestate/widget_realestate_options.html.twig'$vars);
  1049.     }
  1050. }