<?php
namespace Notaris\FrontendBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class TvController extends AbstractController
{
public function indexAction()
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$slug = 'nieuws-pers';
$tvslug = 'notaris-tv';
if($locale == 'fr'){
$slug = 'nouveautes';
$tvslug = 'notaire-tv';
}
$subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
$subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
$section = $section_repo->findOneBySlug($tvslug);
$video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
/** @var $video_repo \Notaris\AdminBundle\Entity\VideoRepository */
$recent = $video_repo->getRecentVideos($locale, 10);
//center modules
$modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
$right_modules = $modules_repo->findAllFromSection($section, $locale);
//glossary
// $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
// $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
//faq
// $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
// $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
$currentslug = $section->getSlug();
return $this->render('@NotarisFrontend/tv/index.html.twig',
['subsite' => $subsite, 'currentslug' => $currentslug, 'section' => $section, 'recent' => $recent, 'rightmodules' => $right_modules]
);
}
public function detailAction(Request $request, $slug, $page)
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$subslug = 'nieuws-pers';
$tvslug = 'notaris-tv';
if($locale == 'fr'){
$subslug = 'nouveautes';
$tvslug = 'notaire-tv';
}
$subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
$subsite = $subsite_repo->getSubsiteBySlugAndLocale($subslug, $locale);
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
/** @var $section \Notaris\AdminBundle\Entity\Section */
$section = $section_repo->findOneByRedirectUrl("/$tvslug/$slug");
if(!$section or !$section->getIsActive()){
return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
}
$videosubsite = $subsite_repo->findOneBySlug($slug);
$perpage = 10;
/** @var $video_repo \Notaris\AdminBundle\Entity\VideoRepository */
$video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
$videos = $video_repo->getSubsiteVideos($videosubsite, $page, $perpage);
$total = $video_repo->getTotalSubsiteVideos($videosubsite);
if($slug == 'notarispraat' or $slug == 'notaire-webserie-le-5e-etage'):
$videosubsite = false;
endif;
if($slug == 'varia' || $slug == 'general'){
$videos = $video_repo->getListVideoIsVaria($locale, $page, $perpage);
$total = $video_repo->getListVideoIsVariaCount($locale);
}
$totalpages = ceil($total / $perpage);
//center modules
$modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
$right_modules = $modules_repo->findAllFromSection($section, $locale);
// $glossary = false;
// $faq = false;
//
// //glossary
// if($videosubsite) {
// $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
// $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $videosubsite);
//
// $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
// $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $videosubsite->getId());
// }
if($locale == 'nl'){
$currentslug = 'notaris-tv';
}else{
$currentslug = 'notaire-tv';
}
return $this->render('@NotarisFrontend/tv/detail.html.twig', [
'subsite' => $subsite,
'videosubsite' => $videosubsite,
'pageslug' => $slug,
'currentslug' => $currentslug,
'currentslug2' => $section->getSlug(),
'section' => $section,
'videos' => $videos,
'total' => $total,
'totalpages' => $totalpages,
'currentpage' => $page,
'rightmodules' => $right_modules
]);
}
public function videoAction(Request $request, $slug, $slugvideo)
{
$localeService = $this->get('notaris.locale.listener');
$locale = $localeService->getLocale();
if($locale == 'de'):
$locale = 'fr';
endif;
$manager = $this->getDoctrine()->getManager();
$subslug = 'nieuws-pers';
$tvslug = 'notaris-tv';
if($locale == 'fr'){
$subslug = 'nouveautes';
$tvslug = 'notaire-tv';
}
$subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
$subsite = $subsite_repo->getSubsiteBySlugAndLocale($subslug, $locale);
$section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
$section = $section_repo->findOneByRedirectUrl("/$tvslug/$slug");
if(!$section){
return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
}
$videosubsite = $subsite_repo->findOneBySlug($slug);
$video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
$video = $video_repo->getVideoBySlug($slugvideo);
if(!$video){
throw new NotFoundHttpException('Sorry not existing!');
}
// $randomvideo = $video_repo->getRandomSubsiteVideos($videosubsite, $video);
$randomvideo = $video_repo->getLatestSubsiteVideos($videosubsite, $video);
//center modules
$modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SubsiteModule');
$right_modules = $modules_repo->findAllRightFromSubsite($subsite, $locale);
// //glossary
// $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
// $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
//
// //faq
// $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
// $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
if($locale == 'nl'){
$currentslug = 'notaris-tv';
}else{
$currentslug = 'notaire-tv';
}
//image og
$shareImageVideo = '';
if($video->getAsset() && sizeof($video->getAsset()->getAssetImages()) > 0){
foreach ($video->getAsset()->getAssetImages() as $image) {
$imagepath = "/uploads/" . $image->getImage()->getLocale() . $image->getImage()->getFilename();
$cacheManager = $this->container->get('liip_imagine.cache.manager');
$shareImageVideo = $cacheManager->getBrowserPath($imagepath, 'facebook_share');
}
}
return $this->render('@NotarisFrontend/tv/video.html.twig', [
'subsite' => $subsite, 'pageslug' => $slug, 'currentslug' => $currentslug, 'currentslug2' => $section->getSlug(), 'section' => $section, 'video' => $video, 'randomvideos' => $randomvideo, 'rightmodules' => $right_modules, 'shareImageVideo' => $shareImageVideo
]);
}
public function clickAction($slug)
{
$manager = $this->getDoctrine()->getManager();
$job_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
$news = $job_repo->findOneBySlug($slug);
$news->setCountClicked($news->getCountClicked()+1);
$manager->flush();
$response = new JsonResponse();
$response->setData(array(
'clicksaved' => true
));
return $response;
}
}