src/Notaris/FrontendBundle/Controller/TagController.php line 25

Open in your IDE?
  1. <?php
  2. namespace Notaris\FrontendBundle\Controller;
  3. use Notaris\AdminBundle\Entity\Attachment;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  9. class TagController extends AbstractController
  10. {
  11.     public function indexAction($tagSlug, $page)
  12.     {
  13.         $localeService = $this->get('notaris.locale.listener');
  14.         $locale = $localeService->getLocale();
  15.         if($locale == 'de'):
  16.             $locale = 'fr';
  17.         endif;
  18.         $manager = $this->getDoctrine()->getManager();
  19.         $tag_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Tag');
  20.         $tag = $tag_repo->findOneBySlug($tagSlug);
  21.         if(!$tag or $tag->getLocale() != $locale){
  22.             return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
  23.         }
  24.         $tagresults = [];
  25.         //videos
  26.         foreach($tag->getVideos() as $video){
  27.             if($video->getIsActive()) {
  28.                 $result = new \stdClass();
  29.                 $result->title = $video->getTitle();
  30.                 $result->description = $video->getDescription();
  31.                 $result->type = 'video';
  32.                 $result->content = $video;
  33.                 $subsiteslug = $this->get('translator')->trans('vid_varia');
  34.                 if ($video->getPrimarySubsite() and $video->getPrimarySubsite()->getIsActive()):
  35.                     $subsiteslug = $video->getPrimarySubsite()->getSlug();
  36.                 elseif ($video->getIsVariaPrimary()):
  37.                     $subsiteslug = $this->get('translator')->trans('vid_varia');
  38.                 elseif (sizeof($video->getSubsites()) > 0):
  39.                     foreach ($video->getSubsites() as $sub) {
  40.                         if ($sub->getSubsite()->getIsActive()) {
  41.                             $subsiteslug = $sub->getSubsite()->getSlug();
  42.                             break;
  43.                         }
  44.                     }
  45.                 endif;
  46.                 //            {#{% set pathurl = path('notaris_frontend_tv_detail_video', {slug: subsiteslug , slugvideo: tagresult.slug}) %}#}
  47.                 //   $urlpath = $this->generateUrl('notaris_frontend_tv_detail', array('slug'=>$subsiteslug));
  48.                 $urlpath = $this->generateUrl('notaris_frontend_tv_detail_video', array('slug' => $subsiteslug, 'slugvideo' => $video->getSlug()));
  49.                 $result->urlpath = $urlpath;
  50.                 $slug = '';
  51.                 if (sizeof($video->getSubsites()) > 0) {
  52.                     foreach ($video->getSubsites() as $sub) {
  53.                         if ($sub->getSubsite()->getIsActive()) {
  54.                             $slug = $sub->getSubsite()->getSlug();
  55.                             break;
  56.                         }
  57.                     }
  58.                     $result->slug = $this->generateUrl('notaris_frontend_tv_detail_video', array('slug' => $slug, 'slugvideo' => $video->getSlug()));//  $video->getSlug();
  59.                     $result->publicationDate = $video->getPublicationDate();
  60.                     $tagresults[] = $result;
  61.                 }
  62.             }
  63.         }
  64.         foreach($tag->getSections() as $section){
  65.             if($section->getIsActive() and $section->getSubsite()->getIsActive()) {
  66.                 $parent = '';
  67.                 $parentUp = '';
  68.                 $result = new \stdClass();
  69.                 $result->title = $section->getTitle();
  70.                 if ($result->title == ''):
  71.                     $result->title = $section->getNavigation();
  72.                 endif;
  73.                 $result->description = $section->getDescription();
  74.                 if ($result->description == '' and sizeof($section->getParagraphs()) > 0):
  75.                     foreach ($section->getParagraphs() as $par):
  76.                         if ($par->getDescription() != ''):
  77.                             $result->description = $par->getDescription();
  78.                             break;
  79.                         endif;
  80.                     endforeach;
  81.                 endif;
  82.                 $result->type = 'section';
  83.                 $result->slug = $section->getSlug();
  84.                 $result->publicationDate = $section->getPublicationDate();
  85.                 $result->content = $section;
  86.                 if ($section->getRedirectUrl()):
  87.                     $result->urlpath = $section->getRedirectUrl();
  88.                 else:
  89.                     $subsiteslug = $section->getSubsite()->getSlug();
  90.                     $sectionslug = $section->getSlug();
  91.                     if ($section->getParent()):
  92.                         $parent = $section->getParent()->getSlug();
  93.                         if ($section->getParent()->getParent()):
  94.                             $parentUp = $section->getParent()->getParent()->getSlug();
  95.                         endif;
  96.                     endif;
  97.                     if ($parentUp != ''):
  98.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug' => $subsiteslug, 'slugdetail' => $parentUp, 'slugdetail2' => $parent, 'slugdetail3' => $sectionslug));
  99.                     elseif ($parent != ''):
  100.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug' => $subsiteslug, 'slugdetail' => $parent, 'slugdetail2' => $sectionslug));
  101.                     else:
  102.                         $urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug' => $subsiteslug, 'slugdetail' => $sectionslug));
  103.                     endif;
  104.                     $result->urlpath = $urlpath;
  105.                 endif;
  106.                 $tagresults[] = $result;
  107.             }
  108.         }
  109.         foreach($tag->getNewsitems() as $news){
  110.             if($news->getIsActive() and $news->getPublicationDate() <= new \DateTime('now')):
  111.                 $result = new \stdClass();
  112.                 $result->title = $news->getTitle();
  113.                 if($news->getIntroduction()):
  114.                     $result->description = $news->getIntroduction();
  115.                 else:
  116.                     $result->description = $news->getText();
  117.                 endif;
  118.                 $result->type = 'news';
  119.                 $result->slug = $news->getSlug();
  120.                 $result->publicationDate = $news->getPublicationDate();
  121.                 $result->content = $news;
  122.                 $result->urlpath = $this->generateUrl('notaris_frontend_news_detail', array('slug'=>$news->getSlug()));
  123.                 $tagresults[] = $result;
  124.             endif;
  125.         }
  126.         foreach($tag->getBrochures() as $brochure){
  127.             if($brochure->getIsActive()){
  128.                 $result = new \stdClass();
  129.                 $result->title = $brochure->getTitle();
  130.                 $result->description = $brochure->getDescription();
  131.                 $result->slug = ''; //$brochure->getSlug();
  132.                 $result->type = 'brochure';
  133.                 $result->publicationDate = $brochure->getPublicationDate();
  134.                 $result->content = $brochure;
  135.                 $subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
  136.                 if($brochure->getIsGeneralPrimary()):
  137.                     $subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
  138.                 elseif($brochure->getPrimarySubsite() and $brochure->getPrimarySubsite()->getIsActive()):
  139.                     $subsiteslug = $brochure->getPrimarySubsite()->getSlug();
  140.                 elseif(sizeof($brochure->getSubsites())> 0):
  141.                     foreach ($brochure->getSubsites() as $sub) {
  142.                         if ($sub->getSubsite()->getIsActive()) {
  143.                             $subsiteslug = $sub->getSubsite()->getSlug();
  144.                             break;
  145.                         }
  146.                     }
  147.                 endif;
  148.                 $result->urlpath = $this->generateUrl('notaris_frontend_brochure_downloads', array('subsiteSlug'=>$subsiteslug, 'brochureId'=>$brochure->getId()));
  149.                 $tagresults[] = $result;
  150.             }
  151.         }
  152.         foreach($tag->getGlossaries() as $glossary){
  153.             if($glossary->getIsActive()) {
  154.                 $result = new \stdClass();
  155.                 $result->title = $glossary->getTerm();
  156.                 $result->description = $glossary->getDescription();
  157.                 $result->slug = $glossary->getSlug();
  158.                 $result->type = 'glossary';
  159.                 $result->publicationDate = $glossary->getPublicationDate();
  160.                 $result->content = $glossary;
  161.                 $result->urlpath = $this->generateUrl('notaris_frontend_glossary', array('selected_letter' => $glossary->getLetter(), 'item' => $glossary->getSlug()));
  162.                 $tagresults[] = $result;
  163.             }
  164.         }
  165.         /** @var  $faqItem \Notaris\AdminBundle\Entity\Faq */
  166.         foreach($tag->getFaqItems() as $faqItem){
  167.             if($faqItem->getIsActive() and $faqItem->getPublicationDate() <= new \DateTime('now')) {
  168.                 $result = new \stdClass();
  169.                 $result->title = $faqItem->getTitle();
  170.                 $result->description = $faqItem->getAnswer();
  171.                 $result->slug = $faqItem->getSlug();
  172.                 $result->type = 'faq';
  173.                 $result->publicationDate = $faqItem->getPublicationDate();
  174.                 $result->content = $faqItem;
  175.                 $subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
  176.                 if (sizeof($faqItem->getSubsites()) > 0):
  177.                     foreach ($faqItem->getSubsites() as $sub) {
  178.                         if ($sub->getSubsite()->getIsActive()) {
  179.                             $subsiteslug = $sub->getSubsite()->getSlug();
  180.                             break;
  181.                         }
  182.                     }
  183.                 endif;
  184.                 $result->urlpath = $this->generateUrl('notaris_frontend_faq_subsite_detail', array('subsiteSlug' => $subsiteslug, 'faqSlug' => $faqItem->getSlug()));
  185.                 $tagresults[] = $result;
  186.             }
  187.         }
  188.         $total = count($tagresults);
  189.         //$page = 0;
  190.         $perpage = 25;
  191.         $totalpages = ceil($total / $perpage);
  192.         $tagresults = array_splice($tagresults, $page * $perpage, $perpage);
  193.         return $this->render('@NotarisFrontend/tag/index.html.twig',
  194.             ['tagresults' => $tagresults, 'tag' => $tag, 'total' => $total, 'currentpage' => $page, 'totalpages' => $totalpages]
  195.         );
  196.     }
  197.     public function clickAction($tagSlug){
  198.         $manager = $this->getDoctrine()->getManager();
  199.         $tag_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Tag');
  200.         $tag = $tag_repo->findOneBySlug($tagSlug);
  201.         $tag->setCountClicked($tag->getCountClicked()+1);
  202.         $manager->flush();
  203.         $response = new JsonResponse();
  204.         $response->setData(array(
  205.             'clicksaved' => true
  206.         ));
  207.         return $response;
  208.     }
  209. }