<?php
namespace Gh\FrontBundle\Controller;
use DateTime;
use Exception;
use Gh\DatabaseBundle\Classes\SearchClass;
use Gh\DatabaseBundle\Entity\GhCard;
use Gh\FrontBundle\Classes\BreadcrumbClass;
use Gh\FrontBundle\Classes\Helpers\PaginatorHelper;
use Gh\FrontBundle\Classes\Helpers\PictureHelper;
use Gh\FrontBundle\Classes\InternalClass;
use Gh\FrontBundle\Classes\ListValues\ConsoleClass;
use Gh\FrontBundle\Classes\ListValues\SectionTypeClass;
use Gh\FrontBundle\Classes\MenuActiveClass;
use Gh\CommonBundle\Classes\Meta\MetaClass;
use Gh\FrontBundle\Classes\Sidebar\SidebarClass;
use Gh\FrontBundle\Classes\Sidebar\SidebarNews;
use Gh\FrontBundle\Classes\Sidebar\SidebarReviews;
use Gh\FrontBundle\Classes\TitleClass;
use Gh\FrontBundle\Classes\UtilClass;
use Gh\FrontBundle\Controller\GhController;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Swift_Message;
class PageController extends GhController
{
/**
* @Route(
* "/",
* name="GhFrontBundle_Page_homepage"
* )
* @Template()
*/
public function homepageAction()
{
return $this->homepageDefaultAction('tout');
}
/**
* @Route(
* "/{console}/",
* name="GhFrontBundle_Page_homepageDefault",
* requirements={"console" = "(3ds|pc|ps3|ps4|ps5|psv|wiiu|x360|xone|xonex|xseriesx|ios|android|web|switch|stadia)"}
* )
* @Template("@GhFront/page/homepage.html.twig")
*/
public function homepageDefaultAction($console)
{
ini_set('memory_limit', '256M');
$em = $this->getDoctrine()->getManager();
// Convert $console param into console code
if ($console != 'tout') {
$console = ConsoleClass::getInstance()->getCodeFromShort($console);
}
$consoleShort = strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('homepage');
// Generate title
if ($console != 'tout') {
TitleClass::getInstance()->setTitle('GameHope.com : Actualité du jeu vidéo sur '.ConsoleClass::getInstance()->getLongFromCode($console));
}
// Retrieve list of consoles
$consolesList = ConsoleClass::getInstance()->getCodes(true, false);
// Get the latest news
$newsList = $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
$console,
$this->container->getParameter('home_limit_news_headline'),
true
);
// Get the latest movies
$moviesList = $em->getRepository('GhDatabaseBundle:GhMovie')->getListArticlesTableContents(
$this->container,
($console == 'tout' ? '' : $console),
'',
'',
0,
$this->container->getParameter('home_limit_latest_movies'),
false,
true
);
// Get the latest articles
$latestArticles = $em->getRepository('GhDatabaseBundle:FakeArticle')->getLatestArticlesForHome(
($console == 'tout' ? '' : $console),
true,
$this->container->getParameter('home_limit_latest_articles')
);
// Retrieve entity associated to the article
foreach ($latestArticles as &$article) {
switch ($article->getSection()) {
case 'dossier':
$dossier = $em->getRepository('GhDatabaseBundle:GhDossier')->findOneById($article->getArticleId());
$article->setExtrafield($dossier);
break;
case 'preview':
$preview = $em->getRepository('GhDatabaseBundle:GhPreview')->findOneById($article->getArticleId());
$article->setExtrafield($preview);
break;
}
}
// Retrieve headlines
$headlinesNb = $this->container->getParameter('home_limit_headlines');
$headlinesList = $em->getRepository('GhDatabaseBundle:GhHomeHeadline')->getHeadlineByConsole($console, $headlinesNb);
// Sidebar "News"
$nbNewsPerPage = $this->container->getParameter('home_limit_news_sidebar_per_page');
$newsListSidebar = $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
$console,
$nbNewsPerPage,
false,
null,
null,
false
);
// Sidebar "Last reviews"
$latestReviews = $em->getRepository('GhDatabaseBundle:FakeArticle')->getLatestReviewsForHome(
($console == 'tout' ? '' : $console),
true,
$this->container->getParameter('home_limit_latest_reviews')
);
// Latest hints
$nbHintsPerPage = $this->container->getParameter('home_limit_news_sidebar_per_page');
$hintsListSidebar = $em->getRepository('GhDatabaseBundle:GhHint')->getHintsListByConsole(
$console,
$nbHintsPerPage
);
// Push the sidebars
SidebarClass::getInstance()->push('news', new SidebarNews($newsList), '-1');
return array(
'console' => $consoleShort,
'consolesList' => $consolesList,
'newsList' => $newsList,
'moviesList' => $moviesList,
'latestArticles' => $latestArticles,
'headlinesList' => $headlinesList,
'latestReviews' => $latestReviews,
'latestNews' => $newsListSidebar,
'latestHints' => $hintsListSidebar
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/image_{pictureId}.html",
* name="GhFrontBundle_Page_picture",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "pictureId" = "([0-9]+)"}
* )
* @Template()
*/
public function pictureAction($console, $cardId, $slug, $pictureId)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->findOneById($cardId);
if ($card === null) {
// Throw a 404 error if no card found
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Get the picture
$picture = $em->getRepository('GhDatabaseBundle:GhGallery')->findOneById($pictureId);
if ($picture === null) {
// Throw a 404 error if no card found
throw $this->createNotFoundException('Aucune image n\'a été trouvée');
}
// Get the thumbs list to be displayed on the top of the screen
$thumbsList = $em->getRepository('GhDatabaseBundle:GhGallery')->getThumbsList(
$card,
$pictureId,
$this->container->getParameter('gallery_thumbs_limit')
);
// Previous/next buttons
$currentIndex = UtilClass::findIndexInList($picture, $thumbsList, 'getId');
if ($currentIndex > 0) {
$previousThumb = $thumbsList[$currentIndex - 1];
} else {
$previousThumb = null;
}
// Next button
if ($currentIndex < count($thumbsList) - 1) {
$nextThumb = $thumbsList[$currentIndex + 1];
} else {
$nextThumb = null;
}
// "Previous page" button
$previousPage = $this->generatePreviousPageLink('GhFrontBundle_Page_picture_previousPage', function($url) {
return InternalClass::isUrlPictureViewer($url);
});
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : la galerie d\'images');
// Generate breadcrumb
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath(ConsoleClass::getInstance()->getLongFromCode($card->getConsole()), $this->get('router'), 'GhFrontBundle_Page_homepageDefault', array('console' => ConsoleClass::getInstance()->getShortFromCode($card->getConsole())));
$breadcrumb->addPath($card->getTitle(), $this->get('router'), 'GhFrontBundle_Card_card', array('card' => $card));
$breadcrumb->addPath('Galerie', $this->get('router'), 'GhFrontBundle_Card_galleryDefault', array('card' => $card));
$breadcrumb->addPath('Image');
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$description = 'Galerie d\'images du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : screenshots, captures d\'écran, artworks, wallpapers.';
$meta->addMeta('description', $description);
$meta->addMeta('og:description', $description);
$meta->addMeta('og:image', $this->container->getParameter('base_url_absolute').PictureHelper::displayGalleryThumb($this->container, $picture));
// Generate canonical URL
$this->updateCanonicalUrl($card, array('pictureId' => $pictureId));
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('gallery');
return array(
'card' => $card,
'picture' => $picture,
'thumbsList' => $thumbsList,
'currentIndex' => $currentIndex,
'previousThumb' => $previousThumb,
'nextThumb' => $nextThumb,
'previousPage' => $previousPage
);
}
/**
* @Route(
* "/images/{id}-{slug}.html",
* name="GhFrontBundle_Page_pictureWysiwyg",
* requirements={"id" = "([0-9a-zA-Z_-]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function pictureWysiwygAction($id, $slug)
{
// Retrieve entity
$em = $this->getDoctrine()->getManager();
$picture = $em->getRepository('GhDatabaseBundle:GhPictureWysiwyg')->findOneById($id);
if ($picture === null) {
// Throw a 404 error if no card found
throw $this->createNotFoundException('Aucune image n\'a été trouvée');
}
// Generate canonical URL
$this->updateCanonicalUrl(NULL, array('id' => $picture->getId(), 'slug' => $picture->getSlug()));
// "Previous page" button
$previousPage = $this->generatePreviousPageLink('GhFrontBundle_Page_pictureWysiwyg_previousPage', function($url) {
return InternalClass::isUrlPictureWysiwygViewer($url);
});
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath($picture->getDescription());
TitleClass::getInstance()->setTitle($picture->getDescription().' - Image');
// Generate meta
$meta = MetaClass::getInstance();
$description = 'Image de jeu vidéo : '.$picture->getDescription().'... et bien plus encore sur GameHope.com !';
$meta->addMeta('description', $description);
$meta->addMeta('og:description', $description);
$meta->addMeta('og:image', $this->container->getParameter('base_url_absolute').$picture->getLowpath());
return array(
'picture' => $picture,
'previousPage' => $previousPage
);
}
/**
* @Route(
* "/actu/{year}/{month}/{day}/",
* name="GhFrontBundle_Page_daily",
* requirements={"year" = "([0-9]{4})", "month" = "([0-9]{2})", "day" = "([0-9]{2})"}
* )
* @Template()
*/
public function dailyAction($year, $month, $day)
{
$em = $this->getDoctrine()->getManager();
setlocale(LC_ALL,'fr_FR.UTF-8', 'French');
// Find current week (set hour to 5.00 AM to be sure to avoid ambiguity due to timezone)
$currentDate = new DateTime($year.'-'.$month.'-'.$day);
$currentDate->setTime(5, 0, 0);
$currentDateBegin = UtilClass::getDateWeekBegin($currentDate);
$currentDateEnd = UtilClass::getDateWeekEnd($currentDate);
// Compute all the days of the selected week
$currentDateList = array();
for ($i = 0; $i < 7; $i++) {
$currentDateList[$i] = new DateTime('@'.$currentDateBegin->getTimestamp());
$currentDateList[$i]->modify('+'.$i.' days');
}
// Find previous week
$previousWeekDateBegin = null;
$previousWeekDateEnd = null;
// Set a limit to 1999 to avoid infinite pages
if ($currentDate->format('Y') >= 1999) {
$previousDate = new DateTime('@'.$currentDate->getTimestamp());
$previousDate->modify('-1 weeks');
$previousWeekDateBegin = UtilClass::getDateWeekBegin($previousDate);
$previousWeekDateEnd = UtilClass::getDateWeekEnd($previousDate);
}
// Find next week
$nextDate = new DateTime('@'.$currentDate->getTimestamp());
$nextDate->modify('+1 weeks');
$nextWeekDateBegin = UtilClass::getDateWeekBegin($nextDate);
$nextWeekDateEnd = UtilClass::getDateWeekEnd($nextDate);
// Set a limit to the current day date
if ($nextWeekDateBegin->getTimestamp() > time()) {
$nextWeekDateBegin = null;
$nextWeekDateEnd = null;
}
// Generate title
$title = UtilClass::generateDailyTitlePage($currentDateBegin, $currentDateEnd);
TitleClass::getInstance()->setTitle($title);
// Generate breadcrumb
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Actualité', $this->get('router'), 'GhFrontBundle_Page_dailyDefault');
$breadcrumb->addPath($title);
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('daily');
// Retrieve articles: reviews, previews, dossiers
$reviewsList = $em->getRepository('GhDatabaseBundle:GhReview')->getListArticlesTableContents(
$this->container, '', '', '', 0, 0, false, true, $currentDate
);
$previewsList = $em->getRepository('GhDatabaseBundle:GhPreview')->getListArticlesTableContents(
$this->container, '', '', '', 0, 0, false, true, $currentDate
);
$dossiersList = $em->getRepository('GhDatabaseBundle:GhDossier')->getListArticlesTableContents(
$this->container, '', '', '', 0, 0, false, true, $currentDate
);
$geeksList = $em->getRepository('GhDatabaseBundle:GhGeek')->getListArticlesTableContents(
$this->container, '', '', '', 0, 0, false, true, $currentDate
);
$articlesList = array_merge($reviewsList, $previewsList, $dossiersList, $geeksList);
// Retrieve news
$newsList = $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByConsole(
'tout', 0, false, null, $currentDate
);
// Retrieve movies
$moviesList = $em->getRepository('GhDatabaseBundle:GhMovie')->getListArticlesTableContents(
$this->container, '', '', '', 0, 0, false, true, $currentDate
);
// Get the cards of day
$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),
$year,
$month,
$day);
return array(
'currentDate' => $currentDate,
'currentDateList' => $currentDateList,
'currentDateBegin' => $currentDateBegin,
'currentDateEnd' => $currentDateEnd,
'previousWeekDateBegin' => $previousWeekDateBegin,
'previousWeekDateEnd' => $previousWeekDateEnd,
'nextWeekDateBegin' => $nextWeekDateBegin,
'nextWeekDateEnd' => $nextWeekDateEnd,
'articlesList' => $articlesList,
'newsList' => $newsList,
'moviesList' => $moviesList,
'cardsList' => $cardsList
);
}
/**
* @Route(
* "/actu/",
* name="GhFrontBundle_Page_dailyDefault"
* )
*/
public function dailyDefaultAction()
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Page_daily',
array("year" => date('Y'), "month" => date('m'), "day" => date('d'))
));
}
/**
* @Route(
* "/{console}/calendrier/{year}/{month}/",
* name="GhFrontBundle_Page_calendar",
* requirements={"console" = "([0-9a-zA-Z]+)", "year" = "([0-9]{4})", "month" = "([0-9]{1,2})"}
* )
* @Template()
*/
public function calendarAction($console, $year, $month)
{
$request = $this->getRequest();
if($request->request->get('submitPeriod')) {
return $this->redirect($this->generateUrl('GhFrontBundle_Page_calendar', array('console' => $console, 'year' => $request->request->get('year'), 'month' => str_pad($request->request->get('month'), 2, 0, STR_PAD_LEFT))));
}
$consoleLong = ConsoleClass::getInstance()->getLongFromCode($console);
$consoleShort = strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
MenuActiveClass::getInstance()->setMenuActive('calendar');
$currentCalendarPeriod = mktime(5, 0, 0, $month, 1, $year);
$moisAnnee = UtilClass::getFrenchDate($currentCalendarPeriod, "%B %Y");
$relatif = "de ";
if(in_array(substr($moisAnnee, 0, 1), array("a","e","i","o","u","y"))) {
$relatif = "d'";
}
$titlePage = 'Les sorties de jeux vidéo '.$relatif.$moisAnnee;
$metaDescription = "Retrouvez toutes les sorties de jeux vidéo du mois ".$relatif.$moisAnnee;
// Generate breadcrumb
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Sorties', $this->get('router'), 'GhFrontBundle_Page_calendarConsole', array('console' => 'tout'));
if($console != "tout") {
$breadcrumb->addPath($consoleLong, $this->get('router'), 'GhFrontBundle_Page_calendarConsole', array('console' => $consoleShort));
$titlePage .= " sur $consoleLong";
$metaDescription .= " sur $consoleLong";
}
$breadcrumb->addPath(ucfirst($moisAnnee));
TitleClass::getInstance()->setTitle($titlePage);
MetaClass::getInstance()->addMeta('description', $metaDescription);
$em = $this->getDoctrine()->getManager();
return array(
'console' => $consoleShort,
'currentCalendarPeriod' => $currentCalendarPeriod,
'previousDate' => strtotime("-1 month", $currentCalendarPeriod),
'nextDate' => strtotime("+1 month", $currentCalendarPeriod),
'consolesList' => ConsoleClass::getInstance()->getCodes(true, false, false),
'unmissableCards' => $em->getRepository('GhDatabaseBundle:GhCard')->searchListCards($this->container, array("counter" => "desc"), array("c.title"), array('type' => GhCard::CARD_TYPE_GAME, 'console' => $console), $year, $month, NULL, array(0,$this->container->getParameter('calendar_unmissable_limit'))),
'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));
}
/**
* @Route(
* "/{console}/calendrier/",
* name="GhFrontBundle_Page_calendarConsole",
* requirements={"console" = "([0-9a-zA-Z]+)"}
* )
* @Template()
*/
public function calendarConsoleAction($console)
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Page_calendar',
array("console" => $console, "year" => date('Y'), "month" => date('m'))
));
}
/**
* @Route(
* "/{console}/top/{source}.html",
* name="GhFrontBundle_Page_chart",
* requirements={"console" = "([0-9a-zA-Z]+)", "source" = "(tout|gamehope|lecteurs)"}
* )
* @Template()
*/
public function chartAction($console, $source)
{
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$filters = array('type' => GhCard::CARD_TYPE_GAME);
$consoleLong = ConsoleClass::getInstance()->getLongFromCode($console);
$consoleShort = strtolower(ConsoleClass::getInstance()->getShortFromCode($console));
MenuActiveClass::getInstance()->setMenuActive('chart');
$listeSources = SectionTypeClass::getInstance()->getListBySection('chartSources');
$listeCategories = SectionTypeClass::getInstance()->getListBySection('cardCategory');
$titlePage = 'Top jeux vidéo ';
$metaDescription = 'Retrouvez le top (classement, charts) des jeux vidéo ';
// Generate breadcrumb and meta
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Tops', $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => 'tout', 'source' => GhCard::CARD_SOURCE_ALL));
$metaDescription .= SectionTypeClass::getInstance()->getLabelById('chartSources', $source);
if($source != GhCard::CARD_SOURCE_ALL) {
$breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('chartSources', $source), $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => 'tout', 'source' => $source));
}
if($console != "tout") {
$breadcrumb->addPath($consoleLong, $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => $consoleShort, 'source' => $source));
$titlePage .= " sur $consoleLong";
$metaDescription .= " sur $consoleLong";
$filters['console'] = $console;
} else {
$titlePage .= " sur tous supports";
$metaDescription .= " sur tous supports";
}
$titlePage .= ' - '.SectionTypeClass::getInstance()->getLabelById('chartSources', $source);
// If a category is set, add extra information in title and breadcrumb
$category = null;
if($request->query->get('cat')) {
$category = $request->query->get('cat');
$filters['category'] = $category;
$breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('cardCategory', $category), $this->get('router'), 'GhFrontBundle_Page_chart', array('console' => $consoleShort, 'source' => $source), '?cat='.$category);
$titlePage .= ' - '.SectionTypeClass::getInstance()->getLabelById('cardCategory', $category);
}
// Set title and meta
TitleClass::getInstance()->setTitle($titlePage);
MetaClass::getInstance()->addMeta('description', $metaDescription);
// Get chart
$cardsList = $em->getRepository('GhDatabaseBundle:GhCard')->getTopScoreFrom(
$this->container,
$source,
$filters,
array(new DateTime($this->container->getParameter('card_chart_max_age')), new DateTime('now')),
array(0,10)
);
return array(
'console' => $consoleShort,
'source' => $source,
'category' => $category,
'sources' => $listeSources,
'consoles' => ConsoleClass::getInstance()->getCodes(true, true, false),
'categories' => $listeCategories,
'cardsList' => $cardsList);
}
/**
* @Route(
* "/{console}/top/",
* name="GhFrontBundle_Page_chartDefault",
* requirements={"console" = "([0-9a-zA-Z]+)"}
* )
* @Template()
*/
public function chartDefaultAction($console)
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Page_chart',
array("console" => $console, "source" => "gamehope")
), 301);
}
/**
* @Route(
* "/presse/{pressId}-{slug}/page-{page}.html",
* name="GhFrontBundle_Page_press",
* requirements={"pressId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "page" = "([0-9]+)"}
* )
* @Template()
*/
public function pressAction($pressId, $slug, $page)
{
$em = $this->getDoctrine()->getManager();
// Get the magazine
$press = $em->getRepository('GhDatabaseBundle:GhPress')->findOneById($pressId);
// Compute pagination
$paginator = new PaginatorHelper($em->getRepository('GhDatabaseBundle:GhPressReview')->countPressReviewByPressId($pressId), $page, $this->container->getParameter('press_reviews_per_page'));
$paginator->setSfLinkedController($this);
$paginator->setRouter($this->get('router'));
$paginator->setSfUrlParameters(array('pressId' => $press->getId(), 'slug' => $press->getSlug()));
$paginator->setPageParameterName('page');
$paginator->setPaginationStep($this->container->getParameter('press_reviews_pagination_step'));
// Get the list of news
$associatedPressReviews = $em->getRepository('GhDatabaseBundle:GhPressReview')->getPressReviewsByPressId($pressId, $paginator->getOffset(), $paginator->getLimit());
// Generate breadcrumb and meta
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath($press->getTitle(), $this->get('router'), 'GhFrontBundle_Page_pressDefault', array('pressId' => $press->getId(), 'slug' => $press->getSlug()));
if ($page != 1) {
$breadcrumb->addPath('Page '.$page);
}
// Set title and meta
TitleClass::getInstance()->setTitle($press->getTitle().' : Revue de presse sur GameHope.com');
// Generate canonical URL
$canonicalUrl = $this->get('router')->generate(
$this->getRequest()->get('_route'),
array('pressId' => $press->getId(), 'slug' => $press->getSlug(), 'page' => $page),
UrlGeneratorInterface::ABSOLUTE_URL
);
$meta = MetaClass::getInstance();
$meta->addLink('canonical', $canonicalUrl);
return array(
'press' => $press,
'associatedPressReviews' => $associatedPressReviews,
'paginator' => $paginator
);
}
/**
* @Route(
* "/presse/{pressId}-{slug}/",
* name="GhFrontBundle_Page_pressDefault",
* requirements={"pressId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
*/
public function pressDefaultAction($pressId, $slug)
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Page_press',
array("pressId" => $pressId, "slug" => $slug, "page" => 1)
), 301);
}
/**
* @Route(
* "/recherche.html",
* name="GhFrontBundle_Page_search"
* )
* @Template()
*/
public function searchAction()
{
$request = $this->getRequest();
$search = $request->query->get('queljeu');
$selectedConsole = $request->query->get('console');
// Get the search result
$em = $this->getDoctrine()->getManager();
$limit = $this->container->getParameter('search_limit');
$cardsList = $em->getRepository('GhDatabaseBundle:GhCard')->search($search, $selectedConsole, $limit, false);
// When only 1 card is matched, forward to the card page
if (count($cardsList) == 1) {
$routerParams = UtilClass::getRouteParamsFromCard(array_pop($cardsList));
return $this->redirect($this->generateUrl('GhFrontBundle_Card_card', $routerParams));
}
// Extract list of consoles where results are found
$consolesFound = SearchClass::getConsolesList($cardsList);
// Generate breadcrumb, title
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Rechercher '.$search);
TitleClass::getInstance()->setTitle($search.' jeu vidéo');
return array(
'cardsList' => $cardsList,
'search' => $search,
'selectedConsole' => $selectedConsole,
'consolesList' => ConsoleClass::getInstance()->getCodes(false, false, true),
'consolesFound' => $consolesFound
);
}
/**
* @Route(
* "/team/",
* name="GhFrontBundle_Page_team"
* )
* @Template()
*/
public function teamAction()
{
TitleClass::getInstance()->setTitle('La team');
MetaClass::getInstance()->addMeta('description', 'Retrouvez ici toute l\'équipe de GameHope');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Team');
$em = $this->getDoctrine()->getManager();
$team = $em->getRepository('GhDatabaseBundle:GhTeam')->getTeamOrderedByOrder();
return array(
'team' => $team
);
}
/**
* @Route(
* "/apropos.html",
* name="GhFrontBundle_Page_about"
* )
* @Template()
*/
public function aboutAction()
{
TitleClass::getInstance()->setTitle('A propos');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('A propos');
$em = $this->getDoctrine()->getManager();
$numbers = array(
'number_card' => $em->getRepository('GhDatabaseBundle:GhCard')->count(),
'number_gallery' => $em->getRepository('GhDatabaseBundle:GhGallery')->count(),
'number_review' => $em->getRepository('GhDatabaseBundle:GhReview')->count(),
'number_preview' => $em->getRepository('GhDatabaseBundle:GhPreview')->count(),
'number_hint' => $em->getRepository('GhDatabaseBundle:GhHint')->count(),
'number_download' => $em->getRepository('GhDatabaseBundle:GhDownload')->count(),
'number_movie' => $em->getRepository('GhDatabaseBundle:GhMovie')->count(),
'number_news' => $em->getRepository('GhDatabaseBundle:GhNews')->count(),
'number_press_review' => $em->getRepository('GhDatabaseBundle:GhPressReview')->count()
);
return array(
'numbers' => $numbers
);
}
/**
* @Route(
* "/recrutement.html",
* name="GhFrontBundle_Page_hiring"
* )
* @Template()
*/
public function hiringAction()
{
TitleClass::getInstance()->setTitle('GameHope recrute !');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Recrutement');
return array();
}
/**
* @Route(
* "/notation.html",
* name="GhFrontBundle_Page_notation"
* )
* @Template()
*/
public function notationAction()
{
TitleClass::getInstance()->setTitle('La notation de GameHope');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('La notation de GameHope');
return array();
}
/**
* @Route(
* "/hasard.html",
* name="GhFrontBundle_Page_random"
* )
*/
public function randomAction()
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getOneByRand();
if($card)
{
$routerParams = UtilClass::getRouteParamsFromCard($card);
return $this->redirect($this->generateUrl('GhFrontBundle_Card_card', $routerParams), 302);
}
return $this->redirect($this->generateUrl('GhFrontBundle_Page_homepage', 302));
}
/**
* @Route(
* "/contact/",
* name="GhFrontBundle_Page_contactAuthor"
* )
* @Template("@GhFront/page/contact.html.twig")
*/
public function contactAuthorAction()
{
$author = $this->getRequest()->query->get('author');
TitleClass::getInstance()->setTitle('Formulaire de contact');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Contact');
$em = $this->getDoctrine()->getManager();
if ($author != '') {
$author = $em->getRepository('GhDatabaseBundle:GhTeam')->findOneByName($author);
}
if($author == NULL || $author == '')
{
$author = $em->getRepository('GhDatabaseBundle:GhTeam')->findOneByName('Monsieur Tomate');
}
$authors = $em->getRepository('GhDatabaseBundle:GhTeam')->getTeamOrderedByOrder();
return array(
'author' => $author,
'team' => $authors
);
}
/**
* @Route(
* "/contactValidation.html",
* name="GhFrontBundle_Page_checkContactForm"
* )
*/
public function checkContactFormAction()
{
$request = $this->getRequest();
$recipient = $request->request->get('recipient', '');
$name = $request->request->get('name', '');
$email = $request->request->get('email', '');
$subject = $request->request->get('subject', '');
$message = $request->request->get('message', '');
$captcha = strtolower(trim($request->request->get('check', '')));
$validForm = TRUE;
$toEmail = '';
switch($recipient)
{
case 'partenariat' :
case 'publicite' :
case 'tech' :
$toEmail = 'tomate@gamehope.com';
break;
case 'presse' :
$toEmail = 'joker@gamehope.com';
break;
case 'recrutement' :
$toEmail = 'recrutement@gamehope.com';
break;
case 'webmaster' :
$toEmail = 'webmaster@gamehope.com';
break;
}
if($toEmail == '')
{
$em = $this->getDoctrine()->getManager();
$member = $em->getRepository('GhDatabaseBundle:GhTeam')->findOneById($recipient);
if($member != NULL)
{
$toEmail = $member->getEmail();
}
}
if($toEmail == '')
{
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'Le destinataire est invalide.'));
}
if(trim($name) == '')
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'Le nom est obligatoire.'));
}
if(trim($email) == '')
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'L\'email est obligatoire.'));
}
else if(!preg_match("#^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$#", $email))
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'L\'email est invalide.'));
}
if(trim($subject) == '')
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'Le sujet est obligatoire.'));
}
if(trim($message) == '')
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'Le message est obligatoire.'));
}
if($captcha != 'blanc' && $captcha != 'blanche')
{
$validForm = FALSE;
$this->get('session')->getFlashBag()->add('error', array('title' => 'Contact', 'content' => 'La question de sécurité n\'est pas correctement renseignée.'));
}
if($validForm)
{
try
{
$content = Swift_Message::newInstance()
->setSubject($subject)
->setFrom(array($email => $name))
->setTo($toEmail)
->setBody($message);
if ($this->get('mailer')->send($content)) {
$this->get('session')->getFlashBag()->add('success', array('title' => 'Contact', 'content' => 'Votre message a été envoyé avec succès !'));
} else {
$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'));
}
}
catch(Exception $e)
{
$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'));
}
}
return $this->redirect($request->headers->get('referer'));
}
/**
* @Route(
* "/down.html",
* name="GhFrontBundle_Page_download"
* )
*/
public function doDownloadAction()
{
$id = $this->getRequest()->query->get('id');
// Get download
$em = $this->getDoctrine()->getManager();
$download = $em->getRepository('GhDatabaseBundle:GhDownload')->findOneById($id);
// Increment counter
$download->setCounter($download->getCounter() + 1);
$em->flush();
return $this->redirect($download->getUrl());
}
/**
* @Route(
* "/rss/",
* name="GhFrontBundle_Page_rss"
* )
* @Template()
*/
public function rssAction()
{
TitleClass::getInstance()->setTitle('Les flux RSS de GameHope');
$breadcrumb = BreadcrumbClass::getInstance();
$breadcrumb->addPath('Flux RSS');
return array();
}
/**
* @Route(
* "/in.html",
* name="GhFrontBundle_Page_inPartner"
* )
*/
public function inPartnerAction()
{
return $this->redirect(
$this->generateUrl(
'GhFrontBundle_Page_homepage',
array()
),
301
);
}
/**
* Generate a "Previous page" link in picture viewer.
* When user navigates between pictures, the previous page is not changed.
* If the previous page is not a picture, it is cleared.
* @param string $sessionKey A key to identify the pictures series (picture viewer, WYSIWYG, etc.).
* @param function $func A callback function which takes a parameter the URL to test,
* and returns a boolean whether the link is in the same "workflow".
* @return string Previous page link.
*/
private function generatePreviousPageLink($sessionKey, $func) {
$previousPage = '';
$session = $this->getRequest()->getSession();
$referer = $this->getRequest()->headers->get('referer');
if (!$func($referer)) {
$previousPage = $referer;
$session->set($sessionKey, $previousPage);
} else {
$previousPage = $session->get($sessionKey);
}
return $previousPage;
}
/**
* @Route(
* "/opensearch.xml",
* name="GhFrontBundle_Page_opensearch",
* defaults={"_format"="xml"}
* )
* @Template()
*/
public function opensearchAction()
{
return array();
}
}