<?php
namespace DW\GingerBundle\Controller;
use DW\GingerBundle\Doctrine\PersonManager;
use DW\GingerBundle\Doctrine\TagManager;
use DW\GingerBundle\Doctrine\AttributeManager;
use DW\GingerBundle\Entity\PersonInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/")
* @IsGranted("ROLE_GINGER_BEUSER")
*/
class DashboardController extends AbstractController
{
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* @var PersonManager
*/
protected $personManager;
/**
* @var AttributeManager
*/
protected $attributeManager;
/**
* @var TagManager
*/
protected $tagManager;
public function __construct(
TranslatorInterface $translator,
PersonManager $personManager,
TagManager $tagManager,
AttributeManager $attributeManager
) {
$this->personManager = $personManager;
$this->tagManager = $tagManager;
$this->attributeManager = $attributeManager;
}
/**
* @Route("/", name="ginger_dashboard")
*
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request)
{
$genderQuery = $this->getDoctrine()
->getRepository(PersonInterface::class)
->createQueryBuilder('person')
->select('person.gender', 'count(person.id) AS count')
->andWhere('person.gender IN (\'m\', \'f\')')
->groupBy('person.gender')
->getQuery()
;
$stats = [
'totalPersons' => $this->personManager->getTotalCount(),
'totalDuplicates' => $this->personManager->getDuplicatesCount(),
'totalTags' => $this->tagManager->getTotalCountByType(),
'personGenders' => $genderQuery->getResult(),
];
return $this->render('@DWGinger/dashboard/index.html.twig', [
'stats' => $stats,
]);
}
}