src/Notaris/FrontendBundle/Controller/TvController.php line 164

Open in your IDE?
  1. <?php
  2. namespace Notaris\FrontendBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class TvController extends AbstractController
  8. {
  9.     public function indexAction()
  10.     {
  11.         $localeService = $this->get('notaris.locale.listener');
  12.         $locale = $localeService->getLocale();
  13.         if($locale == 'de'):
  14.             $locale = 'fr';
  15.         endif;
  16.         $manager = $this->getDoctrine()->getManager();
  17.         $slug = 'nieuws-pers';
  18.         $tvslug = 'notaris-tv';
  19.         if($locale == 'fr'){
  20.             $slug = 'nouveautes';
  21.             $tvslug = 'notaire-tv';
  22.         }
  23.         $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  24.         $subsite = $subsite_repo->getSubsiteBySlugAndLocale($slug, $locale);
  25.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  26.         $section = $section_repo->findOneBySlug($tvslug);
  27.         $video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  28.         /** @var $video_repo \Notaris\AdminBundle\Entity\VideoRepository */
  29.         $recent = $video_repo->getRecentVideos($locale, 10);
  30.         //center modules
  31.         $modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
  32.         $right_modules = $modules_repo->findAllFromSection($section, $locale);
  33.         //glossary
  34. //        $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
  35. //        $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
  36.         //faq
  37. //        $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
  38. //        $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
  39.         $currentslug = $section->getSlug();
  40.         return $this->render('@NotarisFrontend/tv/index.html.twig',
  41.             ['subsite' => $subsite, 'currentslug' => $currentslug, 'section' => $section, 'recent' => $recent, 'rightmodules' => $right_modules]
  42.         );
  43.     }
  44.     public function detailAction(Request $request, $slug, $page)
  45.     {
  46.         $localeService = $this->get('notaris.locale.listener');
  47.         $locale = $localeService->getLocale();
  48.         if($locale == 'de'):
  49.             $locale = 'fr';
  50.         endif;
  51.         $manager = $this->getDoctrine()->getManager();
  52.         $subslug = 'nieuws-pers';
  53.         $tvslug = 'notaris-tv';
  54.         if($locale == 'fr'){
  55.             $subslug = 'nouveautes';
  56.             $tvslug = 'notaire-tv';
  57.         }
  58.         $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  59.         $subsite = $subsite_repo->getSubsiteBySlugAndLocale($subslug, $locale);
  60.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  61.         /** @var  $section \Notaris\AdminBundle\Entity\Section */
  62.         $section = $section_repo->findOneByRedirectUrl("/$tvslug/$slug");
  63.         if(!$section or !$section->getIsActive()){
  64.             return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
  65.         }
  66.         $videosubsite = $subsite_repo->findOneBySlug($slug);
  67.         $perpage = 10;
  68.         /** @var  $video_repo \Notaris\AdminBundle\Entity\VideoRepository */
  69.         $video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  70.         $videos = $video_repo->getSubsiteVideos($videosubsite, $page, $perpage);
  71.         $total = $video_repo->getTotalSubsiteVideos($videosubsite);
  72.         if($slug == 'notarispraat' or $slug == 'notaire-webserie-le-5e-etage'):
  73.             $videosubsite = false;
  74.         endif;
  75.         if($slug == 'varia' || $slug == 'general'){
  76.             $videos = $video_repo->getListVideoIsVaria($locale, $page, $perpage);
  77.             $total = $video_repo->getListVideoIsVariaCount($locale);
  78.         }
  79.         $totalpages = ceil($total / $perpage);
  80.         //center modules
  81.         $modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SectionModule');
  82.         $right_modules = $modules_repo->findAllFromSection($section, $locale);
  83. //        $glossary = false;
  84. //        $faq = false;
  85. //
  86. //        //glossary
  87. //        if($videosubsite) {
  88. //            $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
  89. //            $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $videosubsite);
  90. //
  91. //            $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
  92. //            $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $videosubsite->getId());
  93. //        }
  94.         if($locale == 'nl'){
  95.             $currentslug = 'notaris-tv';
  96.         }else{
  97.             $currentslug = 'notaire-tv';
  98.         }
  99.         return $this->render('@NotarisFrontend/tv/detail.html.twig', [
  100.             'subsite' => $subsite,
  101.             'videosubsite' => $videosubsite,
  102.             'pageslug' => $slug,
  103.             'currentslug' => $currentslug,
  104.             'currentslug2' => $section->getSlug(),
  105.             'section' => $section,
  106.             'videos' => $videos,
  107.             'total' => $total,
  108.             'totalpages' => $totalpages,
  109.             'currentpage' => $page,
  110.             'rightmodules' => $right_modules
  111.             ]);
  112.     }
  113.     public function videoAction(Request $request, $slug, $slugvideo)
  114.     {
  115.         $localeService = $this->get('notaris.locale.listener');
  116.         $locale = $localeService->getLocale();
  117.         if($locale == 'de'):
  118.             $locale = 'fr';
  119.         endif;
  120.         $manager = $this->getDoctrine()->getManager();
  121.         $subslug = 'nieuws-pers';
  122.         $tvslug = 'notaris-tv';
  123.         if($locale == 'fr'){
  124.             $subslug = 'nouveautes';
  125.             $tvslug = 'notaire-tv';
  126.         }
  127.         $subsite_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Subsite');
  128.         $subsite = $subsite_repo->getSubsiteBySlugAndLocale($subslug, $locale);
  129.         $section_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Section');
  130.         $section = $section_repo->findOneByRedirectUrl("/$tvslug/$slug");
  131.         if(!$section){
  132.             return $this->redirect($this->generateUrl('notaris_frontend_homepage'), 301);
  133.         }
  134.         $videosubsite = $subsite_repo->findOneBySlug($slug);
  135.         $video_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  136.         $video = $video_repo->getVideoBySlug($slugvideo);
  137.         if(!$video){
  138.             throw new NotFoundHttpException('Sorry not existing!');
  139.         }
  140. //        $randomvideo = $video_repo->getRandomSubsiteVideos($videosubsite, $video);
  141.         $randomvideo = $video_repo->getLatestSubsiteVideos($videosubsite, $video);
  142.         //center modules
  143.         $modules_repo = $manager->getRepository('Notaris\AdminBundle\Entity\SubsiteModule');
  144.         $right_modules = $modules_repo->findAllRightFromSubsite($subsite, $locale);
  145. //        //glossary
  146. //        $glossary_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Glossary');
  147. //        $glossary = $glossary_repo->getRandomGlossaryFromSubsite($locale, $subsite);
  148. //
  149. //        //faq
  150. //        $faq_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Faq');
  151. //        $faq = $faq_repo->getRandomFaqSubsitePublic($locale, $subsite->getId());
  152.         if($locale == 'nl'){
  153.             $currentslug = 'notaris-tv';
  154.         }else{
  155.             $currentslug = 'notaire-tv';
  156.         }
  157.         //image og
  158.         $shareImageVideo = '';
  159.         if($video->getAsset() && sizeof($video->getAsset()->getAssetImages()) > 0){
  160.             foreach ($video->getAsset()->getAssetImages() as $image) {
  161.                 $imagepath = "/uploads/" . $image->getImage()->getLocale() . $image->getImage()->getFilename();
  162.                 $cacheManager = $this->container->get('liip_imagine.cache.manager');
  163.                 $shareImageVideo = $cacheManager->getBrowserPath($imagepath, 'facebook_share');
  164.             }
  165.         }
  166.         return $this->render('@NotarisFrontend/tv/video.html.twig', [
  167.             'subsite' => $subsite, 'pageslug' => $slug, 'currentslug' => $currentslug, 'currentslug2' => $section->getSlug(), 'section' => $section, 'video' => $video, 'randomvideos' => $randomvideo, 'rightmodules' => $right_modules, 'shareImageVideo' => $shareImageVideo
  168.         ]);
  169.     }
  170.     public function clickAction($slug)
  171.     {
  172.         $manager = $this->getDoctrine()->getManager();
  173.         $job_repo = $manager->getRepository('Notaris\AdminBundle\Entity\Video');
  174.         $news = $job_repo->findOneBySlug($slug);
  175.         $news->setCountClicked($news->getCountClicked()+1);
  176.         $manager->flush();
  177.         $response = new JsonResponse();
  178.         $response->setData(array(
  179.             'clicksaved' => true
  180.         ));
  181.         return $response;
  182.     }
  183. }