<?php
namespace Notaris\FrontendBundle\Controller;
use Notaris\AdminBundle\Entity\Attachment;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class TagController extends AbstractController
{
public function indexAction($tagSlug, $page)
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$tag_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Tag');
$tag = $tag_repo->findOneBySlug($tagSlug);
if(!$tag or $tag->getLocale() != $locale){
return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
}
$tagresults = [];
//videos
foreach($tag->getVideos() as $video){
if($video->getIsActive()) {
$result = new \stdClass();
$result->title = $video->getTitle();
$result->description = $video->getDescription();
$result->type = 'video';
$result->content = $video;
$subsiteslug = $this->get('translator')->trans('vid_varia');
if ($video->getPrimarySubsite() and $video->getPrimarySubsite()->getIsActive()):
$subsiteslug = $video->getPrimarySubsite()->getSlug();
elseif ($video->getIsVariaPrimary()):
$subsiteslug = $this->get('translator')->trans('vid_varia');
elseif (sizeof($video->getSubsites()) > 0):
foreach ($video->getSubsites() as $sub) {
if ($sub->getSubsite()->getIsActive()) {
$subsiteslug = $sub->getSubsite()->getSlug();
break;
}
}
endif;
// {#{% set pathurl = path('notaris_frontend_tv_detail_video', {slug: subsiteslug , slugvideo: tagresult.slug}) %}#}
// $urlpath = $this->generateUrl('notaris_frontend_tv_detail', array('slug'=>$subsiteslug));
$urlpath = $this->generateUrl('notaris_frontend_tv_detail_video', array('slug' => $subsiteslug, 'slugvideo' => $video->getSlug()));
$result->urlpath = $urlpath;
$slug = '';
if (sizeof($video->getSubsites()) > 0) {
foreach ($video->getSubsites() as $sub) {
if ($sub->getSubsite()->getIsActive()) {
$slug = $sub->getSubsite()->getSlug();
break;
}
}
$result->slug = $this->generateUrl('notaris_frontend_tv_detail_video', array('slug' => $slug, 'slugvideo' => $video->getSlug()));// $video->getSlug();
$result->publicationDate = $video->getPublicationDate();
$tagresults[] = $result;
}
}
}
foreach($tag->getSections() as $section){
if($section->getIsActive() and $section->getSubsite()->getIsActive()) {
$parent = '';
$parentUp = '';
$result = new \stdClass();
$result->title = $section->getTitle();
if ($result->title == ''):
$result->title = $section->getNavigation();
endif;
$result->description = $section->getDescription();
if ($result->description == '' and sizeof($section->getParagraphs()) > 0):
foreach ($section->getParagraphs() as $par):
if ($par->getDescription() != ''):
$result->description = $par->getDescription();
break;
endif;
endforeach;
endif;
$result->type = 'section';
$result->slug = $section->getSlug();
$result->publicationDate = $section->getPublicationDate();
$result->content = $section;
if ($section->getRedirectUrl()):
$result->urlpath = $section->getRedirectUrl();
else:
$subsiteslug = $section->getSubsite()->getSlug();
$sectionslug = $section->getSlug();
if ($section->getParent()):
$parent = $section->getParent()->getSlug();
if ($section->getParent()->getParent()):
$parentUp = $section->getParent()->getParent()->getSlug();
endif;
endif;
if ($parentUp != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail3', array('slug' => $subsiteslug, 'slugdetail' => $parentUp, 'slugdetail2' => $parent, 'slugdetail3' => $sectionslug));
elseif ($parent != ''):
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail2', array('slug' => $subsiteslug, 'slugdetail' => $parent, 'slugdetail2' => $sectionslug));
else:
$urlpath = $this->generateUrl('notaris_frontend_subsite_detail', array('slug' => $subsiteslug, 'slugdetail' => $sectionslug));
endif;
$result->urlpath = $urlpath;
endif;
$tagresults[] = $result;
}
}
foreach($tag->getNewsitems() as $news){
if($news->getIsActive() and $news->getPublicationDate() <= new \DateTime('now')):
$result = new \stdClass();
$result->title = $news->getTitle();
if($news->getIntroduction()):
$result->description = $news->getIntroduction();
else:
$result->description = $news->getText();
endif;
$result->type = 'news';
$result->slug = $news->getSlug();
$result->publicationDate = $news->getPublicationDate();
$result->content = $news;
$result->urlpath = $this->generateUrl('notaris_frontend_news_detail', array('slug'=>$news->getSlug()));
$tagresults[] = $result;
endif;
}
foreach($tag->getBrochures() as $brochure){
if($brochure->getIsActive()){
$result = new \stdClass();
$result->title = $brochure->getTitle();
$result->description = $brochure->getDescription();
$result->slug = ''; //$brochure->getSlug();
$result->type = 'brochure';
$result->publicationDate = $brochure->getPublicationDate();
$result->content = $brochure;
$subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
if($brochure->getIsGeneralPrimary()):
$subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
elseif($brochure->getPrimarySubsite() and $brochure->getPrimarySubsite()->getIsActive()):
$subsiteslug = $brochure->getPrimarySubsite()->getSlug();
elseif(sizeof($brochure->getSubsites())> 0):
foreach ($brochure->getSubsites() as $sub) {
if ($sub->getSubsite()->getIsActive()) {
$subsiteslug = $sub->getSubsite()->getSlug();
break;
}
}
endif;
$result->urlpath = $this->generateUrl('notaris_frontend_brochure_downloads', array('subsiteSlug'=>$subsiteslug, 'brochureId'=>$brochure->getId()));
$tagresults[] = $result;
}
}
foreach($tag->getGlossaries() as $glossary){
if($glossary->getIsActive()) {
$result = new \stdClass();
$result->title = $glossary->getTerm();
$result->description = $glossary->getDescription();
$result->slug = $glossary->getSlug();
$result->type = 'glossary';
$result->publicationDate = $glossary->getPublicationDate();
$result->content = $glossary;
$result->urlpath = $this->generateUrl('notaris_frontend_glossary', array('selected_letter' => $glossary->getLetter(), 'item' => $glossary->getSlug()));
$tagresults[] = $result;
}
}
/** @var $faqItem \Notaris\AdminBundle\Entity\Faq */
foreach($tag->getFaqItems() as $faqItem){
if($faqItem->getIsActive() and $faqItem->getPublicationDate() <= new \DateTime('now')) {
$result = new \stdClass();
$result->title = $faqItem->getTitle();
$result->description = $faqItem->getAnswer();
$result->slug = $faqItem->getSlug();
$result->type = 'faq';
$result->publicationDate = $faqItem->getPublicationDate();
$result->content = $faqItem;
$subsiteslug = $this->get('translator')->trans('faq_algemeen_slug');
if (sizeof($faqItem->getSubsites()) > 0):
foreach ($faqItem->getSubsites() as $sub) {
if ($sub->getSubsite()->getIsActive()) {
$subsiteslug = $sub->getSubsite()->getSlug();
break;
}
}
endif;
$result->urlpath = $this->generateUrl('notaris_frontend_faq_subsite_detail', array('subsiteSlug' => $subsiteslug, 'faqSlug' => $faqItem->getSlug()));
$tagresults[] = $result;
}
}
$total = count($tagresults);
//$page = 0;
$perpage = 25;
$totalpages = ceil($total / $perpage);
$tagresults = array_splice($tagresults, $page * $perpage, $perpage);
return $this->render('@NotarisFrontend/tag/index.html.twig',
['tagresults' => $tagresults, 'tag' => $tag, 'total' => $total, 'currentpage' => $page, 'totalpages' => $totalpages]
);
}
public function clickAction($tagSlug){
$manager = $this->getDoctrine()->getManager();
$tag_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Tag');
$tag = $tag_repo->findOneBySlug($tagSlug);
$tag->setCountClicked($tag->getCountClicked()+1);
$manager->flush();
$response = new JsonResponse();
$response->setData(array(
'clicksaved' => true
));
return $response;
}
}