src/Gh/FrontBundle/Controller/PageController.php line 953

Open in your IDE?
  1. <?php
  2. namespace Gh\FrontBundle\Controller;
  3. use DateTime;
  4. use Exception;
  5. use Gh\DatabaseBundle\Classes\SearchClass;
  6. use Gh\DatabaseBundle\Entity\GhCard;
  7. use Gh\FrontBundle\Classes\BreadcrumbClass;
  8. use Gh\FrontBundle\Classes\Helpers\PaginatorHelper;
  9. use Gh\FrontBundle\Classes\Helpers\PictureHelper;
  10. use Gh\FrontBundle\Classes\InternalClass;
  11. use Gh\FrontBundle\Classes\ListValues\ConsoleClass;
  12. use Gh\FrontBundle\Classes\ListValues\SectionTypeClass;
  13. use Gh\FrontBundle\Classes\MenuActiveClass;
  14. use Gh\CommonBundle\Classes\Meta\MetaClass;
  15. use Gh\FrontBundle\Classes\Sidebar\SidebarClass;
  16. use Gh\FrontBundle\Classes\Sidebar\SidebarNews;
  17. use Gh\FrontBundle\Classes\Sidebar\SidebarReviews;
  18. use Gh\FrontBundle\Classes\TitleClass;
  19. use Gh\FrontBundle\Classes\UtilClass;
  20. use Gh\FrontBundle\Controller\GhController;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  23. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  24. use Swift_Message;
  25. class PageController extends GhController
  26. {
  27.     /**
  28.      * @Route(
  29.      *      "/",
  30.      *      name="GhFrontBundle_Page_homepage"
  31.      * )
  32.      * @Template()
  33.      */
  34.     public function homepageAction()
  35.     {      
  36.         return $this->homepageDefaultAction('tout');
  37.     }
  38.     
  39.     /**
  40.      * @Route(
  41.      *      "/{console}/",
  42.      *      name="GhFrontBundle_Page_homepageDefault",
  43.      *      requirements={"console" = "(3ds|pc|ps3|ps4|ps5|psv|wiiu|x360|xone|xonex|xseriesx|ios|android|web|switch|stadia)"}
  44.      * )
  45.      * @Template("@GhFront/page/homepage.html.twig")
  46.      */
  47.     public function homepageDefaultAction($console)
  48.     {
  49.         ini_set('memory_limit''256M');
  50.         
  51.         $em $this->getDoctrine()->getManager();
  52.         
  53.         // Convert $console param into console code
  54.         if ($console != 'tout') {
  55.             $console ConsoleClass::getInstance()->getCodeFromShort($console);
  56.         }
  57.         $consoleShort strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
  58.         
  59.         // Set menu active
  60.         MenuActiveClass::getInstance()->setMenuActive('homepage');
  61.         
  62.         // Generate title
  63.         if ($console != 'tout') {
  64.             TitleClass::getInstance()->setTitle('GameHope.com : Actualité du jeu vidéo sur '.ConsoleClass::getInstance()->getLongFromCode($console));
  65.         }
  66.         
  67.         // Retrieve list of consoles
  68.         $consolesList ConsoleClass::getInstance()->getCodes(truefalse);
  69.         
  70.         // Get the latest news
  71.         $newsList $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
  72.             $console
  73.             $this->container->getParameter('home_limit_news_headline'),
  74.             true
  75.         );
  76.         // Get the latest movies
  77.         $moviesList $em->getRepository('GhDatabaseBundle:GhMovie')->getListArticlesTableContents(
  78.             $this->container,
  79.             ($console == 'tout' '' $console),
  80.             '',
  81.             '',
  82.             0,
  83.             $this->container->getParameter('home_limit_latest_movies'),
  84.             false,
  85.             true
  86.         );
  87.         
  88.         // Get the latest articles
  89.         $latestArticles $em->getRepository('GhDatabaseBundle:FakeArticle')->getLatestArticlesForHome(
  90.             ($console == 'tout' '' $console),
  91.             true,
  92.             $this->container->getParameter('home_limit_latest_articles')
  93.         );
  94.         
  95.         // Retrieve entity associated to the article
  96.         foreach ($latestArticles as &$article) {
  97.             switch ($article->getSection()) {
  98.                 case 'dossier':
  99.                     $dossier $em->getRepository('GhDatabaseBundle:GhDossier')->findOneById($article->getArticleId());
  100.                     $article->setExtrafield($dossier);
  101.                     break;
  102.                 case 'preview':
  103.                     $preview $em->getRepository('GhDatabaseBundle:GhPreview')->findOneById($article->getArticleId());
  104.                     $article->setExtrafield($preview);
  105.                     break;
  106.             }
  107.         }
  108.         
  109.         // Retrieve headlines
  110.         $headlinesNb $this->container->getParameter('home_limit_headlines');
  111.         $headlinesList $em->getRepository('GhDatabaseBundle:GhHomeHeadline')->getHeadlineByConsole($console$headlinesNb);
  112.         
  113.         // Sidebar "News"
  114.         $nbNewsPerPage $this->container->getParameter('home_limit_news_sidebar_per_page');
  115.         $newsListSidebar $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
  116.             $console
  117.             $nbNewsPerPage,
  118.             false,
  119.             null,
  120.             null,
  121.             false
  122.         );
  123.         // Sidebar "Last reviews"
  124.         $latestReviews $em->getRepository('GhDatabaseBundle:FakeArticle')->getLatestReviewsForHome(
  125.             ($console == 'tout' '' $console),
  126.             true,
  127.             $this->container->getParameter('home_limit_latest_reviews')
  128.         );
  129.         // Latest hints
  130.         $nbHintsPerPage $this->container->getParameter('home_limit_news_sidebar_per_page');
  131.         $hintsListSidebar $em->getRepository('GhDatabaseBundle:GhHint')->getHintsListByConsole(
  132.             $console,
  133.             $nbHintsPerPage
  134.         );
  135.         // Push the sidebars
  136.         SidebarClass::getInstance()->push('news', new SidebarNews($newsList), '-1');
  137.         return array(
  138.             'console' => $consoleShort,
  139.             'consolesList' => $consolesList,
  140.             'newsList' => $newsList,
  141.             'moviesList' => $moviesList,
  142.             'latestArticles' => $latestArticles,
  143.             'headlinesList' => $headlinesList,
  144.             'latestReviews' => $latestReviews,
  145.             'latestNews' => $newsListSidebar,
  146.             'latestHints' => $hintsListSidebar
  147.         );
  148.     }
  149.     
  150.     /**
  151.      * @Route(
  152.      *      "/{console}/{cardId}-{slug}/image_{pictureId}.html",
  153.      *      name="GhFrontBundle_Page_picture",
  154.      *      requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "pictureId" = "([0-9]+)"}
  155.      * )
  156.      * @Template()
  157.      */
  158.     public function pictureAction($console$cardId$slug$pictureId)
  159.     {      
  160.         $em $this->getDoctrine()->getManager();
  161.         $card $em->getRepository('GhDatabaseBundle:GhCard')->findOneById($cardId);
  162.         
  163.         if ($card === null) {
  164.             // Throw a 404 error if no card found
  165.             throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
  166.         }
  167.         
  168.         // Get the picture
  169.         $picture $em->getRepository('GhDatabaseBundle:GhGallery')->findOneById($pictureId);
  170.         
  171.         if ($picture === null) {
  172.             // Throw a 404 error if no card found
  173.             throw $this->createNotFoundException('Aucune image n\'a été trouvée');
  174.         }
  175.         
  176.         // Get the thumbs list to be displayed on the top of the screen
  177.         $thumbsList $em->getRepository('GhDatabaseBundle:GhGallery')->getThumbsList(
  178.             $card
  179.             $pictureId
  180.             $this->container->getParameter('gallery_thumbs_limit')
  181.         );
  182.         
  183.         // Previous/next buttons
  184.         $currentIndex UtilClass::findIndexInList($picture$thumbsList'getId');
  185.         if ($currentIndex 0) {
  186.             $previousThumb $thumbsList[$currentIndex 1];
  187.         } else {
  188.             $previousThumb null;
  189.         }
  190.         
  191.         // Next button
  192.         if ($currentIndex count($thumbsList) - 1) {
  193.             $nextThumb $thumbsList[$currentIndex 1];
  194.         } else {
  195.             $nextThumb null;
  196.         }
  197.         
  198.         // "Previous page" button
  199.         $previousPage $this->generatePreviousPageLink('GhFrontBundle_Page_picture_previousPage', function($url) {
  200.             return InternalClass::isUrlPictureViewer($url);
  201.         });
  202.         
  203.         // Generate title
  204.         TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : la galerie d\'images');
  205.         
  206.         // Generate breadcrumb
  207.         $breadcrumb BreadcrumbClass::getInstance();
  208.         $breadcrumb->addPath(ConsoleClass::getInstance()->getLongFromCode($card->getConsole()), $this->get('router'), 'GhFrontBundle_Page_homepageDefault', array('console' => ConsoleClass::getInstance()->getShortFromCode($card->getConsole())));
  209.         $breadcrumb->addPath($card->getTitle(), $this->get('router'), 'GhFrontBundle_Card_card', array('card' => $card));
  210.         $breadcrumb->addPath('Galerie'$this->get('router'), 'GhFrontBundle_Card_galleryDefault', array('card' => $card));
  211.         $breadcrumb->addPath('Image');
  212.         
  213.         // Generate meta
  214.         $meta MetaClass::getInstance();
  215.         $meta->setMetaCard($card);
  216.         $description 'Galerie d\'images du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : screenshots, captures d\'écran, artworks, wallpapers.';
  217.         $meta->addMeta('description'$description);
  218.         $meta->addMeta('og:description'$description);
  219.         $meta->addMeta('og:image'$this->container->getParameter('base_url_absolute').PictureHelper::displayGalleryThumb($this->container$picture));
  220.         
  221.         // Generate canonical URL
  222.         $this->updateCanonicalUrl($card, array('pictureId' => $pictureId));
  223.         
  224.         // Set menu active
  225.         MenuActiveClass::getInstance()->setMenuActive('gallery');
  226.         
  227.         return array(
  228.             'card' => $card
  229.             'picture' => $picture
  230.             'thumbsList' => $thumbsList
  231.             'currentIndex' => $currentIndex,
  232.             'previousThumb' => $previousThumb,
  233.             'nextThumb' => $nextThumb,
  234.             'previousPage' => $previousPage
  235.         );
  236.     }
  237.     
  238.     /**
  239.      * @Route(
  240.      *      "/images/{id}-{slug}.html",
  241.      *      name="GhFrontBundle_Page_pictureWysiwyg",
  242.      *      requirements={"id" = "([0-9a-zA-Z_-]+)", "slug" = "([0-9a-zA-Z_-]+)"}
  243.      * )
  244.      * @Template()
  245.      */
  246.     public function pictureWysiwygAction($id$slug)
  247.     {   
  248.         // Retrieve entity
  249.         $em $this->getDoctrine()->getManager();
  250.         $picture $em->getRepository('GhDatabaseBundle:GhPictureWysiwyg')->findOneById($id);
  251.         
  252.         if ($picture === null) {
  253.             // Throw a 404 error if no card found
  254.             throw $this->createNotFoundException('Aucune image n\'a été trouvée');
  255.         }
  256.         
  257.         // Generate canonical URL
  258.         $this->updateCanonicalUrl(NULL, array('id' => $picture->getId(), 'slug' => $picture->getSlug()));
  259.         
  260.         // "Previous page" button
  261.         $previousPage $this->generatePreviousPageLink('GhFrontBundle_Page_pictureWysiwyg_previousPage', function($url) {
  262.             return InternalClass::isUrlPictureWysiwygViewer($url);
  263.         });
  264.         
  265.         $breadcrumb BreadcrumbClass::getInstance();
  266.         $breadcrumb->addPath($picture->getDescription());
  267.         
  268.         TitleClass::getInstance()->setTitle($picture->getDescription().' - Image');
  269.         
  270.         // Generate meta
  271.         $meta MetaClass::getInstance();
  272.         $description 'Image de jeu vidéo : '.$picture->getDescription().'... et bien plus encore sur GameHope.com !';
  273.         $meta->addMeta('description'$description);
  274.         $meta->addMeta('og:description'$description);
  275.         $meta->addMeta('og:image'$this->container->getParameter('base_url_absolute').$picture->getLowpath());
  276.         
  277.         return array(
  278.             'picture' => $picture,
  279.             'previousPage' => $previousPage
  280.         );
  281.     }
  282.     
  283.     /**
  284.      * @Route(
  285.      *      "/actu/{year}/{month}/{day}/",
  286.      *      name="GhFrontBundle_Page_daily",
  287.      *      requirements={"year" = "([0-9]{4})", "month" = "([0-9]{2})", "day" = "([0-9]{2})"}
  288.      * )
  289.      * @Template()
  290.      */
  291.     public function dailyAction($year$month$day)
  292.     {
  293.         $em $this->getDoctrine()->getManager();
  294.         setlocale(LC_ALL,'fr_FR.UTF-8''French');
  295.         
  296.         // Find current week (set hour to 5.00 AM to be sure to avoid ambiguity due to timezone)
  297.         $currentDate = new DateTime($year.'-'.$month.'-'.$day);
  298.         $currentDate->setTime(500);
  299.         $currentDateBegin UtilClass::getDateWeekBegin($currentDate);
  300.         $currentDateEnd UtilClass::getDateWeekEnd($currentDate);
  301.         
  302.         // Compute all the days of the selected week
  303.         $currentDateList = array();
  304.         for ($i 0$i 7$i++) {
  305.             $currentDateList[$i] = new DateTime('@'.$currentDateBegin->getTimestamp());
  306.             $currentDateList[$i]->modify('+'.$i.' days');
  307.         }
  308.         
  309.         // Find previous week
  310.         $previousWeekDateBegin null;
  311.         $previousWeekDateEnd null;
  312.         // Set a limit to 1999 to avoid infinite pages
  313.         if ($currentDate->format('Y') >= 1999) {
  314.             $previousDate = new DateTime('@'.$currentDate->getTimestamp());
  315.             $previousDate->modify('-1 weeks');
  316.             $previousWeekDateBegin UtilClass::getDateWeekBegin($previousDate);
  317.             $previousWeekDateEnd UtilClass::getDateWeekEnd($previousDate);
  318.         }
  319.         
  320.         // Find next week
  321.         $nextDate = new DateTime('@'.$currentDate->getTimestamp());
  322.         $nextDate->modify('+1 weeks');
  323.         $nextWeekDateBegin UtilClass::getDateWeekBegin($nextDate);
  324.         $nextWeekDateEnd UtilClass::getDateWeekEnd($nextDate);
  325.         // Set a limit to the current day date
  326.         if ($nextWeekDateBegin->getTimestamp() > time()) {
  327.             $nextWeekDateBegin null;
  328.             $nextWeekDateEnd null;
  329.         }
  330.         
  331.         // Generate title
  332.         $title UtilClass::generateDailyTitlePage($currentDateBegin$currentDateEnd);
  333.         TitleClass::getInstance()->setTitle($title);
  334.         
  335.         // Generate breadcrumb
  336.         $breadcrumb BreadcrumbClass::getInstance();
  337.         $breadcrumb->addPath('Actualité'$this->get('router'), 'GhFrontBundle_Page_dailyDefault');
  338.         $breadcrumb->addPath($title);
  339.         
  340.         // Set menu active
  341.         MenuActiveClass::getInstance()->setMenuActive('daily');
  342.         
  343.         // Retrieve articles: reviews, previews, dossiers
  344.         $reviewsList $em->getRepository('GhDatabaseBundle:GhReview')->getListArticlesTableContents(
  345.             $this->container''''''00falsetrue$currentDate
  346.         );
  347.         $previewsList $em->getRepository('GhDatabaseBundle:GhPreview')->getListArticlesTableContents(
  348.             $this->container''''''00falsetrue$currentDate
  349.         );
  350.         $dossiersList $em->getRepository('GhDatabaseBundle:GhDossier')->getListArticlesTableContents(
  351.             $this->container''''''00falsetrue$currentDate
  352.         );
  353.         $geeksList $em->getRepository('GhDatabaseBundle:GhGeek')->getListArticlesTableContents(
  354.             $this->container''''''00falsetrue$currentDate
  355.         );
  356.         $articlesList array_merge($reviewsList$previewsList$dossiersList$geeksList);
  357.         
  358.         // Retrieve news
  359.         $newsList $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
  360.             'tout'0falsenull$currentDate
  361.         );
  362.         
  363.         // Retrieve movies
  364.         $moviesList $em->getRepository('GhDatabaseBundle:GhMovie')->getListArticlesTableContents(
  365.             $this->container''''''00falsetrue$currentDate
  366.         );
  367.         
  368.         // Get the cards of day
  369.         $cardsList $em->getRepository('GhDatabaseBundle:GhCard')->searchListCards(
  370.             $this->container
  371.             array("datefrance" => "asc""title" => "asc"), 
  372.             array("CONCAT(c.title, c.dateFrance)"), 
  373.             array('type' => GhCard::CARD_TYPE_GAME), 
  374.             $year
  375.             $month,
  376.             $day);
  377.         return array(
  378.             'currentDate' => $currentDate,
  379.             'currentDateList' => $currentDateList,
  380.             'currentDateBegin' => $currentDateBegin,
  381.             'currentDateEnd' => $currentDateEnd,
  382.             'previousWeekDateBegin' => $previousWeekDateBegin,
  383.             'previousWeekDateEnd' => $previousWeekDateEnd,
  384.             'nextWeekDateBegin' => $nextWeekDateBegin,
  385.             'nextWeekDateEnd' => $nextWeekDateEnd,
  386.             'articlesList' => $articlesList,
  387.             'newsList' => $newsList,
  388.             'moviesList' => $moviesList,
  389.             'cardsList' => $cardsList
  390.         );
  391.     }
  392.     
  393.     /**
  394.      * @Route(
  395.      *      "/actu/",
  396.      *      name="GhFrontBundle_Page_dailyDefault"
  397.      * )
  398.      */
  399.     public function dailyDefaultAction()
  400.     {      
  401.         return $this->redirect($this->generateUrl(
  402.                 'GhFrontBundle_Page_daily',
  403.                 array("year" => date('Y'), "month" => date('m'), "day" => date('d'))
  404.             ));
  405.     }
  406.     
  407.     /**
  408.      * @Route(
  409.      *      "/{console}/calendrier/{year}/{month}/",
  410.      *      name="GhFrontBundle_Page_calendar",
  411.      *      requirements={"console" = "([0-9a-zA-Z]+)", "year" = "([0-9]{4})", "month" = "([0-9]{1,2})"}
  412.      * )
  413.      * @Template()
  414.      */
  415.     public function calendarAction($console$year$month)
  416.     {  
  417.         $request $this->getRequest();
  418.         if($request->request->get('submitPeriod')) {
  419.             return $this->redirect($this->generateUrl('GhFrontBundle_Page_calendar', array('console' => $console'year' => $request->request->get('year'), 'month' => str_pad($request->request->get('month'), 20STR_PAD_LEFT))));
  420.         }
  421.         $consoleLong ConsoleClass::getInstance()->getLongFromCode($console);
  422.         $consoleShort strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
  423.         MenuActiveClass::getInstance()->setMenuActive('calendar');
  424.         $currentCalendarPeriod mktime(500$month1$year);
  425.         $moisAnnee UtilClass::getFrenchDate($currentCalendarPeriod"%B %Y");
  426.         $relatif "de ";
  427.         if(in_array(substr($moisAnnee01), array("a","e","i","o","u","y"))) {
  428.             $relatif "d'";
  429.         }
  430.         $titlePage 'Les sorties de jeux vidéo '.$relatif.$moisAnnee;
  431.         $metaDescription "Retrouvez toutes les sorties de jeux vidéo du mois ".$relatif.$moisAnnee;
  432.         // Generate breadcrumb
  433.         $breadcrumb BreadcrumbClass::getInstance();
  434.         $breadcrumb->addPath('Sorties'$this->get('router'), 'GhFrontBundle_Page_calendarConsole', array('console' => 'tout'));
  435.         if($console != "tout") {
  436.             $breadcrumb->addPath($consoleLong$this->get('router'), 'GhFrontBundle_Page_calendarConsole', array('console' => $consoleShort));
  437.             $titlePage .= " sur $consoleLong";
  438.             $metaDescription .= " sur $consoleLong";
  439.         }
  440.         $breadcrumb->addPath(ucfirst($moisAnnee));
  441.         TitleClass::getInstance()->setTitle($titlePage);
  442.         MetaClass::getInstance()->addMeta('description'$metaDescription);
  443.         $em $this->getDoctrine()->getManager();
  444.         return array(
  445.             'console' => $consoleShort,
  446.             'currentCalendarPeriod' => $currentCalendarPeriod,
  447.             'previousDate' => strtotime("-1 month"$currentCalendarPeriod),
  448.             'nextDate' => strtotime("+1 month"$currentCalendarPeriod),
  449.             'consolesList' => ConsoleClass::getInstance()->getCodes(truefalsefalse),
  450.             'unmissableCards' => $em->getRepository('GhDatabaseBundle:GhCard')->searchListCards($this->container, array("counter" => "desc"), array("c.title"), array('type' => GhCard::CARD_TYPE_GAME'console' => $console), $year$monthNULL, array(0,$this->container->getParameter('calendar_unmissable_limit'))),
  451.             'cardsList' => $em->getRepository('GhDatabaseBundle:GhCard')->searchListCards($this->container, array("datefrance" => "asc""title" => "asc"), array("CONCAT(c.title, c.dateFrance)"), array('type' => GhCard::CARD_TYPE_GAME'console' => $console), $year$month));
  452.     }
  453.     
  454.     /**
  455.      * @Route(
  456.      *      "/{console}/calendrier/",
  457.      *      name="GhFrontBundle_Page_calendarConsole",
  458.      *      requirements={"console" = "([0-9a-zA-Z]+)"}
  459.      * )
  460.      * @Template()
  461.      */
  462.     public function calendarConsoleAction($console)
  463.     {      
  464.         return $this->redirect($this->generateUrl(
  465.                 'GhFrontBundle_Page_calendar',
  466.                 array("console" => $console"year" => date('Y'), "month" => date('m'))
  467.             ));
  468.     }
  469.     
  470.     /**
  471.      * @Route(
  472.      *      "/{console}/top/{source}.html",
  473.      *      name="GhFrontBundle_Page_chart",
  474.      *      requirements={"console" = "([0-9a-zA-Z]+)", "source" = "(tout|gamehope|lecteurs)"}
  475.      * )
  476.      * @Template()
  477.      */
  478.     public function chartAction($console$source)
  479.     {      
  480.         $em $this->getDoctrine()->getManager();
  481.         
  482.         $request $this->getRequest();
  483.         $filters = array('type' => GhCard::CARD_TYPE_GAME);
  484.         
  485.         $consoleLong ConsoleClass::getInstance()->getLongFromCode($console);
  486.         $consoleShort strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
  487.         MenuActiveClass::getInstance()->setMenuActive('chart');
  488.         $listeSources SectionTypeClass::getInstance()->getListBySection('chartSources');
  489.         $listeCategories SectionTypeClass::getInstance()->getListBySection('cardCategory');
  490.         $titlePage 'Top jeux vidéo ';
  491.         $metaDescription 'Retrouvez le top (classement, charts) des jeux vidéo ';
  492.         
  493.         // Generate breadcrumb and meta
  494.         $breadcrumb BreadcrumbClass::getInstance();
  495.         $breadcrumb->addPath('Tops'$this->get('router'), 'GhFrontBundle_Page_chart', array('console' => 'tout''source' => GhCard::CARD_SOURCE_ALL));
  496.         
  497.         $metaDescription .= SectionTypeClass::getInstance()->getLabelById('chartSources'$source);
  498.         if($source != GhCard::CARD_SOURCE_ALL) {
  499.             $breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('chartSources'$source), $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => 'tout''source' => $source));
  500.         }
  501.         
  502.         if($console != "tout") {
  503.             $breadcrumb->addPath($consoleLong$this->get('router'), 'GhFrontBundle_Page_chart', array('console' => $consoleShort'source' => $source));
  504.             $titlePage .= " sur $consoleLong";
  505.             $metaDescription .= " sur $consoleLong";
  506.             $filters['console'] = $console;
  507.         } else {
  508.             $titlePage .= " sur tous supports";
  509.             $metaDescription .= " sur tous supports";
  510.         }
  511.         
  512.         $titlePage .= ' - '.SectionTypeClass::getInstance()->getLabelById('chartSources'$source);
  513.         
  514.         // If a category is set, add extra information in title and breadcrumb
  515.         $category null;
  516.         if($request->query->get('cat')) {
  517.             $category $request->query->get('cat');
  518.             $filters['category'] = $category;
  519.             $breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('cardCategory'$category), $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => $consoleShort'source' => $source), '?cat='.$category);
  520.             $titlePage .= ' - '.SectionTypeClass::getInstance()->getLabelById('cardCategory'$category);
  521.         }
  522.         
  523.         // Set title and meta
  524.         TitleClass::getInstance()->setTitle($titlePage);
  525.         MetaClass::getInstance()->addMeta('description'$metaDescription);
  526.         
  527.         // Get chart
  528.         $cardsList $em->getRepository('GhDatabaseBundle:GhCard')->getTopScoreFrom(
  529.             $this->container
  530.             $source
  531.             $filters
  532.             array(new DateTime($this->container->getParameter('card_chart_max_age')), new DateTime('now')), 
  533.             array(0,10)
  534.         );
  535.         return array(
  536.             'console' => $consoleShort,
  537.             'source' => $source,
  538.             'category' => $category,
  539.             'sources' => $listeSources,
  540.             'consoles' => ConsoleClass::getInstance()->getCodes(truetruefalse),
  541.             'categories' => $listeCategories,
  542.             'cardsList' => $cardsList);
  543.     }
  544.     
  545.     /**
  546.      * @Route(
  547.      *      "/{console}/top/",
  548.      *      name="GhFrontBundle_Page_chartDefault",
  549.      *      requirements={"console" = "([0-9a-zA-Z]+)"}
  550.      * )
  551.      * @Template()
  552.      */
  553.     public function chartDefaultAction($console)
  554.     {      
  555.         return $this->redirect($this->generateUrl(
  556.                 'GhFrontBundle_Page_chart',
  557.                 array("console" => $console"source" => "gamehope")
  558.             ), 301);
  559.     }
  560.      
  561.     /**
  562.      * @Route(
  563.      *      "/presse/{pressId}-{slug}/page-{page}.html",
  564.      *      name="GhFrontBundle_Page_press",
  565.      *      requirements={"pressId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "page" = "([0-9]+)"}
  566.      * )
  567.      * @Template()
  568.      */
  569.     public function pressAction($pressId$slug$page)
  570.     {
  571.         $em $this->getDoctrine()->getManager();
  572.         // Get the magazine
  573.         $press $em->getRepository('GhDatabaseBundle:GhPress')->findOneById($pressId);
  574.         
  575.         // Compute pagination
  576.         $paginator = new PaginatorHelper($em->getRepository('GhDatabaseBundle:GhPressReview')->countPressReviewByPressId($pressId), $page$this->container->getParameter('press_reviews_per_page'));
  577.         $paginator->setSfLinkedController($this);
  578.         $paginator->setRouter($this->get('router'));
  579.         $paginator->setSfUrlParameters(array('pressId' => $press->getId(), 'slug' => $press->getSlug()));
  580.         $paginator->setPageParameterName('page');
  581.         $paginator->setPaginationStep($this->container->getParameter('press_reviews_pagination_step'));
  582.         
  583.         // Get the list of news
  584.     $associatedPressReviews $em->getRepository('GhDatabaseBundle:GhPressReview')->getPressReviewsByPressId($pressId$paginator->getOffset(), $paginator->getLimit());
  585.         
  586.         // Generate breadcrumb and meta
  587.         $breadcrumb BreadcrumbClass::getInstance();
  588.         $breadcrumb->addPath($press->getTitle(),  $this->get('router'), 'GhFrontBundle_Page_pressDefault', array('pressId' => $press->getId(), 'slug' => $press->getSlug()));
  589.         if ($page != 1) {
  590.             $breadcrumb->addPath('Page '.$page);
  591.         }
  592.         
  593.         // Set title and meta
  594.         TitleClass::getInstance()->setTitle($press->getTitle().' : Revue de presse sur GameHope.com');
  595.         
  596.         // Generate canonical URL
  597.         $canonicalUrl $this->get('router')->generate(
  598.             $this->getRequest()->get('_route'),
  599.             array('pressId' => $press->getId(), 'slug' => $press->getSlug(), 'page' => $page), 
  600.             UrlGeneratorInterface::ABSOLUTE_URL
  601.         );
  602.         $meta MetaClass::getInstance();
  603.         $meta->addLink('canonical'$canonicalUrl);
  604.         
  605.         return array(
  606.             'press' => $press,
  607.             'associatedPressReviews' => $associatedPressReviews,
  608.             'paginator' => $paginator
  609.         );
  610.     }
  611.     
  612.     /**
  613.      * @Route(
  614.      *      "/presse/{pressId}-{slug}/",
  615.      *      name="GhFrontBundle_Page_pressDefault",
  616.      *      requirements={"pressId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
  617.      * )
  618.      */
  619.     public function pressDefaultAction($pressId$slug)
  620.     {      
  621.         return $this->redirect($this->generateUrl(
  622.                 'GhFrontBundle_Page_press',
  623.                 array("pressId" => $pressId"slug" => $slug"page" => 1)
  624.             ), 301);
  625.     }
  626.     
  627.     /**
  628.      * @Route(
  629.      *      "/recherche.html",
  630.      *      name="GhFrontBundle_Page_search"
  631.      * )
  632.      * @Template()
  633.      */
  634.     public function searchAction()
  635.     {
  636.         $request $this->getRequest();
  637.         $search $request->query->get('queljeu');
  638.         $selectedConsole $request->query->get('console');
  639.         
  640.         // Get the search result
  641.         $em $this->getDoctrine()->getManager();
  642.         $limit $this->container->getParameter('search_limit');
  643.         $cardsList $em->getRepository('GhDatabaseBundle:GhCard')->search($search$selectedConsole$limitfalse);
  644.         
  645.         // When only 1 card is matched, forward to the card page
  646.         if (count($cardsList) == 1) {
  647.             $routerParams UtilClass::getRouteParamsFromCard(array_pop($cardsList));
  648.             return $this->redirect($this->generateUrl('GhFrontBundle_Card_card'$routerParams));
  649.         }
  650.         
  651.         // Extract list of consoles where results are found
  652.         $consolesFound SearchClass::getConsolesList($cardsList);
  653.         
  654.         // Generate breadcrumb, title
  655.         $breadcrumb BreadcrumbClass::getInstance();
  656.         $breadcrumb->addPath('Rechercher '.$search);
  657.         TitleClass::getInstance()->setTitle($search.' jeu vidéo');
  658.         
  659.         return array(
  660.             'cardsList' => $cardsList,
  661.             'search' => $search,
  662.             'selectedConsole' => $selectedConsole,
  663.             'consolesList' => ConsoleClass::getInstance()->getCodes(falsefalsetrue),
  664.             'consolesFound' => $consolesFound
  665.         );
  666.     }
  667.     
  668.     /**
  669.      * @Route(
  670.      *      "/team/",
  671.      *      name="GhFrontBundle_Page_team"
  672.      * )
  673.      * @Template()
  674.      */
  675.     public function teamAction()
  676.     {
  677.         TitleClass::getInstance()->setTitle('La team');
  678.         MetaClass::getInstance()->addMeta('description''Retrouvez ici toute l\'équipe de GameHope');
  679.         
  680.         $breadcrumb BreadcrumbClass::getInstance();
  681.         $breadcrumb->addPath('Team');
  682.         
  683.         $em $this->getDoctrine()->getManager();
  684.         
  685.         $team $em->getRepository('GhDatabaseBundle:GhTeam')->getTeamOrderedByOrder();
  686.         
  687.         return array(
  688.             'team' => $team
  689.         );
  690.     }
  691.     
  692.     /**
  693.      * @Route(
  694.      *      "/apropos.html",
  695.      *      name="GhFrontBundle_Page_about"
  696.      * )
  697.      * @Template()
  698.      */
  699.     public function aboutAction()
  700.     {
  701.         TitleClass::getInstance()->setTitle('A propos');
  702.         
  703.         $breadcrumb BreadcrumbClass::getInstance();
  704.         $breadcrumb->addPath('A propos');
  705.         
  706.         $em $this->getDoctrine()->getManager();
  707.         $numbers = array(
  708.             'number_card' => $em->getRepository('GhDatabaseBundle:GhCard')->count(),
  709.             'number_gallery' => $em->getRepository('GhDatabaseBundle:GhGallery')->count(),
  710.             'number_review' => $em->getRepository('GhDatabaseBundle:GhReview')->count(),
  711.             'number_preview' => $em->getRepository('GhDatabaseBundle:GhPreview')->count(),
  712.             'number_hint' => $em->getRepository('GhDatabaseBundle:GhHint')->count(),
  713.             'number_download' => $em->getRepository('GhDatabaseBundle:GhDownload')->count(),
  714.             'number_movie' => $em->getRepository('GhDatabaseBundle:GhMovie')->count(),
  715.             'number_news' => $em->getRepository('GhDatabaseBundle:GhNews')->count(),
  716.             'number_press_review' => $em->getRepository('GhDatabaseBundle:GhPressReview')->count()
  717.         );
  718.         
  719.         return array(
  720.             'numbers' => $numbers
  721.         );
  722.     }
  723.     
  724.     /**
  725.      * @Route(
  726.      *      "/recrutement.html",
  727.      *      name="GhFrontBundle_Page_hiring"
  728.      * )
  729.      * @Template()
  730.      */
  731.     public function hiringAction()
  732.     {      
  733.         TitleClass::getInstance()->setTitle('GameHope recrute !');
  734.         
  735.         $breadcrumb BreadcrumbClass::getInstance();
  736.         $breadcrumb->addPath('Recrutement');
  737.         
  738.         return array();
  739.     }
  740.     
  741.     /**
  742.      * @Route(
  743.      *      "/notation.html",
  744.      *      name="GhFrontBundle_Page_notation"
  745.      * )
  746.      * @Template()
  747.      */
  748.     public function notationAction()
  749.     {
  750.         TitleClass::getInstance()->setTitle('La notation de GameHope');
  751.         
  752.         $breadcrumb BreadcrumbClass::getInstance();
  753.         $breadcrumb->addPath('La notation de GameHope');
  754.         
  755.         return array();
  756.     }
  757.     
  758.     /**
  759.      * @Route(
  760.      *      "/hasard.html",
  761.      *      name="GhFrontBundle_Page_random"
  762.      * )
  763.      */
  764.     public function randomAction()
  765.     {    
  766.         $em $this->getDoctrine()->getManager();
  767.         $card $em->getRepository('GhDatabaseBundle:GhCard')->getOneByRand();
  768.         if($card)
  769.         {
  770.             $routerParams UtilClass::getRouteParamsFromCard($card);
  771.             return $this->redirect($this->generateUrl('GhFrontBundle_Card_card'$routerParams), 302);
  772.         }       
  773.         return $this->redirect($this->generateUrl('GhFrontBundle_Page_homepage'302));
  774.     } 
  775.     
  776.     /**
  777.      * @Route(
  778.      *      "/contact/",
  779.      *      name="GhFrontBundle_Page_contactAuthor"
  780.      * )
  781.      * @Template("@GhFront/page/contact.html.twig")
  782.      */
  783.     public function contactAuthorAction()
  784.     {
  785.         $author $this->getRequest()->query->get('author');
  786.         TitleClass::getInstance()->setTitle('Formulaire de contact');
  787.         $breadcrumb BreadcrumbClass::getInstance();
  788.         $breadcrumb->addPath('Contact');
  789.         
  790.         $em $this->getDoctrine()->getManager();
  791.         if ($author != '') {
  792.             $author $em->getRepository('GhDatabaseBundle:GhTeam')->findOneByName($author);
  793.         }
  794.         if($author == NULL || $author == '')
  795.         {
  796.             $author $em->getRepository('GhDatabaseBundle:GhTeam')->findOneByName('Monsieur Tomate');
  797.         }
  798.         $authors $em->getRepository('GhDatabaseBundle:GhTeam')->getTeamOrderedByOrder();
  799.         
  800.         return array(
  801.             'author' => $author,
  802.             'team' => $authors
  803.         );
  804.     }
  805.     
  806.     /**
  807.      * @Route(
  808.      *      "/contactValidation.html",
  809.      *      name="GhFrontBundle_Page_checkContactForm"
  810.      * )
  811.      */
  812.     public function checkContactFormAction()
  813.     {  
  814.         $request $this->getRequest();
  815.         $recipient $request->request->get('recipient''');
  816.         $name $request->request->get('name''');
  817.         $email $request->request->get('email''');
  818.         $subject $request->request->get('subject''');
  819.         $message $request->request->get('message''');
  820.         $captcha strtolower(trim($request->request->get('check''')));
  821.         
  822.         $validForm TRUE;
  823.         $toEmail '';
  824.         switch($recipient)
  825.         {
  826.             case 'partenariat' :
  827.             case 'publicite' 
  828.             case 'tech' 
  829.                 $toEmail 'tomate@gamehope.com'
  830.                 break;
  831.             case 'presse' :
  832.                 $toEmail 'joker@gamehope.com';
  833.                 break;
  834.             case 'recrutement' :
  835.                 $toEmail 'recrutement@gamehope.com';
  836.                 break;
  837.             case 'webmaster' :
  838.                 $toEmail 'webmaster@gamehope.com';
  839.                 break;
  840.         }
  841.         if($toEmail == '')
  842.         {
  843.             $em $this->getDoctrine()->getManager();
  844.             $member $em->getRepository('GhDatabaseBundle:GhTeam')->findOneById($recipient);
  845.             if($member != NULL)
  846.             {
  847.                 $toEmail $member->getEmail();
  848.             }
  849.         }
  850.         if($toEmail == '')
  851.         {
  852.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Le destinataire est invalide.'));
  853.         }
  854.         if(trim($name) == '')
  855.         {
  856.             $validForm FALSE;
  857.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Le nom est obligatoire.'));
  858.         }
  859.         if(trim($email) == '')
  860.         {
  861.             $validForm FALSE;
  862.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'L\'email est obligatoire.'));
  863.         }
  864.         else if(!preg_match("#^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$#"$email))
  865.         {
  866.             $validForm FALSE;
  867.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'L\'email est invalide.'));
  868.         }
  869.         if(trim($subject) == '')
  870.         {
  871.             $validForm FALSE;
  872.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Le sujet est obligatoire.'));
  873.         }
  874.         if(trim($message) == '')
  875.         {
  876.             $validForm FALSE;
  877.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Le message est obligatoire.'));
  878.         }
  879.         
  880.         if($captcha != 'blanc' && $captcha != 'blanche')
  881.         {
  882.             $validForm FALSE;
  883.             $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'La question de sécurité n\'est pas correctement renseignée.'));
  884.         }
  885.         
  886.         if($validForm)
  887.         {
  888.             try
  889.             {
  890.                 $content Swift_Message::newInstance()
  891.                     ->setSubject($subject)
  892.                     ->setFrom(array($email => $name))
  893.                     ->setTo($toEmail)
  894.                     ->setBody($message);
  895.                 if ($this->get('mailer')->send($content)) {
  896.                     $this->get('session')->getFlashBag()->add('success', array('title' => 'Contact''content' => 'Votre message a été envoyé avec succès !'));
  897.                 } else {
  898.                     $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Erreur lors de l\'envoi de l\'email. Veuillez contacter l\'administrateur du site : WEBMASTER AT GAMEHOPE POINT COM'));  
  899.                 }
  900.             }
  901.             catch(Exception $e)
  902.             {
  903.                 $this->get('session')->getFlashBag()->add('error', array('title' => 'Contact''content' => 'Erreur lors de l\'envoi de l\'email. Veuillez contacter l\'administrateur du site : WEBMASTER AT GAMEHOPE POINT COM'));              
  904.             }
  905.         }
  906.         return $this->redirect($request->headers->get('referer'));
  907.     }
  908.     
  909.     /**
  910.      * @Route(
  911.      *      "/down.html",
  912.      *      name="GhFrontBundle_Page_download"
  913.      * )
  914.      */
  915.     public function doDownloadAction()
  916.     {
  917.         $id $this->getRequest()->query->get('id');
  918.         
  919.         // Get download
  920.         $em $this->getDoctrine()->getManager();
  921.         $download $em->getRepository('GhDatabaseBundle:GhDownload')->findOneById($id);
  922.         
  923.         // Increment counter
  924.         $download->setCounter($download->getCounter() + 1);
  925.         $em->flush();
  926.         
  927.         return $this->redirect($download->getUrl());
  928.     }
  929.     
  930.     /**
  931.      * @Route(
  932.      *      "/rss/",
  933.      *      name="GhFrontBundle_Page_rss"
  934.      * )
  935.      * @Template()
  936.      */
  937.     public function rssAction()
  938.     {
  939.         TitleClass::getInstance()->setTitle('Les flux RSS de GameHope');
  940.         
  941.         $breadcrumb BreadcrumbClass::getInstance();
  942.         $breadcrumb->addPath('Flux RSS');
  943.         
  944.         return array();
  945.     }
  946.     
  947.     /**
  948.      * @Route(
  949.      *      "/in.html",
  950.      *      name="GhFrontBundle_Page_inPartner"
  951.      * )
  952.      */
  953.     public function inPartnerAction()
  954.     {
  955.         return $this->redirect(
  956.             $this->generateUrl(
  957.                 'GhFrontBundle_Page_homepage',
  958.                 array()
  959.             ), 
  960.             301
  961.         );
  962.     }
  963.     
  964.     /**
  965.      * Generate a "Previous page" link in picture viewer.
  966.      * When user navigates between pictures, the previous page is not changed.
  967.      * If the previous page is not a picture, it is cleared.
  968.      * @param string $sessionKey A key to identify the pictures series (picture viewer, WYSIWYG, etc.).
  969.      * @param function $func A callback function which takes a parameter the URL to test, 
  970.      *      and returns a boolean whether the link is in the same "workflow".
  971.      * @return string Previous page link.
  972.      */
  973.     private function generatePreviousPageLink($sessionKey$func) {
  974.         $previousPage '';
  975.         $session $this->getRequest()->getSession();
  976.         $referer $this->getRequest()->headers->get('referer');
  977.         if (!$func($referer)) {
  978.             $previousPage $referer;
  979.             $session->set($sessionKey$previousPage);
  980.         } else {
  981.             $previousPage $session->get($sessionKey);
  982.         }
  983.         
  984.         return $previousPage;
  985.     }
  986.     
  987.     /**
  988.      * @Route(
  989.      *      "/opensearch.xml",
  990.      *      name="GhFrontBundle_Page_opensearch", 
  991.      *      defaults={"_format"="xml"}
  992.      * )
  993.      * @Template()
  994.      */
  995.     public function opensearchAction()
  996.     {
  997.         return array();
  998.     }
  999. }