src/Notaris/FrontendBundle/Controller/DefaultController.php line 110

Open in your IDE?
  1. <?php
  2. namespace Notaris\FrontendBundle\Controller;
  3. use Notaris\AdminBundle\Entity\Module;
  4. use Notaris\AdminBundle\Entity\NotaryInfo;
  5. use Notaris\AdminBundle\Entity\SvenBannerGalleryRepository;
  6. use Notaris\AdminBundle\NotarisAdminBundle;
  7. use Pdp\Cache;
  8. use Pdp\CurlHttpClient;
  9. use Pdp\Parser;
  10. use Pdp\Manager;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  16. class DefaultController extends AbstractController
  17. {
  18.     public function indexAction(Request $request, $slug = null): Response
  19.     {
  20.         $localelistener = $this->get('notaris.locale.listener');
  21.         $notary = $localelistener->getNotary();
  22.         $isMultiLanguage = $localelistener->getIsMulti();
  23.         $host = $localelistener->getHost();
  24.         if($notary == false):
  25.             //default home page
  26.             $manager = $this->getDoctrine()->getManager();
  27.             $localeService = $this->get('notaris.locale.listener');
  28.             $locale = $localeService->getLocale();
  29. //            file_get_contents('https://immo.notaris.be/immoplatform-public-service_v1/api/authentication/guest');
  30. //
  31. //            $cookies = array();
  32. //            foreach ($http_response_header as $hdr) {
  33. //                if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
  34. //                    $cookies []= $matches[1];
  35. //                }
  36. //            }
  37. //
  38. //            // Create a stream
  39. //            $opts = [
  40. //                "http" => [
  41. //                    "method" => "GET",
  42. //                    "header" => "Cookie: " . implode("; ", $cookies)
  43. //                ]
  44. //            ];
  45. //
  46. //            $context = stream_context_create($opts);
  47. //
  48. //            $immoRequest = file_get_contents('https://immo.notaris.be/immoplatform-public-service_v1/api/properties/reference/' . '206890', false, $context);
  49. //            $immoResponse = json_decode($immoRequest);
  50. //            var_dump($immoResponse->response->id);exit;
  51.             //get home banners
  52.             $banners_repo = $manager->getRepository('Notaris\AdminBundle\Entity\HomeBanner');
  53.             $banners = $banners_repo->findActiveByLanguage($locale);
  54.             $news_repo = $manager->getRepository('Notaris\AdminBundle\Entity\News');
  55.             $news = $news_repo->getAllHomepageNews($locale);
  56.             //FEDNOTLINKS ophalen
  57.             $columntypes = array('home1', 'home2', 'home3');
  58.             /** @var  $repo_svenlinks  \Notaris\AdminBundle\Entity\ModuleLinksRepository */
  59.             $repo_svenlinks = $manager->getRepository('Notaris\AdminBundle\Entity\ModuleLinks');
  60.             $fednotmodule = array();
  61.             foreach ($columntypes as $columntype):
  62.                 $left = $repo_svenlinks->getModuleColumn($columntype, 'L', $locale);
  63.                 $center = $repo_svenlinks->getModuleColumn($columntype, 'C', $locale);
  64.                 $right = $repo_svenlinks->getModuleColumn($columntype, 'R', $locale);
  65.                 $fednotmodule[$columntype] = array('left'=>$left,'center'=>$center,'right'=>$right);
  66.             endforeach;
  67.             //NOTARIS-TV
  68.             $video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  69.             $recent_videos = $video_repo->getRecentVideos($locale,1);
  70.             //THEMES
  71.             /** @var $subsite_repo \Notaris\AdminBundle\Entity\SubsiteRepository */
  72.             $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  73.             $themes = $subsite_repo->getThemesInfo($locale);
  74.             //JOBS
  75.             $jobs_repo = $manager->getRepository('Notaris\AdminBundle\Entity\NotaryJobGeneral');
  76.             $jobs = $jobs_repo->findByLocale($locale);
  77.             $totaljobs = false;
  78.             if(isset($jobs[0])){
  79.                 $totaljobs = $jobs[0]->getTotal();
  80.             }
  81.             //IMMO
  82.             /* @var $general_repo /Notaris\AdminBundle\Entity\General */
  83.             $general_repo = $manager->getRepository('Notaris\AdminBundle\Entity\General');
  84.             $totalImmoItem = $general_repo->findOneBy(['item' => 'totalImmos']);
  85.             $totalImmos = $totalImmoItem->getValue();
  86.             //random immo image ophalen
  87.             /* @var $immo_repo /Notaris\AdminBundle\Entity\Immo */
  88.             $immo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Immo');
  89.             $immo_image = $immo_repo->randomImage();
  90.             $totalimmo = ($totalImmos) ? $totalImmos : 0;
  91.             return $this->render('@NotarisFrontend/default/index.html.twig', [
  92.                 'banners'=>$banners,
  93.                 'news' => $news,
  94.                 'fednotmodule'=>$fednotmodule,
  95.                 'videos'=>$recent_videos,
  96.                 'themes'=>$themes,
  97.                 'totalJobs'=>$totaljobs,
  98.                 'jobs'=>$jobs,
  99.                 'totalImmo' => $totalimmo,
  100.                 'immoImage'=> $immo_image
  101.             ]);
  102.         else:
  103.             //INFO: vroeger moest er taalkeuze zijn als er geen taalcookie was, nu toont hij de moedertaal van de sven
  104. //            $langCookie = "NotarySven_Lang_".$notary->getId();
  105. //            if((isset($_COOKIE[$langCookie]) AND $_COOKIE[$langCookie] == $notary->getLocale()) OR $localelistener->getSvenChoosenLang() != ''):
  106. //                $isMultiLanguage = false;
  107. //            endif;
  108. //            if($isMultiLanguage == false):
  109.                 return $this->svenAction($request, $host, $slug);
  110. //            else:
  111. //                return $this->redirect($this->generateUrl('notaris_frontend_sven_choose_language'));
  112. //            endif;
  113.         endif;
  114.         foreach ($addresses as $address) {
  115.             if($address->getSlug() == $currentslug){
  116.                 $office_id = $address->getEe();
  117.                 if(!$address->getEe()){
  118.                     $office_id = $address->getSlug();
  119.                 }
  120.                 if(!$address->getSkedifyId()){
  121.                     $address = $skedifyService->getOfficesByExternalId($office_id, $address);
  122.                 }
  123.                 if($address and $address->getSkedifyId()) {
  124.                     $showSkedify = $skedifyService->getSpecificOffice($address->getSkedifyId());
  125.                 }else{
  126.                     $showSkedify = false;
  127.                 }
  128.             }
  129.         }
  130.     }
  131.     public function downloadAction($dd,$filename)
  132.     {
  133.         $localeService = $this->get('notaris.locale.listener');
  134.         $locale = $localeService->getLocale();
  135.         if($locale == 'de'):
  136.             $locale = 'fr';
  137.         endif;
  138.         $manager = $this->getDoctrine()->getManager();
  139.         $attachment_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Attachment');
  140.         $filename = urldecode($filename);
  141.         $dd = urldecode($dd);
  142.         $attachment = $attachment_repo->findOneByFilename('/'.$dd .'/'. $filename);
  143.         $file = $this->get('kernel')->getRootDir() . "/../web/uploads/$locale" . $attachment->getFilename() ;
  144.         $response = new BinaryFileResponse($file);
  145.         BinaryFileResponse::trustXSendfileTypeHeader();
  146.         $response->headers->set('Content-type', $attachment->getFileType());
  147.         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $attachment->getOriginalFilename()  );
  148.         return $response;
  149.     }
  150.     public function clearAction(){
  151.         opcache_reset();
  152.         echo "opcache reset";
  153.     }
  154.     public function svenAction(Request $request, $host, $slug)
  155.     {
  156.         $localelistener = $this->get('notaris.locale.listener');
  157.         $locale = $localelistener->getLocale();
  158.         $address_info = false;
  159.         $manager = $this->getDoctrine()->getManager();
  160.         /** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressInfoRepository */
  161.         $svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  162.         /** @var $address_info \Notaris\AdminBundle\Entity\SvenAddressInfo */
  163.         /** @var $notary \Notaris\AdminBundle\Entity\Notary */
  164.         $notary = $localelistener->getNotary();
  165.         if($notary):
  166.             //keep chosen address in session
  167.             $session = $request->getSession();
  168.             if(sizeof($notary->getAddresses()) > 1){
  169.                 if($slug){
  170.                     /** @var $notaryInfo_repo \Notaris\AdminBundle\Entity\NotaryInfoRepository */
  171.                     $notaryInfo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\NotaryInfo');
  172.                     $address_info = $svenAddress_repo->getAddressFromNotary($notary, $slug, $localelistener->getLocale());
  173.                     $info = $notaryInfo_repo->getInfoFromNotaryAddress($localelistener->getLocale(),$address_info->getAddress());
  174.                     if(!$info){
  175.                         //when there is no info on address, added it her, only first time
  176.                         $info = new NotaryInfo();
  177.                         $info->setIsActive(true);
  178.                         $info->setLocale($localelistener->getLocale());
  179.                         $info->setAddress($address_info->getAddress());
  180.                         $manager->persist($info);
  181.                         $manager->flush();
  182.                     }
  183.                     $session->set('sven_address_slug', $address_info->getAddress()->getSlug());
  184.                 }
  185.                 if(!$address_info){
  186.                     //msk
  187.                     $sven_color_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenColor');
  188.                     $default_color = $sven_color_repo->findDefault();
  189.                     return $this->render('@NotarisFrontend/sven/msk.html.twig',
  190.                         array(
  191.                             'isKantoor'=>false,
  192.                             'showMskSplash'=> true,
  193.                             'notary'=>$notary,
  194.                             'defaultColor'=>$default_color
  195.                         )
  196.                     );
  197.                 }
  198.             }else{
  199.                 $session->remove('sven_address_slug');
  200.                 /** @var $info \Notaris\AdminBundle\Entity\NotaryInfo */
  201.                 $info = $localelistener->getNotaryInfo();
  202.                 $address_info = $svenAddress_repo->getAddressFromNotary($notary, $info->getAddress()->getSlug(), $localelistener->getLocale());
  203.             }
  204.         else:
  205.             return $this->redirect($this->container->getParameter('url_'. $locale));
  206.         endif;
  207.         if(!$info){
  208.             //redirct to default site
  209.             return $this->redirect($this->container->getParameter('url_'. $locale));
  210.         }
  211.        //service
  212.         $svenService = $this->get('notaris.sven.service');
  213.         $svenPage = $svenService->getSvenPage($notary, $info, $address_info);
  214.         /** @var  $svenBannerGalleryRepository \Notaris\AdminBundle\Entity\SvenBannerGallery */
  215.         $svenBannerGalleryRepository = $manager->getRepository('Notaris\AdminBundle\Entity\SvenBannerGallery');
  216.         $backgroundImageGallery = $svenBannerGalleryRepository->findOneBy([
  217.             'name' => 'Start-screen images',
  218.             'locale' => $notary->getLocale(),
  219.         ]);
  220.         //period for notary people
  221.         /** @var  $notabasePeriodRepository  \Notaris\AdminBundle\Entity\NotabasePeriodRepository */
  222.         $notabasePeriodRepository = $manager->getRepository('Notaris\AdminBundle\Entity\NotabasePeriod');
  223.         $periods = $notabasePeriodRepository->createQueryBuilder('p')
  224.             ->select('p')
  225.             ->groupBy('p.personNumber, p.replacedNumber')
  226.             ->where('p.officeNumber = :officeNumber')
  227.             ->andWhere('p.active = 1')
  228.             ->andWhere('p.endDate IS NULL')
  229.             ->setParameter('officeNumber', $notary->getEe())
  230.             ->getQuery()
  231.             ->getResult();
  232.         return $this->render('@NotarisFrontend/sven/homepage.html.twig', [
  233.             'isKantoor' => true,
  234.             'notary' => $notary,
  235.             'address_info' => $address_info,
  236.             'banners' => $svenPage['banners'],
  237.             'groupinfos' => $svenPage['groupinfos'],
  238.             'build' => $svenPage['build'],
  239.             'backgroundImageGallery' => $backgroundImageGallery->getAssets(),
  240.             'periods' => $periods,
  241.             'socialMedia' => $svenPage['socialMedia'],
  242.             'navigation' => $svenPage['navigation']
  243.         ]);
  244.     }
  245.     public function skedifyAction(Request $request, $addressslug = null){
  246.         $office_id = false;
  247.         $notary = false;
  248.         $showSkedify = true;
  249.         $manager = $this->getDoctrine()->getManager();
  250.         $skedifyService = $this->get('skedify_service');
  251.         $address_info = null;
  252.         /** @var $address_info \Notaris\AdminBundle\Entity\SvenAddressInfo */
  253.         $svenAddressInfo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  254.         if($addressslug){
  255.             //via notaris.be with slug
  256.             /** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressRepository */
  257.             $svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddress');
  258.             /** @var $address \Notaris\AdminBundle\Entity\SvenAddress */
  259.             $address = $svenAddress_repo->findOneBySlug($addressslug);
  260.             if($address){
  261.                 $notary = $address->getNotary();
  262.                 $office_id = $address->getEe();
  263.                 if(!$office_id){
  264.                     $office_id = $address->getSlug();
  265.                 }
  266. //                if(!$address->getSkedifyId()){
  267. //                    $address = $skedifyService->getOfficesByExternalId($office_id, $address);
  268. //                }
  269. //                if($address and $address->getSkedifyId()) {
  270. //                    $showSkedify = $skedifyService->getSpecificOffice($address->getSkedifyId());
  271. //                }else{
  272. //                    $showSkedify = false;
  273. //                }
  274. //                $showSkedify = $address->getIsSkedifyActive();
  275.             }
  276.         }else{
  277.             //via sven domain
  278.             $localelistener = $this->get('notaris.locale.listener');
  279.             $notary = $localelistener->getNotary();
  280.             if($notary){
  281.                 $session = $request->getSession();
  282.                 $currentslug = $session->get('sven_address_slug');
  283.                 $addresses = $notary->getAddresses();
  284.                 if(sizeof($addresses) > 1){
  285.                     if($currentslug){
  286.                         /** @var $notaryInfo_repo \Notaris\AdminBundle\Entity\NotaryInfoRepository */
  287.                         $notaryInfo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\NotaryInfo');
  288.                         $address_info = $svenAddressInfo_repo->getAddressFromNotary($notary, $currentslug, $localelistener->getLocale());
  289.                     }
  290.                     foreach ($addresses as $address) {
  291.                         if($address->getSlug() == $currentslug){
  292.                             $office_id = $address->getEe();
  293.                             if(!$address->getEe()){
  294.                                 $office_id = $address->getSlug();
  295.                             }
  296. //                            if(!$address->getSkedifyId()){
  297. //                                $address = $skedifyService->getOfficesByExternalId($office_id, $address);
  298. //                            }
  299. //
  300. //                            if($address and $address->getSkedifyId()) {
  301. //                                $showSkedify = $skedifyService->getSpecificOffice($address->getSkedifyId());
  302. //                            }else{
  303. //                                $showSkedify = false;
  304. //                            }
  305. //                            $showSkedify = $address->getIsSkedifyActive();
  306.                         }
  307.                     }
  308.                 }else{
  309.                     $info = $localelistener->getNotaryInfo();
  310.                     $address = $info->getAddress();
  311.                     $office_id = $address->getEe();
  312.                     /** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressInfoRepository */
  313.                     $svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  314.                     $address_info = $svenAddress_repo->getAddressFromNotary($notary, $info->getAddress()->getSlug(), $localelistener->getLocale());
  315. //                    if(!$address->getSkedifyId()){
  316. ////                        $address = $skedifyService->getOfficesByExternalId($office_id, $address);
  317. ////                    }
  318. ////
  319. ////                    if($address and $address->getSkedifyId()) {
  320. ////                        $showSkedify = $skedifyService->getSpecificOffice($address->getSkedifyId());
  321. ////                    }else{
  322. ////                        $showSkedify = false;
  323. ////                    }
  324. //                    $showSkedify = $address->getIsSkedifyActive();
  325.                 }
  326.             }
  327.         }
  328.         //back link
  329.         $backlink = $request->headers->get('referer');
  330.         $host = parse_url($backlink, PHP_URL_HOST);
  331.         if ($backlink == '') {
  332.             $backlink = '/';
  333.         } elseif($request->getHttpHost() != $host) {
  334.             // Check if referer has a sven domain
  335.             $repo_notary_domain = $manager->getRepository('Notaris\AdminBundle\Entity\NotaryDomain');
  336.             $pslManager = new Manager(new Cache(), new CurlHttpClient());
  337.             try {
  338.                 $rules = $pslManager->getRules();
  339.                 $url = $rules->resolve($host);
  340.                 $domain = $repo_notary_domain->findNotaryByDomain($url->getRegistrableDomain());
  341.                 if(!$domain) {
  342.                     $backlink = $this->generateUrl('notaris_frontend_homepage');
  343.                 }
  344.             } catch(\Exception $exception) {
  345.                 $backlink = $this->generateUrl('notaris_frontend_homepage');
  346.             }
  347.         }
  348.         if(!$addressslug) {
  349.             //only on sven domain
  350.             if (!empty($notary) && empty($address_info)) {
  351.                 $info = $localelistener->getNotaryInfo();
  352.                 /** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressInfoRepository */
  353.                 $svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  354.                 $address_info = $svenAddress_repo->getAddressFromNotary($notary, $info->getAddress()->getSlug(), $localelistener->getLocale());
  355.             }
  356.             if (!empty($notary) && !empty($address_info)) {
  357.                 $info = $localelistener->getNotaryInfo();
  358.                 $svenService = $this->get('notaris.sven.service');
  359.                 $svenPage = $svenService->getSvenPage($notary, $info, $address_info);
  360.                 return $this->render('@NotarisFrontend/sven/skedify.html.twig', [
  361.                     'office_id' => $office_id,
  362.                     'showSkedify' => $showSkedify,
  363.                     'notary' => $notary,
  364.                     'backlink' => $backlink,
  365.                     'address_info' => $address_info,
  366.                     'socialMedia' => $svenPage['socialMedia'],
  367.                     'build' => $svenPage['build'],
  368.                 ]);
  369.             }
  370.         }
  371.         return $this->render('@NotarisFrontend/default/skedify.html.twig', [
  372.             'office_id'=> $office_id, 'showSkedify' => $showSkedify, 'notary' => $notary, 'backlink' => $backlink
  373.         ]);
  374.     }
  375. //@TODO: remove old code
  376. //    public function getAction(Request $request){
  377. //
  378. //        $response = new \stdClass();
  379. //        $response->success = false;
  380. //
  381. //        $submit_name = '';
  382. //
  383. ////        if($request->get('name')):
  384. ////            echo "Hello submit " . $request->get('name'); exit;
  385. //            $submit_name = $request->get('name','');
  386. ////        endif;
  387. //
  388. ////        if($request->get('ajax_name')):
  389. //////            echo "Hello submit " . $request->get('ajax_name'); exit;
  390. ////            $response->success = true;
  391. ////            $response->name = $request->get('ajax_name');
  392. ////            return $this->json($response);
  393. ////        endif;
  394. //
  395. //        return array('submitName'=>$submit_name);
  396. //    }
  397. //    /**
  398. //     * @param $data
  399. //     * @return Response
  400. //     */
  401. //    protected function json($data)
  402. //    {
  403. //        $response = new Response(json_encode($data));
  404. //        $response->headers->set('Content-Type', 'application/json');
  405. //
  406. //        return $response;
  407. //    }
  408.     public function staticFaqAction(Request $request,)
  409.     {
  410.         $filename = __DIR__ . '/../../../../web/not-so-faq-' . "nl" . '.html';
  411.         if (!file_exists($filename)) {
  412.             throw $this->createNotFoundException('Pagina niet gevonden');
  413.         }
  414.         return new \Symfony\Component\HttpFoundation\Response(file_get_contents($filename));
  415.     }
  416.     public function barometerAction(Request $request)
  417.     {
  418.         return $this->render('@NotarisFrontend/default/barometer.html.twig');
  419.     }
  420. }