<?php
namespace Gh\FrontBundle\Controller;
use Doctrine\Common\Collections\ArrayCollection;
use Gh\DatabaseBundle\Entity\GhCard;
use Gh\DatabaseBundle\Entity\GhTeam;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* In this controller, a method is created for each component of the right sidebar.
*
* @author jmboyer
*/
class SidebarController extends Controller
{
/**
* These constants are used for similarCards and linkedCards sidebars.
*/
const CARDS_LIST_SIMILAR = 10;
const CARDS_LIST_LINKED = 20;
/**
* This component is the Similar games block in the sidebar (displayed in cards layout).
*
* @param GhCard|null $card
* @return array
* @Template("@GhFront/sidebar/cards_list.html.twig")
*/
public function similarCardsAction(?GhCard $card): array {
$em = $this->getDoctrine()->getManager();
$similarCards = $em->getRepository('GhDatabaseBundle:GhCard')->getSimilarCards($card, $this->container);
return array('cardsList' => $similarCards, 'mode' => self::CARDS_LIST_SIMILAR);
}
/**
* This component is the Linked cards block in the sidebar (displayed in news).
*
* @param GhCard[] $cardsList
* @return array
* @Template("@GhFront/sidebar/cards_list.html.twig")
*/
public function linkedCardsAction($cardsList): array {
return array('cardsList' => $cardsList, 'mode' => self::CARDS_LIST_LINKED);
}
/**
* This component is the Card block in the sidebar (displayed in news).
*
* @param GhCard[] $card This parameter is an array because a card can exist on multiple consoles.
* @return array
* @Template()
*/
public function cardAction($card): array {
$em = $this->getDoctrine()->getManager();
// Get card aliases
$cardAliases = $em->getRepository('GhDatabaseBundle:GhCardAlias')->findByCardid($card[0]->getId());
// Get the material cards
$cardMaterialList = $em->getRepository('GhDatabaseBundle:GhCardMaterial')->getMaterialCards($card[0]);
$cardMaterialsMandatory = array();
$cardMaterialsNotMandatory = array();
foreach ($cardMaterialList as $cardMaterial) {
if ($cardMaterial->getIsmandatory()) {
$cardMaterialsMandatory[] = $cardMaterial;
} else {
$cardMaterialsNotMandatory[] = $cardMaterial;
}
}
// Get the distribution methods
$cardDistributionMethods = $em->getRepository('GhDatabaseBundle:GhCardDistributionMethod')->getByCard($card[0]);
return array(
'card' => $card[0],
'cardConsoles' => $card,
'cardAliases' => $cardAliases,
'cardMaterialsMandatory' => $cardMaterialsMandatory,
'cardMaterialsNotMandatory' => $cardMaterialsNotMandatory,
'cardDistributionMethods' => $cardDistributionMethods
);
}
/**
* This component is the "Top reviews" block displayed in the table of contents of reviews.
*
* @param string $console
* @param string $subsection
* @return array
* @Template("@GhFront/sidebar/top_reviews.html.twig")
*/
public function topReviewsAction(string $console, string $subsection): array {
$em = $this->getDoctrine()->getManager();
$reviewsList = $em->getRepository('GhDatabaseBundle:GhReview')->getListTopReviewsTableContents(
$console,
$subsection,
$this->container->getParameter('table_contents_top_date_limit'),
$this->container->getParameter('table_contents_top_limit')
);
return array('reviewsList' => $reviewsList);
}
/**
* This sidebar is the list of latest news displayed on homepage.
*
* @param ArrayCollection|GhNews[] $newsList
* @return array
* @Template()
*/
public function newsAction($newsList): array {
return array('newsList' => $newsList);
}
/**
* This sidebar is the list of latest reviews displayed on homepage.
*
* @param ArrayCollection|GhReview[] $latestReviews
* @param string $console
* @return array
* @Template()
*/
public function reviewsAction($latestReviews, string $console): array {
return array('latestReviews' => $latestReviews, 'console' => $console);
}
/**
* This sidebar displays information about an author.
*
* @param GhTeam $member
* @return array
* @Template()
*/
public function authorAction(?GhTeam $member): array {
return array('member' => $member);
}
/**
* This sidebar displays previous news.
*
* @param GhNews[] $news
* @return array
* @Template("@GhFront/sidebar/news_previous.html.twig")
*/
public function newsPreviousAction($news): array {
return array('news' => $news);
}
/**
* This sidebar displays buy links.
*
* @param GhCard $card
* @param string[] $shopLinks
* @return array
* @Template()
*/
public function buyAction($card, $shopLinks): array {
return array('card' => $card, 'shopLinks' => $shopLinks);
}
/**
* This sidebar displays latest dossiers.
*
* @param GhDossier[] $latestDossiers
* @return array
* @Template("@GhFront/sidebar/dossiers_latest.html.twig")
*/
public function dossiersLatestAction($latestDossiers): array {
return array('latestDossiers' => $latestDossiers);
}
}