src/Notaris/FrontendBundle/Controller/SubsiteController.php line 184

Open in your IDE?
  1. <?php
  2. namespace Notaris\FrontendBundle\Controller;
  3. use Notaris\AdminBundle\Entity\Attachment;
  4. use Notaris\AdminBundle\Entity\Faq;
  5. use Notaris\AdminBundle\Entity\Subsite;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. class SubsiteController extends AbstractController
  14. {
  15.     public function indexAction(Request $request, $slug)
  16.     {
  17.         $localeService = $this->get('notaris.locale.listener');
  18.         $locale = $localeService->getLocale();
  19.         if($locale == 'de'):
  20.             $locale = 'fr';
  21.         endif;
  22.         $manager = $this->getDoctrine()->getManager();
  23.         $smallsidenav = false;
  24.         if($slug == 'other-languages'){
  25.             $smallsidenav = true;
  26.         }
  27.         $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  28.         $subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
  29.         //plaats in de if hieronder de slug van de duplicatie subsite eraan to
  30.         if($subsite and ($subsite->getSlug() == 'opstarten-ondernemen-2019')){
  31.             $subsite->setIsActive(true);
  32.         }
  33.         if(!$subsite or !$subsite->getIsActive()){
  34.             //check if it is a domain annex
  35.             $dynamic_url_repo = $manager->getRepository('Notaris\AdminBundle\Entity\DynamicUrl');
  36.             $dynamic_url = $dynamic_url_repo->findOneBy(
  37.               array(
  38.                   'extension'=>[$slug,'/'.$slug],
  39.                   'locale'=>$locale,
  40.                   'isActive'=>1
  41.               )
  42.             );
  43.             if(!$dynamic_url):
  44.                 throw new NotFoundHttpException('Sorry not existing!');
  45.             endif;
  46.             return $this->redirect($dynamic_url->getDestination(),301);
  47.         }
  48.         //center modules
  49.         $modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SubsiteModule');
  50.         $center_modules = $modules_repo->findAllCenterFromSubsite($subsite, $locale);
  51.         $right_modules = $modules_repo->findAllRightFromSubsite($subsite, $locale);
  52.         if(!$center_modules){
  53.             return $this->detailAction($request, $slug,'','','');
  54.         }
  55.         //glossary
  56.         $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
  57.         $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
  58.         //faq
  59.         $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
  60.         $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
  61.         //news
  62.         $news_repo = $manager->getRepository('Notaris\AdminBundle\Entity\News');
  63.         $news = $news_repo->getNewsSubsitePublic($locale, 0, 1, 'desc', $subsite);
  64.         $news = empty($news[0]) ? null : $news[0];
  65.         //video
  66.         $video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  67.         $videos = $video_repo->getSubsiteVideos($subsite, 0, 1);
  68.         $video = empty($videos[0]) ? null : $videos[0];
  69.         //random faq
  70.         $randomFaq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId(), true);
  71.         $randomFaq = $randomFaq ?: null;
  72.         //brochure
  73.         $brochure_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Brochure');
  74.         $brochures = $brochure_repo->getListBrochuresSubsitePublic($locale, $subsite->getId());
  75.         $brochure = empty($brochures[0]) ? null : $brochures[0];
  76.         return $this->render('@NotarisFrontend/subsite/index.html.twig', [
  77.             'subsite' => $subsite,
  78.             'currentslug' => $slug,
  79.             'centermodules' => $center_modules,
  80.             'rightmodules' => $right_modules,
  81.             'smallsidenav' => $smallsidenav,
  82.             'glossary' => $glossary,
  83.             'faq' => $faq,
  84.             'randomFaq' => $randomFaq,
  85.             'news' => $news,
  86.             'video' => $video,
  87.             'brochure' => $brochure,
  88.         ]);
  89.     }
  90.     public function detailAction(Request $request, $slug, $slugdetail, $slugdetail2, $slugdetail3)
  91.     {
  92.         $localeService = $this->get('notaris.locale.listener');
  93.         $locale = $localeService->getLocale();
  94.         if($locale == 'de'):
  95.             $locale = 'fr';
  96.         endif;
  97.         $smallsidenav = false;
  98.         if($slug == 'other-languages'){
  99.             $smallsidenav = true;
  100.         }
  101.         $localelistener = $this->get('notaris.locale.listener');
  102.         $notary = $localelistener->getNotary();
  103.         if ($notary !== false && (
  104.             ($slug === 'contact' && $slugdetail === 'notaris-be-contact') ||
  105.             ($slug === 'nouveautes' && $slugdetail === 'contact')
  106.         )) {
  107.             return $this->redirect('/', 301);
  108.         }
  109.         $manager = $this->getDoctrine()->getManager();
  110.         $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  111.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  112.         /** @var $subsite_repo \Notaris\AdminBundle\Entity\SubsiteRepository */
  113.         $subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
  114.         $titleslug = $slug;
  115.         if($slugdetail3 != ''){
  116.             $selectedslug = $slugdetail3;
  117.             $titleslug = $slugdetail;
  118.         }else if($slugdetail2 != ''){
  119.             $selectedslug = $slugdetail2;
  120.             $titleslug = $slugdetail;
  121.         }else if($slugdetail != ''){
  122.             $selectedslug = $slugdetail;
  123.             $titleslug = $slugdetail;
  124.         }else{
  125.             $selectedslug = $slug;
  126.         }
  127.         if(($slugdetail == 'notaris-tv' OR $slugdetail == 'notaire-tv')){
  128.             if($slugdetail2 != ''){
  129.                 return $this->redirect($this->generateUrl('notaris_frontend_tv_detail', ['slug' => $slugdetail2]), '302');
  130.             }
  131.             return $this->redirect($this->generateUrl('notaris_frontend_tv'), '302');
  132.         }
  133.         if($subsite){
  134.             if($subsite->getSlug() == 'vacatures'){
  135.                 return $this->redirect($this->generateUrl('notaris_frontend_job'), '302');
  136.             }
  137.             if($subsite->getSlug() == 'calcul_de_frais'){
  138.                 return $this->redirect($this->generateUrl('notaris_frontend_calculate'), '302');
  139.             }
  140.             if($subsite->getSlug() == 'adresboek' or $subsite->getSlug() == 'annuaire'){
  141.                 return $this->redirect($this->generateUrl('notaris_frontend_homepage'), '301');
  142.             }
  143.         }
  144.         $titlesection = $section_repo->getSectionBySlug($titleslug);
  145.         if ($notary !== false || ($selectedslug !== 'gdpr-gedragscode' && $selectedslug !== 'code-de-conduite-rgpd')) {
  146.             $section = $section_repo->getSectionBySlug($selectedslug);
  147.         } else {
  148.             $section = false;
  149.         }
  150.         if($section and $section->getRedirectUrl() != ''){
  151.             return $this->redirect($section->getRedirectUrl(), '301');
  152.         }
  153.         if(!$section or !$subsite or $section->getSubsite() != $subsite){
  154.             //check if it is a domain annex
  155.             $dynamic_url_repo = $manager->getRepository('Notaris\AdminBundle\Entity\DynamicUrl');
  156.             $dynamic_url = $dynamic_url_repo->findOneBy(
  157.                 array(
  158.                     'extension'=>$_SERVER['REQUEST_URI'],
  159.                     'locale'=>$locale,
  160.                     'isActive'=>1
  161.                 )
  162.             );
  163.             if($dynamic_url):
  164.                 return $this->redirect($dynamic_url->getDestination(), 301);
  165.             endif;
  166.             if($subsite){
  167.                 $section = $section_repo->getFirstSectionFromSubsite($subsite);
  168.                 if($section) {
  169.                     return $this->redirect($this->generateUrl('notaris_frontend_subsite_detail', array('slug' => $subsite->getSlug(), 'slugdetail' => $section->getSlug())), 301);
  170.                 }
  171.             }
  172. //            return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
  173.         }
  174.         if($section and $section->getSubsite()->getSlug() != 'other-languages'){
  175.             $pathslug =  '/'. $section->getSubsite()->getSlug() . '/'. $section->getSlug();
  176.             if($section and $section->getParent()){
  177.                 $pathslug =  '/'. $section->getSubsite()->getSlug() . '/'. $section->getParent()->getSlug() . '/'. $section->getSlug();
  178.                 if($section->getParent()->getParent()){
  179.                     $pathslug =  '/'. $section->getSubsite()->getSlug() . '/'. $section->getParent()->getParent()->getSlug() . '/'. $section->getParent()->getSlug() . '/'. $section->getSlug();
  180.                 }
  181.             }
  182.             $checkUtm = $request->query->has('utm');
  183.             $checkGclid = $request->query->has('gclid');
  184.             if($_SERVER['REQUEST_URI'] != $pathslug and !$checkGclid and !$checkUtm){
  185.                 return $this->redirect($pathslug,301);
  186.             }
  187.         }
  188.         if(!$subsite){
  189.             return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
  190.         }
  191.         $paragraph_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionParagraph');
  192.         $paragraphs = $paragraph_repo->getParagraphsBySection($section);
  193.         if($paragraphs) {
  194.             foreach ($paragraphs as $paragraph) {
  195.                 if ($paragraph->getAsset() != null) {
  196.                     if (count($paragraph->getAsset()->getAssetVideoPaths()) > 0) {
  197.                         //check meta
  198.                         $videopath = $paragraph->getAsset()->getAssetVideoPaths()[0];
  199.                         $video = $paragraph_repo->getVideoByVideoPath($videopath);
  200.                         if ($video) {
  201.                             $videopath->getVideoPath()->setVideo($video);
  202.                         }
  203.                     }
  204.                 }
  205.             }
  206.         }
  207.         $modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
  208.         $right_modules = $modules_repo->findAllFromSection($section);
  209.         if($slug == 'other-languages'){
  210.             $slugdetail3 = $slugdetail2;
  211.             $slugdetail2 = $slugdetail;
  212.             $slugdetail = $slug;
  213.             if($locale == 'fr') {
  214.                 $slugdetail = 'other-languages-1';
  215.             }
  216.         }
  217.         //archive cookies
  218.         $isArchived = false;
  219.         if(isset($_COOKIE['leeslater'])):
  220.             $leeslater = $_COOKIE['leeslater'];
  221.             $leeslater_arr = explode(",",$leeslater);
  222.             for ($x=0; $x<count($leeslater_arr); $x++){
  223.                 if($leeslater_arr[$x] == $section->getId()){
  224.                     $isArchived = true;
  225.                 }
  226.             }
  227.         endif;
  228.         if ($notary !== false ) {
  229.             $session = $request->getSession();
  230.             $currentslug = $session->get('sven_address_slug');
  231.             $address_info = null;
  232.             /** @var $info \Notaris\AdminBundle\Entity\NotaryInfo */
  233.             $info = $localelistener->getNotaryInfo();
  234.             if(sizeof($notary->getAddresses()) > 1 && $currentslug){
  235.                 /** @var $address_info \Notaris\AdminBundle\Entity\SvenAddressInfo */
  236.                 $svenAddressInfo_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  237.                 $address_info = $svenAddressInfo_repo->getAddressFromNotary($notary, $currentslug, $localelistener->getLocale());
  238.             }
  239.             if (empty($address_info)) {
  240.                 /** @var $svenAddress_repo \Notaris\AdminBundle\Entity\SvenAddressInfoRepository */
  241.                 $svenAddress_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SvenAddressInfo');
  242.                 $address_info = $svenAddress_repo->getAddressFromNotary($notary, $info->getAddress()->getSlug(), $localelistener->getLocale());
  243.             }
  244.             $svenService = $this->get('notaris.sven.service');
  245.             $svenPage = $svenService->getSvenPage($notary, $info, $address_info);
  246.             return $this->render('@NotarisFrontend/sven/subsite.html.twig', [
  247.                 'subsite' => $subsite,
  248.                 'titlesection' => $titlesection,
  249.                 'section' => $section,
  250.                 'paragraphs' => $paragraphs,
  251.                 'rightmodules' => $right_modules,
  252.                 'currentslug' => $slugdetail,
  253.                 'currentslug2' => $slugdetail2,
  254.                 'currentslug3' => $slugdetail3,
  255.                 'smallsidenav' => $smallsidenav,
  256.                 'isArchived' => $isArchived,
  257.                 'address_info' => $address_info,
  258.                 'notary' => $notary,
  259.                 'socialMedia' => $svenPage['socialMedia'],
  260.                 'build' => $svenPage['build'],
  261.             ]);
  262.         }
  263.         return  $this->render('@NotarisFrontend/subsite/detail.html.twig', array('subsite' => $subsite, 'titlesection' => $titlesection, 'section' => $section, 'paragraphs' => $paragraphs, 'rightmodules' => $right_modules, 'currentslug' => $slugdetail, 'currentslug2' => $slugdetail2, 'currentslug3' => $slugdetail3, 'smallsidenav' => $smallsidenav, 'isArchived'=>$isArchived));
  264.     }
  265.     public function archiveAction()
  266.     {
  267.         $localeService = $this->get('notaris.locale.listener');
  268.         $locale = $localeService->getLocale();
  269.         if($locale == 'de'):
  270.             $locale = 'fr';
  271.         endif;
  272.         $manager = $this->getDoctrine()->getManager();
  273.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  274.         $results = array();
  275.         if(isset($_COOKIE['leeslater'])):
  276.             $leeslater = $_COOKIE['leeslater'];
  277.             $leeslater_arr = explode(",",$leeslater);//.','.$leeslater.','.$leeslater.','.$leeslater);
  278. //            echo "LEESLATER: " . $leeslater;
  279.             $index = 0;
  280.             //$begin = true;
  281.             foreach($leeslater_arr as $pageID):
  282.                 $parentUp = '';
  283.                 $parent = '';
  284.                 $index++;
  285.                 if($index > 10):
  286.                     break;
  287.                 endif;
  288.                 $section = $section_repo->find($pageID);
  289.                 if($section):
  290.                     $result = new \stdClass();
  291.                     $result->content = $section;
  292.                     //get url path
  293.                     $subsiteslug = $section->getSubsite()->getSlug();
  294.                     $sectionslug = $section->getSlug();
  295.                     if($section->getParent()):
  296.                         $parent = $section->getParent()->getSlug();
  297.                         if($section->getParent()->getParent()):
  298.                             $parentUp = $section->getParent()->getParent()->getSlug();
  299.                         endif;
  300.                     endif;
  301.                     if($parentUp != ''):
  302.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug'=> $subsiteslug, 'slugdetail'=>$parentUp, 'slugdetail2'=>$parent, 'slugdetail3'=> $sectionslug));
  303.                         $title = $section->getSubsite()->getName() . " > " . $section->getParent()->getParent()->getTitle() . ' > ' . $section->getParent()->getTitle();
  304.                     elseif($parent != ''):
  305.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug'=> $subsiteslug, 'slugdetail'=>$parent, 'slugdetail2'=> $sectionslug));
  306.                         $title = $section->getSubsite()->getName() . ' > ' . $section->getParent()->getTitle();
  307.                     else:
  308.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug'=> $subsiteslug, 'slugdetail'=> $sectionslug));
  309.                         $title = $section->getSubsite()->getName();
  310.                     endif;
  311.                     $result->urlpath = $urlpath;
  312.                     $result->title = $title;
  313.                     $results[] = $result;
  314.                 endif;
  315.             endforeach;
  316.         endif;
  317.         return $this->render('@NotarisFrontend/subsite/archive.html.twig', ['results' => $results]);
  318.     }
  319.     public function pdfAction()
  320.     {
  321. //        $loader = new ClassLoader();
  322. //        $loader->addPrefix('Zend', __DIR__.'/vendor/zf/library');
  323. //        $loader->register();
  324. //        $web = $this->get('kernel')->getRootDir() . '/../web/';
  325. //        require_once ($web."Zend/Pdf.php");
  326.         $localeService = $this->get('notaris.locale.listener');
  327.         $locale = $localeService->getLocale();
  328.         if($locale == 'de'):
  329.             $locale = 'fr';
  330.         endif;
  331.         $manager = $this->getDoctrine()->getManager();
  332.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  333.         $section_paragraph_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionParagraph');
  334.         $results = array();
  335.         if(isset($_COOKIE['leeslater'])):
  336.             $pdf = new \Zend_Pdf();
  337.             $pages = array();
  338.             //fonts
  339.             $font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA, 'UTF-8');
  340.             $font_cursief = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_ITALIC, 'UTF-8');
  341.             $font_cursief_bold = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC, 'UTF-8');
  342.             $font_bold = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'UTF-8');
  343.             $page = $this->makeNewPage();
  344.             $pages[] = $page;
  345.             //start positie
  346.             $x = 40;
  347.             $y = 800;
  348.             $header = $this->get('translator')->trans('sd_pdf_header');
  349.             $filename = $this->get('translator')->trans('sd_pdf_filename');
  350.             $pages[sizeof($pages)-1]->setFont($font_bold, 16)
  351.                 ->setFillColor(\Zend_Pdf_Color_Html::color('#3a3939'))
  352.                 ->drawText($header, $x, $y, 'UTF-8');
  353.             $leeslater = $_COOKIE['leeslater'];
  354.             $leeslater_arr = explode(",",$leeslater);//.','.$leeslater.','.$leeslater.','.$leeslater);
  355. //            echo "LEESLATER: " . $leeslater;
  356.             $index = 0;
  357.             //$begin = true;
  358.             foreach($leeslater_arr as $pageID):
  359.                 $parentUp = '';
  360.                 $parent = '';
  361.                 $index++;
  362.                 if($index > 10):
  363.                     break;
  364.                 endif;
  365.                 $section = $section_repo->find($pageID);
  366.                 if($section):
  367.                     $result = new \stdClass();
  368.                     $result->content = $section;
  369.                     //get url path
  370.                     $subsiteslug = $section->getSubsite()->getSlug();
  371.                     $sectionslug = $section->getSlug();
  372.                     if($section->getParent()):
  373.                         $parent = $section->getParent()->getSlug();
  374.                         if($section->getParent()->getParent()):
  375.                             $parentUp = $section->getParent()->getParent()->getSlug();
  376.                         endif;
  377.                     endif;
  378.                     if($parentUp != ''):
  379.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug'=> $subsiteslug, 'slugdetail'=>$parentUp, 'slugdetail2'=>$parent, 'slugdetail3'=> $sectionslug));
  380.                         $title = $section->getSubsite()->getName() . " > " . $section->getParent()->getParent()->getTitle() . ' > ' . $section->getParent()->getTitle();
  381.                     elseif($parent != ''):
  382.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug'=> $subsiteslug, 'slugdetail'=>$parent, 'slugdetail2'=> $sectionslug));
  383.                         $title = $section->getSubsite()->getName() . ' > ' . $section->getParent()->getTitle();
  384.                     else:
  385.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug'=> $subsiteslug, 'slugdetail'=> $sectionslug));
  386.                         $title = $section->getSubsite()->getName();
  387.                     endif;
  388.                     $result->urlpath = $urlpath;
  389.                     $result->title = $title;
  390.                     $result->paragraphs = $section_paragraph_repo->getParagraphsBySection($section);
  391.                     $results[] = $result;
  392.                 endif;
  393.             endforeach;
  394.             foreach($results as $result):
  395.                 $y -=35;
  396.                 // MENU PATH
  397.                 $pages[sizeof($pages)-1]->setFont($font, 9)
  398.                     ->setFillColor(\Zend_Pdf_Color_Html::color('#3a3939'));
  399.                 $arr = $this->shrinkLongText($result->title, 90, $x, $y, $pages, 13, $font. 9,'#3a3939', $font, 9, '#3a3939');
  400.                 $y = $arr[0];
  401.                 $pages = $arr[1];
  402.                 //TITEL
  403.                 if($result->content->getTitle() != ""){
  404.                     $y -=10;
  405.                     $pages[sizeof($pages)-1]->setFont($font_bold, 18)
  406.                         ->setFillColor(\Zend_Pdf_Color_Html::color('#80187a'));
  407.                     $arr = $this->shrinkLongText($result->content->getTitle(),55,$x,$y,$pages, 20, $font_bold,18,'#5295C1');
  408.                     $y = $arr[0];
  409.                     $pages = $arr[1];
  410.                 }else{
  411.                     $y -=10;
  412.                     $pages[sizeof($pages)-1]->setFont($font_bold, 18)
  413.                         ->setFillColor(\Zend_Pdf_Color_Html::color('#80187a'));
  414.                     $arr = $this->shrinkLongText($result->content->getNavigation(),55,$x,$y,$pages, 20, $font_bold, 18, '#5295C1');
  415.                     $y = $arr[0];
  416.                     $pages = $arr[1];
  417.                 }
  418.                 //INTROTEKST
  419.                 if($result->content->getDescription() != ""){
  420.                     $intro_tekst = $this->metaTagFormat($result->content->getDescription());
  421.                     //$y -= 25;
  422.                     $pages[sizeof($pages)-1]->setFont($font, 12)
  423.                         ->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
  424.                     $arr = $this->shrinkLongText(html_entity_decode($intro_tekst, ENT_QUOTES, 'UTF-8'),85,$x,$y,$pages, 14, $font, 12, '#555555');
  425.                     $y = $arr[0];
  426.                     $pages = $arr[1];
  427.                 }
  428.                 //CHECK PAGE SIZE FOR NEW PAGE
  429.                 if($y <= 100){
  430.                     $y = 800;
  431.                     $page = $this->makeNewPage();
  432.                     $pages[] = $page;
  433.                 }
  434.                 //paragraphs
  435.                 if($result->paragraphs):
  436.                     foreach($result->paragraphs as $paragraph):
  437.                         //CHECK PAGE SIZE FOR NEW PAGE
  438.                         if($y <= 100){
  439.                             $y = 800;
  440.                             $page = $this->makeNewPage();
  441.                             $pages[] = $page;
  442.                         }
  443.                         if($paragraph->getTitle()){
  444.                             $y -= 20;
  445.                             $pages[sizeof($pages)-1]->setFont($font_bold, 13)
  446.                                 ->setFillColor(\Zend_Pdf_Color_Html::color('#555555'))
  447.                                 ->drawText($paragraph->getTitle(),$x,$y, 'UTF-8');
  448.                         }
  449.                         //CHECK PAGE SIZE FOR NEW PAGE
  450.                         if($y <= 100){
  451.                             $y = 800;
  452.                             $page = $this->makeNewPage();
  453.                             $pages[] = $page;
  454.                         }
  455.                         if($paragraph->getSubtitle()){
  456.                             $y -= 15;
  457.                             $pages[sizeof($pages)-1]->setFont($font_bold, 12)
  458.                                 ->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
  459.                             $arr = $this->shrinkLongText(utf8_encode($paragraph->getSubtitle()),100,$x,$y,$pages, 10, $font_bold, 12, '#555555');
  460.                             $y = $arr[0];
  461.                             $pages = $arr[1];
  462.                         }
  463.                         //CHECK PAGE SIZE FOR NEW PAGE
  464.                         if($y <= 100){
  465.                             $y = 800;
  466.                             $page = $this->makeNewPage();
  467.                             $pages[] = $page;
  468.                         }
  469.                         if($paragraph->getDescription()){
  470.                             $tekst = $this->metaTagFormat($paragraph->getDescription());
  471.                             $y -= 20;
  472.                             $pages[sizeof($pages)-1]->setFont($font, 12)
  473.                                 ->setFillColor(\Zend_Pdf_Color_Html::color('#555555'));
  474.                             $arr = $this->shrinkLongText(html_entity_decode($tekst, ENT_QUOTES, 'UTF-8'),85,$x,$y,$pages, 14, $font, 12, '#555555');
  475.                             $y = $arr[0];
  476.                             $pages = $arr[1];
  477.                         }
  478.                     endforeach;
  479.                 endif;
  480.             endforeach;
  481.             $pdf->pages = $pages;
  482.             /*OPSLAAN VAN PDF AAN CLIENT ZIJDE*/
  483.             $pdfData = $pdf->render();
  484.             header("Content-Disposition: inline; filename=".$filename);
  485.             header("Content-type: application/x-pdf");
  486.             echo $pdfData;
  487.             exit;
  488.         endif;
  489. //http://www.craftitonline.com/2011/06/pdf-generation-with-symfony2-part-ii-zend-option/
  490.         return $this->render('@NotarisFrontend/subsite/pdf.html.twig', ['results' => $results]);
  491.     }
  492.     private function makeNewPage(){
  493.         $page_2 = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4);
  494.         /*    ->setFillColor(Zend_Pdf_Color_Html::color('#5da0c6'))
  495.             ->drawText('[ '.$address.' ]', 15, 830)
  496.             ->setFillColor(Zend_Pdf_Color_Html::color('#000000'))
  497.             ->drawText(utf8_encode($building->_project_name), 15, 820)*/;
  498.         return $page_2;
  499.     }
  500.     private function shrinkLongText($text, $characters, $x, $y, $pages, $spatie, $font, $size, $color){
  501.         $newtext = wordwrap($text, $characters, "%%");
  502.         $omschrijving = array();
  503.         $omschrijving[] = explode("%%", $newtext);
  504.         foreach($omschrijving as $newtext):
  505.             foreach($newtext as $text):
  506.                 //CHECK PAGE SIZE FOR NEW PAGE
  507.                 if($y <= 100){
  508.                     $y = 800;
  509.                     $page  = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4);
  510.                     $page->setFont($font, $size)
  511.                         ->setFillColor(\Zend_Pdf_Color_Html::color($color));
  512.                     $pages[] = $page;
  513.                 }
  514.                 //echo "* " .utf8_decode($text) . "<br />";
  515.                 $pages[sizeof($pages)-1]->drawText(trim($text), $x, $y, 'UTF-8');
  516.                 $y = $y - $spatie;
  517.             endforeach;
  518.         endforeach;
  519.         return array($y,$pages);;  //ARRAY Y EN PAGES MEEGEVEN
  520.     }
  521.     private function metaTagFormat($html){
  522.         $html = str_replace('</p>', '%% %%', $html);
  523.         $html = str_replace('</ul>', '%% %%', $html);
  524.         $html = str_replace('</div><div>', '%%', $html);
  525.         $html = str_replace('<br />', '%%', $html);
  526.         $html = str_replace('<li>', '%% %% &nbsp;&bull;&nbsp; ', $html);
  527.         $html = str_replace('<div>', '&nbsp;', $html);
  528.         $html = strip_tags($html);
  529.         $html = str_replace(array('"',"&ldquo;","&rdquo;"), '&quot;', $html);
  530.         $html = str_replace("'", '&#39;', $html);
  531.         $html = str_replace('%% %% %%', '%% %%', $html);
  532.         $pos = strrpos(substr($html,-5), '%% %%');
  533.         if($pos === false){
  534.         }else{
  535.             $html = substr($html,0,-5);
  536.         }
  537.         $startzin = substr($html,0,11);
  538.         $pos = strrpos($startzin, '%% %%');
  539.         if($pos === false){
  540.         }else{
  541.             $html = substr($html,11);
  542.         }
  543.         //    echo "<br /><br /> ********* <br />".$html."<br />******<br /><br />";
  544.         return $html;
  545.     }
  546. }