<?php
namespace Gh\FrontBundle\Controller;
use Gh\FrontBundle\Classes\Sidebar\SidebarAuthor;
use Gh\FrontBundle\Classes\Sidebar\SidebarBuy;
use Gh\FrontBundle\Classes\Sidebar\SidebarCard;
use Gh\FrontBundle\Controller\GhController,
Symfony\Component\Routing\Annotation\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template,
Symfony\Component\HttpFoundation\RedirectResponse,
Gh\DatabaseBundle\Entity\GhCard,
Gh\DatabaseBundle\Entity\GhDownload,
Gh\DatabaseBundle\Entity\GhNews,
Gh\FrontBundle\Classes\TitleClass,
Gh\CommonBundle\Classes\Meta\MetaClass,
Gh\FrontBundle\Classes\BreadcrumbClass,
Gh\FrontBundle\Classes\UtilClass,
Gh\FrontBundle\Classes\InternalClass,
Gh\FrontBundle\Classes\ShopClass,
Gh\FrontBundle\Classes\MenuActiveClass,
Gh\FrontBundle\Classes\ListValues\ConsoleClass,
Gh\FrontBundle\Classes\ListValues\SectionTypeClass,
Gh\FrontBundle\Classes\ListValues\WorkflowStateClass,
Gh\FrontBundle\Classes\Helpers\PaginatorHelper,
Gh\FrontBundle\Classes\Helpers\MovieHelper,
Gh\FrontBundle\Classes\Sidebar\SidebarClass,
Gh\FrontBundle\Classes\Sidebar\SidebarSimilarCards;
class CardController extends GhController
{
const ARTICLE_TYPE_REVIEW = 'review';
const ARTICLE_TYPE_PREVIEW = 'preview';
/**
* This component manages the card layout header.
* @Template()
* @param GhCard $card
* @param string $route
* @return array
*/
public function dynamicCardLayoutHeaderAction($card, $route)
{
// Get the also available consoles (the current card is at first position)
$em = $this->getDoctrine()->getManager();
$alsoAvailableCards = $em->getRepository('GhDatabaseBundle:GhCard')->getAlsoAvailableCards($card, true);
array_unshift($alsoAvailableCards, $card);
// Get the shop links
$shopLinks = array(
'amazon' => ShopClass::getAmazonLink($card),
'priceminister' => ShopClass::getPriceMinisterLink($card),
'ebay' => ShopClass::getEbayLink($card),
'boulanger' => ShopClass::getBoulangerLink($card)
);
// Get review
$cardReviews = $em->getRepository('GhDatabaseBundle:GhReview')->getReviewsByCardId($card->getId());
if ($cardReviews != null) {
$cardReview = $cardReviews[0];
} else {
$cardReview = null;
}
// Increment view counters (total and daily)
$card->setCounter($card->getCounter() + 1);
$card->setCounterdaily($card->getCounterdaily() + 1);
$em->flush();
// Push the block Similar games
// GH-78 : do not display similar cards for companies and material
if(!in_array($card->getType(), array(GhCard::CARD_TYPE_COMPANY, GhCard::CARD_TYPE_MATERIAL))) {
SidebarClass::getInstance()->push('similarCards', new SidebarSimilarCards($card), -1);
}
// Push the Buy sidebar
SidebarClass::getInstance()->push('buy', new SidebarBuy($card, $shopLinks), -1);
// Push the About card sidebar
SidebarClass::getInstance()->push('card', new SidebarCard($alsoAvailableCards), -1);
return array(
'card' => $card,
'alsoAvailableCards' => $alsoAvailableCards,
'review' => $cardReview,
'route' => $route
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/",
* name="GhFrontBundle_Card_card",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function cardAction($console, $cardId, $slug)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
if ($card === null) {
// Throw a 404 error if no card found
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole());
// 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());
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$description = '';
// Depending on card type, generate an appropriated description
switch ($card->getType()) {
case GhCard::CARD_TYPE_GAME:
$description = 'Toutes les dernières infos sur le jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : tests, previews, news, reportages, vidéos, astuces, téléchargements.';
break;
case GhCard::CARD_TYPE_EVENT:
$description = 'Toutes les dernières infos sur l\'événement '.$card->getTitle().' sur GameHope : news, reportages, vidéos, premières impressions.';
break;
case GhCard::CARD_TYPE_COMPANY:
$description = 'Toutes les dernières infos sur la société '.$card->getTitle().' sur GameHope : tests, previews, news, news, reportages, vidéos.';
break;
case GhCard::CARD_TYPE_MATERIAL:
$description = 'Toutes les dernières infos sur l\'accessoire '.$card->getTitle().' sur GameHope : tests, previews, news, news, reportages, vidéos.';
break;
}
$meta->addMeta('description', $description);
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole());
// Generate canonical URL
$this->updateCanonicalUrl($card);
// Get data for block "Gallery"
$latestPictures = $em->getRepository('GhDatabaseBundle:GhGallery')->getGalleryByCardId(
$cardId,
0,
$this->container->getParameter('card_limit_show_images_block_gallery')
);
// Get data for block "Fil d'actualité"
$latestArticles = $em->getRepository('GhDatabaseBundle:FakeArticle')->getLatestArticlesForCard($cardId, $this->container);
// Get data for blocks "Review", "Preview", "Dossier"
$cardReviews = $em->getRepository('GhDatabaseBundle:GhReview')->getReviewsByCardId($cardId);
$cardPreviews = $em->getRepository('GhDatabaseBundle:GhPreview')->getPreviewsByCardId($cardId);
$cardDossiers = $em->getRepository('GhDatabaseBundle:GhDossier')->getDossiersByCardId($cardId);
// Get data for block "Opinion"
$cardOpinions = $em->getRepository('GhDatabaseBundle:GhNews')->getNewsListByCardIdAndSubsectionId($cardId, GhNews::NEWS_TYPE_OPINION);
// Get data for published/developed games (company only)
$publishedGames = null;
$developedGames = null;
if ($card->getType() == GhCard::CARD_TYPE_COMPANY) {
$publishedGames = $em->getRepository('GhDatabaseBundle:GhCard')->getPublishedOrDevelopedCards(
$card,
GhCard::CARD_COMPANY_PUBLISHER,
0,
$this->container->getParameter('card_company_published_max_list')
);
$developedGames = $em->getRepository('GhDatabaseBundle:GhCard')->getPublishedOrDevelopedCards(
$card,
GhCard::CARD_COMPANY_DEVELOPER,
0,
$this->container->getParameter('card_company_published_max_list')
);
}
// Get data for compatible games (material only)
$compatibleGames = null;
if ($card->getType() == GhCard::CARD_TYPE_MATERIAL) {
$compatibleGames = $em->getRepository('GhDatabaseBundle:GhCardMaterial')->getCompatibleCards(
$card
);
}
return array(
'card' => $card,
'latestArticles' => $latestArticles,
'latestPictures' => $latestPictures,
'cardReviews' => $cardReviews,
'cardPreviews' => $cardPreviews,
'cardDossiers' => $cardDossiers,
'cardOpinions' => $cardOpinions,
'publishedGames' => $publishedGames,
'developedGames' => $developedGames,
'compatibleGames' => $compatibleGames
);
}
/**
* This private method is used to factorize the code between review and preview pages, which
* are quite similar.
*
* @param int $cardId Card identifier (from GhCard entity).
* @param int $articleId Article identifier (from GhReview or GhPreview entities).
* @param string $type CardController::ARTICLE_TYPE_REVIEW or CardController::ARTICLE_TYPE_PREVIEW.
* @return array/RedirectResponse Array with the following keys: 'card', 'article'.
* If an error is thrown, RedirectResponse is sent.
*/
private function reviewPreviewAction($cardId, $articleId, $type)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
if ($card === null) {
// Throw a 404 error if no card found
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
if ($type == self::ARTICLE_TYPE_REVIEW) {
$article = $em->getRepository('GhDatabaseBundle:GhReview')->findOneById($articleId);
} elseif ($type == self::ARTICLE_TYPE_PREVIEW) {
$article = $em->getRepository('GhDatabaseBundle:GhPreview')->findOneById($articleId);
}
if ($article === null) {
// Throw a 404 error if no article found
throw $this->createNotFoundException('Aucun article n\'a été trouvé');
}
// Increment view counter
$article->setCounter($article->getCounter() + 1);
$em->flush();
// Generate title
if ($type == self::ARTICLE_TYPE_REVIEW) {
$title = 'Test';
} elseif ($type == self::ARTICLE_TYPE_PREVIEW) {
$title = 'Preview';
}
$title .= ' '.$card->getTitle().' - '.$card->getDisplayConsole();
TitleClass::getInstance()->setTitle($title);
// 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(SectionTypeClass::getInstance()->getLabelById($type, $article->getType()));
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', SectionTypeClass::getInstance()->getLabelById($type, $article->getType()).' du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope.');
$meta->addMeta('og:type', 'article');
$meta->addMeta('og:description', $article->getCatcherfacebook());
// Prevent indexation of not published articles
if ($article->getWorkflowstate() != WorkflowStateClass::PUBLISHED) {
$meta->setMeta('robots', 'noindex, nofollow');
}
// Generate canonical URL
if ($type == self::ARTICLE_TYPE_REVIEW) {
$this->updateCanonicalUrl($card, array('reviewId' => $articleId));
} elseif ($type == self::ARTICLE_TYPE_PREVIEW) {
$this->updateCanonicalUrl($card, array('previewId' => $articleId));
}
$canonicalUrl = UtilClass::getCanonicalUrlFromMeta();
// Push the sidebar Author
$member = $em->getRepository('GhDatabaseBundle:GhTeam')->findOneByName($article->getAuthor());
SidebarClass::getInstance()->push('author', new SidebarAuthor($member), -1);
return array(
'card' => $card,
'article' => $article,
'canonicalUrl' => $canonicalUrl
);
}
/**
* $previewMode: If true, all articles can be opened. If false, only published articles can be opened.
*
* @Route(
* "/{console}/{cardId}-{slug}/test_{reviewId}.html",
* name="GhFrontBundle_Card_review",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "reviewId" = "([0-9]+)"}
* )
* @Template()
*/
public function reviewAction($console, $cardId, $slug, $reviewId, $previewMode = false)
{
$array = $this->reviewPreviewAction($cardId, $reviewId, self::ARTICLE_TYPE_REVIEW);
// If an error is thrown, RedirectResponse is sent
if ($array instanceof RedirectResponse) {
return $array;
}
$meta = MetaClass::getInstance();
$meta->addMeta('keywords', 'jeux vidéo, '.$array['card']->getTitle().', '.$array['card']->getDisplayConsole().', test, '.SectionTypeClass::getInstance()->getLabelById('review', $array['article']->getType()));
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('review');
return array(
'card' => $array['card'],
'article' => $array['article'],
'canonicalUrl' => $array['canonicalUrl']
);
}
/**
* Route used by GameHope V4 and V5.
*
* @Route(
* "/test.articles/{reviewId}.html",
* name="GhFrontBundle_Card_reviewOldRoute",
* requirements={"reviewId" = "([0-9]+)"}
* )
*/
public function reviewOldRouteAction($reviewId)
{
// Find the associated review
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository('GhDatabaseBundle:GhReview')->findOneById($reviewId);
// Throw a 404 error if no article found
if ($article === null) {
throw $this->createNotFoundException('Aucun article n\'a été trouvé');
}
$routeParams = UtilClass::getRouteParamsFromCard($article->getCardid());
return $this->redirect($this->generateUrl(
'GhFrontBundle_Card_review',
array_merge($routeParams, array('reviewId' => $reviewId))
),
301
);
}
/**
* $previewMode: If true, all articles can be opened. If false, only published articles can be opened.
*
* @Route(
* "/{console}/{cardId}-{slug}/preview_{previewId}.html",
* name="GhFrontBundle_Card_preview",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "previewId" = "([0-9]+)"}
* )
* @Template()
*/
public function previewAction($console, $cardId, $slug, $previewId, $previewMode = false)
{
$array = $this->reviewPreviewAction($cardId, $previewId, self::ARTICLE_TYPE_PREVIEW);
// If an error is thrown, RedirectResponse is sent
if ($array instanceof RedirectResponse) {
return $array;
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->addMeta('keywords', 'jeux vidéo, '.$array['card']->getTitle().', '.$array['card']->getDisplayConsole().', preview, '.SectionTypeClass::getInstance()->getLabelById('preview', $array['article']->getType()));
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('preview');
return array(
'card' => $array['card'],
'article' => $array['article'],
'canonicalUrl' => $array['canonicalUrl']
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/galerie-{page}.html",
* name="GhFrontBundle_Card_gallery",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "page" = "([0-9]+)"}
* )
* @Template()
*/
public function galleryAction($console, $cardId, $slug, $page)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucun article n\'a été trouvé');
}
// 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_gallery', array('card' => $card, 'page' => 1));
if ($page != 1) {
$breadcrumb->addPath('Page '.$page);
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez toutes les images du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' : screenshots, captures d\'écran, artworks, wallpapers.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole());
// Generate canonical URL
$this->updateCanonicalUrl($card, array('page' => $page));
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('gallery');
// Pagination
$paginator = new PaginatorHelper(
$em->getRepository('GhDatabaseBundle:GhGallery')->countGalleryByCardId($cardId),
$page,
$this->container->getParameter('gallery_images_per_page')
);
$paginator->setSfLinkedController($this);
$paginator->setRouter($this->get('router'));
$paginator->setSfUrlParameters(UtilClass::getRouteParamsFromCard($card));
$paginator->setPageParameterName('page');
$paginator->setPaginationStep($this->container->getParameter('gallery_pagination_step'));
// Get pictures list
$associatedGalleries = $em->getRepository('GhDatabaseBundle:GhGallery')->getGalleryByCardId($cardId, $paginator->getOffset(), $paginator->getLimit());
// Throw a 404 error if no picture found
if (count($associatedGalleries) == 0) {
throw $this->createNotFoundException('Aucune image n\'a été trouvée');
}
// Determine the date limit to highlight the screenshots
$newInterval = $this->container->getParameter('gallery_new_interval');
$newDateLimit = time() - ($newInterval * 3600 * 24);
return array(
'card' => $card,
'page' => $page,
'associatedGalleries' => $associatedGalleries,
'paginator' => $paginator,
'imagesPerLine' => $this->container->getParameter('gallery_images_per_line'),
'newDateLimit' => $newDateLimit
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/galerie.html",
* name="GhFrontBundle_Card_galleryDefault",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
*/
public function galleryDefaultAction($console, $cardId, $slug)
{
return $this->redirect(
$this->generateUrl(
'GhFrontBundle_Card_gallery',
array('console' => $console, 'cardId' => $cardId, 'slug' => $slug, 'page' => 1)
),
301
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/videos.html",
* name="GhFrontBundle_Card_movie",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function movieAction($console, $cardId, $slug)
{
$type = NULL;
$request = $this->getRequest();
if ($request->query->get('type')) {
$type = $request->query->get('type');
}
return $this->movieFactorized($cardId, 0, $type);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/video-{movieId}.html",
* name="GhFrontBundle_Card_movieView",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "movieId" = "([0-9]+)"}
* )
* @Template("@GhFront/card/movie.html.twig")
*/
public function movieViewAction($console, $cardId, $slug, $movieId)
{
return $this->movieFactorized($cardId, $movieId);
}
/**
* This private method is called by both GhFrontBundle_Card_movie and GhFrontBundle_Card_movieView routes.
*
* @param integer $cardId
* @param integer $movieId By default, set to 0 (no movie selected).
* @param integer $type By default, set to NULL (no category selected).
* @return array()
*/
private function movieFactorized($cardId, $movieId = 0, $type = NULL)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Select the movies
$associatedMovies = $em->getRepository('GhDatabaseBundle:GhMovie')->getMovieByCardIdAndType($cardId, $type);
if (count($associatedMovies) == 0) {
// Throw a 404 error if no movie found
throw $this->createNotFoundException('Aucune vidéo n\'a été trouvée');
}
// Extract all categories
if ($type !== NULL) {
$associatedMoviesForCategories = $em->getRepository('GhDatabaseBundle:GhMovie')->getMovieByCardIdAndType($cardId);
} else {
$associatedMoviesForCategories = $associatedMovies;
}
$categoriesList = array();
foreach ($associatedMoviesForCategories as $movie) {
if (!in_array($movie->getType(), $categoriesList)) {
$categoriesList[] = $movie->getType();
}
}
sort($categoriesList);
// Get the movie to display
$selectedMovie = null;
if ($movieId == 0) {
// When no movie is selected, choose one by default
if (count($associatedMovies) > 0) {
$selectedMovie = $associatedMovies[0];
}
// Exclude current video
array_shift($associatedMovies);
} else {
// When a movie is selected, choose it, and remove it from the list
for ($i = 0; $i < count($associatedMovies); $i++) {
if ($associatedMovies[$i]->getId() == $movieId) {
$selectedMovie = $associatedMovies[$i];
unset($associatedMovies[$i]);
}
}
}
if ($selectedMovie === null) {
// Throw a 404 error if no movie found
throw $this->createNotFoundException('Aucune vidéo n\'a été trouvée');
}
// Increment view counter
if ($selectedMovie) {
$selectedMovie->setCounter($selectedMovie->getCounter() + 1);
$em->flush();
}
// Determine the date limit to highlight the movies
$newInterval = $this->container->getParameter('movie_new_interval');
$newDateLimit = time() - ($newInterval * 3600 * 24);
// Generate title
$title = $card->getTitle().' - '.$card->getDisplayConsole().' : vidéo';
if ($selectedMovie && mb_strtolower($selectedMovie->getTitle(), 'UTF-8') != mb_strtolower($card->getTitle(), 'UTF-8')) {
$title .= ' '.$selectedMovie->getTitle().' ('.SectionTypeClass::getInstance()->getLabelById('movie', $selectedMovie->getType()).')';
}
TitleClass::getInstance()->setTitle($title);
// 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('Vidéos', $this->get('router'), 'GhFrontBundle_Card_movie', array('card' => $card));
if ($type !== NULL) {
$breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('movie', $type), $this->get('router'), 'GhFrontBundle_Card_movie', array('card' => $card, 'type' => $type));
}
if ($movieId != 0) {
$breadcrumb->addPath($selectedMovie->getTitle());
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez toutes les vidéos du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : trailers, bande annonces, reportages, interviews.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole().', vidéos');
$meta->addMeta('og:type', 'video.movie');
$meta->addMeta('og:image', $this->container->getParameter('base_url_absolute').MovieHelper::displayMovieThumb($this->container, $selectedMovie));
// Generate canonical URL
$this->updateCanonicalUrl($card, array('movieId' => $selectedMovie->getId()), '', 'GhFrontBundle_Card_movieView');
$canonicalUrl = UtilClass::getCanonicalUrlFromMeta();
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('movie');
return array(
'card' => $card,
'associatedMovies' => $associatedMovies,
'movie' => $selectedMovie,
'movieId' => $movieId,
'selectedType' => $type,
'newDateLimit' => $newDateLimit,
'categoriesList' => $categoriesList,
'canonicalUrl' => $canonicalUrl
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/presse.html",
* name="GhFrontBundle_Card_pressReview",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function pressReviewAction($console, $cardId, $slug)
{
$em = $this->getDoctrine()->getManager();
$associatedPressReviews = $em->getRepository('GhDatabaseBundle:GhPressReview')->getPressReviewsByCardId($cardId);
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Throw a 404 error if no press review found
if (count($associatedPressReviews) == 0) {
throw $this->createNotFoundException('Aucune revue de presse n\'a été trouvée');
}
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : la revue de presse');
// 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('Revue de presse');
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez toutes les revues de presse du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole().', revue de presse');
// Generate canonical URL
$this->updateCanonicalUrl($card);
return array(
'card' => $card,
'associatedPressReviews' => $associatedPressReviews
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/astuces.html",
* name="GhFrontBundle_Card_hint",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function hintAction($console, $cardId, $slug)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
$associatedHints = $em->getRepository('GhDatabaseBundle:GhHint')->getHintByCardId($cardId);
// Throw a 404 error if no hint found
if (count($associatedHints) == 0) {
throw $this->createNotFoundException('Aucune astuce n\'a été trouvée');
}
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : astuces, cheat codes, solution');
// 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('Astuces');
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez toutes les astuces, cheat codes, triches du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole().', cheat codes, astuces, triche, solution, soluce');
// Generate canonical URL
$this->updateCanonicalUrl($card);
$canonicalUrl = UtilClass::getCanonicalUrlFromMeta();
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('hint');
return array(
'card' => $card,
'associatedHints' => $associatedHints,
'canonicalUrl' => $canonicalUrl
);
}
/**
* Route used by GameHope V4 and V5.
*
* @Route(
* "/astuce.articles/{hintId}.html",
* name="GhFrontBundle_Card_hintOldRoute",
* requirements={"hintId" = "([0-9]+)"}
* )
*/
public function hintOldRouteAction($hintId)
{
// Find the associated hint
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository('GhDatabaseBundle:GhHint')->findOneById($hintId);
// Throw a 404 error if no article found
if ($article === null) {
throw $this->createNotFoundException('Aucun article n\'a été trouvé');
}
$routeParams = UtilClass::getRouteParamsFromCard($article->getCardid());
return $this->redirect($this->generateUrl(
'GhFrontBundle_Card_hint',
$routeParams
),
301
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/telecharger.html",
* name="GhFrontBundle_Card_download",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function downloadAction($console, $cardId, $slug)
{
return $this->downloadFactorized($cardId);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/demos-jouables.html",
* name="GhFrontBundle_Card_downloadDemo",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template("@GhFront/card/download.html.twig")
*/
public function downloadDemoAction($console, $cardId, $slug)
{
return $this->downloadFactorized($cardId, GhDownload::DOWNLOAD_TYPE_DEMO);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/patches.html",
* name="GhFrontBundle_Card_downloadPatch",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template("@GhFront/card/download.html.twig")
*/
public function downloadPatchAction($console, $cardId, $slug)
{
return $this->downloadFactorized($cardId, GhDownload::DOWNLOAD_TYPE_PATCH);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/videos-telecharger.html",
* name="GhFrontBundle_Card_downloadMovie",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template("@GhFront/card/download.html.twig")
*/
public function downloadMovieAction($console, $cardId, $slug)
{
return $this->downloadFactorized($cardId, GhDownload::DOWNLOAD_TYPE_MOVIE);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/jeu-complet.html",
* name="GhFrontBundle_Card_downloadFullGame",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template("@GhFront/card/download.html.twig")
*/
public function downloadFullGameAction($console, $cardId, $slug)
{
return $this->downloadFactorized($cardId, GhDownload::DOWNLOAD_TYPE_FULL_GAME);
}
/**
* @param integer $cardId
* @param integer $type Type of download. See GhDownload::DOWNLOAD_TYPE_* constants.
* By default NULL (all types are returned).
* @return array(mixed) Values to be sent to Twig template.
*/
private function downloadFactorized($cardId, $type = NULL)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Get pagination information
if ($this->getRequest()->query->get('page')) {
$page = $this->getRequest()->query->get('page');
} else {
$page = 1;
}
$paginator = new PaginatorHelper($em->getRepository('GhDatabaseBundle:GhDownload')->countDownloadsByCardIdAndType($cardId, $type), $page, $this->container->getParameter('downloads_per_page'));
$paginator->setSfLinkedController($this);
$paginator->setRouter($this->get('router'));
$paginator->setSfUrlParameters(array_merge(UtilClass::getRouteParamsFromCard($card), array('page' => $page)));
$paginator->setPageParameterName('page');
$paginator->setPaginationStep($this->container->getParameter('downloads_pagination_step'));
$associatedDownloads = $em->getRepository('GhDatabaseBundle:GhDownload')->getDownloadsByCardIdAndType($cardId, $type, $paginator->getOffset(), $paginator->getLimit());
// Throw a 404 error if no download found
if (count($associatedDownloads) == 0) {
throw $this->createNotFoundException('Aucun téléchargement n\'a été trouvé');
}
// Extract all categories
$associatedDownloadsForCategories = $em->getRepository('GhDatabaseBundle:GhDownload')->getDownloadsByCardIdAndType($cardId);
$categoriesList = array();
foreach ($associatedDownloadsForCategories as $download) {
if (!in_array($download->getType(), $categoriesList)) {
$categoriesList[] = $download->getType();
}
}
sort($categoriesList);
// Get the gallery, in order to illustrate the page
$gallery = $em->getRepository('GhDatabaseBundle:GhGallery')->getGalleryByCardId($cardId, 0, count($associatedDownloads));
// Generate title
$title = $card->getTitle().' - '.$card->getDisplayConsole().' : téléchargements';
if ($type !== NULL) {
$title .= ' ('.SectionTypeClass::getInstance()->getLabelById('download', $type, false).')';
}
TitleClass::getInstance()->setTitle($title);
// 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('Téléchargements', $this->get('router'), 'GhFrontBundle_Card_download', array('card' => $card));
if ($type !== NULL) {
$route = GhDownload::translateRoute($type);
$breadcrumb->addPath(SectionTypeClass::getInstance()->getLabelById('download', $type, false), $this->get('router'), $route, array('card' => $card));
}
if ($page != 1) {
$breadcrumb->addPath('Page '.$page);
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez tous les téléchargements du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : démos jouables, patches, vidéos, jeux complets.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole().', téléchargements, downloads');
// Generate canonical URL
$canonicalParam = '';
if ($page != 1) {
$canonicalParam = '?page='.$page;
}
$this->updateCanonicalUrl($card, array(), $canonicalParam);
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('download');
return array(
'card' => $card,
'associatedDownloads' => $associatedDownloads,
'paginator' => $paginator,
'gallery' => $gallery,
'categoriesList' => $categoriesList,
'selectedType' => ($type === NULL ? -1 : $type)
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/acheter.html",
* name="GhFrontBundle_Card_buy",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
* @Template()
*/
public function buyAction($console, $cardId, $slug)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : acheter au meilleur prix');
// 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('Acheter');
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Achetez '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole());
// Generate canonical URL
$this->updateCanonicalUrl($card);
// Get the shop links
$shopLinks = array(
'amazon' => ShopClass::getAmazonLink($card),
'priceminister' => ShopClass::getPriceMinisterLink($card),
'ebay' => ShopClass::getEbayLink($card),
'boulanger' => ShopClass::getBoulangerLink($card)
);
return array(
'card' => $card,
'shopLinks' => $shopLinks
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/news-{page}.html",
* name="GhFrontBundle_Card_news",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "page" = "([0-9]+)"}
* )
* @Template()
*/
public function newsAction($console, $cardId, $slug, $page)
{
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
// Generate title
TitleClass::getInstance()->setTitle($card->getTitle().' - '.$card->getDisplayConsole().' : toutes les news du jeu vidéo');
// 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('News', $this->get('router'), 'GhFrontBundle_Card_news', array('card' => $card, 'page' => 1));
if ($page != 1) {
$breadcrumb->addPath('Page '.$page);
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Découvrez toute l\'actualité du jeu vidéo '.$card->getTitle().' sur '.$card->getDisplayConsole().' sur GameHope : news, infos, reportages, rumeurs, plannings.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole());
// Set menu active
MenuActiveClass::getInstance()->setMenuActive('daily');
// Compute pagination
$paginator = new PaginatorHelper($em->getRepository('GhDatabaseBundle:GhNewsCard')->countNewsCardByCardId($cardId), $page, $this->container->getParameter('news_per_page'));
$paginator->setSfLinkedController($this);
$paginator->setRouter($this->get('router'));
$paginator->setSfUrlParameters(array_merge(UtilClass::getRouteParamsFromCard($card), array('page' => $page)));
$paginator->setPageParameterName('page');
$paginator->setPaginationStep($this->container->getParameter('news_pagination_step'));
// Get the list of news
$associatedNews = $em->getRepository('GhDatabaseBundle:GhNewsCard')->getNewsCardByCardId($cardId, $paginator->getOffset(), $paginator->getLimit());
// Generate canonical URL
$this->updateCanonicalUrl($card, array('page' => $page));
return array(
'card' => $card,
'associatedNews' => $associatedNews,
'paginator' => $paginator
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/news.html",
* name="GhFrontBundle_Card_newsDefault",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)"}
* )
*/
public function newsDefaultAction($console, $cardId, $slug)
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Card_news',
array('console' => $console, 'cardId' => $cardId, 'slug' => $slug, 'page' => 1)
),
301
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/{type}-{page}.html",
* name="GhFrontBundle_Card_companyGames",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "type" = "(editeur|developpeur)", "page" = "([0-9]+)"}
* )
* @Template()
*/
public function companyGamesAction($console, $cardId, $slug, $type, $page)
{
switch ($type) {
case 'editeur':
$filterType = GhCard::CARD_COMPANY_PUBLISHER;
break;
case 'developpeur':
$filterType = GhCard::CARD_COMPANY_DEVELOPER;
break;
default:
throw $this->createNotFoundException('Le type est invalide');
}
$em = $this->getDoctrine()->getManager();
$card = $em->getRepository('GhDatabaseBundle:GhCard')->getCardAndCompanies($cardId);
// Throw a 404 error if no card found
if ($card === null) {
throw $this->createNotFoundException('Aucun article n\'a été trouvé');
}
// Generate title
if ($filterType == GhCard::CARD_COMPANY_PUBLISHER) {
TitleClass::getInstance()->setTitle('Les jeux édités par '.$card->getTitle());
} else {
TitleClass::getInstance()->setTitle('Les jeux développés par '.$card->getTitle());
}
// 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));
if ($filterType == GhCard::CARD_COMPANY_PUBLISHER) {
$breadcrumb->addPath('Jeux édités', $this->get('router'), 'GhFrontBundle_Card_companyGames', array('card' => $card, 'type' => $type, 'page' => 1));
$descriptionLabel = 'édités';
} else {
$breadcrumb->addPath('Jeux développés', $this->get('router'), 'GhFrontBundle_Card_companyGames', array('card' => $card, 'type' => $type, 'page' => 1));
$descriptionLabel = 'développés';
}
if ($page != 1) {
$breadcrumb->addPath('Page '.$page);
}
// Generate meta
$meta = MetaClass::getInstance();
$meta->setMetaCard($card);
$meta->addMeta('description', 'Retrouvez tous les jeux '.$descriptionLabel.' par '.$card->getTitle().' sur GameHope : tests, previews, news, reportages, vidéos, astuces, téléchargements.');
$meta->addMeta('keywords', 'jeux vidéo, '.$card->getTitle().', '.$card->getDisplayConsole());
// Generate canonical URL
$this->updateCanonicalUrl($card, array('page' => $page, 'type' => $type));
// Pagination
$paginator = new PaginatorHelper(
$em->getRepository('GhDatabaseBundle:GhCard')->countPublishedOrDevelopedCards($card, $filterType),
$page,
$this->container->getParameter('cards_company_per_page')
);
$paginator->setSfLinkedController($this);
$paginator->setRouter($this->get('router'));
$paginator->setSfUrlParameters(array_merge(UtilClass::getRouteParamsFromCard($card), array('type' => $type)));
$paginator->setPageParameterName('page');
$paginator->setPaginationStep($this->container->getParameter('cards_company_pagination_step'));
// Get cards list
$associatedCards = $em->getRepository('GhDatabaseBundle:GhCard')->getPublishedOrDevelopedCards($card, $filterType, $paginator->getOffset(), $paginator->getLimit());
// Throw a 404 error if no card found
if (count($associatedCards) == 0) {
throw $this->createNotFoundException('Aucune fiche n\'a été trouvée');
}
return array(
'card' => $card,
'page' => $page,
'type' => $filterType,
'associatedCards' => $associatedCards,
'paginator' => $paginator
);
}
/**
* @Route(
* "/{console}/{cardId}-{slug}/{type}.html",
* name="GhFrontBundle_Card_companyGamesDefault",
* requirements={"console" = "([0-9a-zA-Z]+)", "cardId" = "([0-9]+)", "slug" = "([0-9a-zA-Z_-]+)", "type" = "(editeur|developpeur)"}
* )
*/
public function companyGamesDefaultAction($console, $cardId, $slug, $type)
{
return $this->redirect($this->generateUrl(
'GhFrontBundle_Card_companyGames',
array('console' => $console, 'cardId' => $cardId, 'slug' => $slug, 'type' => $type, 'page' => 1)
),
301
);
}
}