vendor/datenwerk/ginger-bundle/Controller/DashboardController.php line 56

Open in your IDE?
  1. <?php
  2. namespace DW\GingerBundle\Controller;
  3. use DW\GingerBundle\Doctrine\PersonManager;
  4. use DW\GingerBundle\Doctrine\TagManager;
  5. use DW\GingerBundle\Doctrine\AttributeManager;
  6. use DW\GingerBundle\Entity\PersonInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. /**
  14.  * @Route("/")
  15.  * @IsGranted("ROLE_GINGER_BEUSER")
  16.  */
  17. class DashboardController extends AbstractController
  18. {
  19.     /**
  20.      * @var TranslatorInterface
  21.      */
  22.     protected $translator;
  23.     /**
  24.      * @var PersonManager
  25.      */
  26.     protected $personManager;
  27.     /**
  28.      * @var AttributeManager
  29.      */
  30.     protected $attributeManager;
  31.     /**
  32.      * @var TagManager
  33.      */
  34.     protected $tagManager;
  35.     public function __construct(
  36.         TranslatorInterface $translator,
  37.         PersonManager $personManager,
  38.         TagManager $tagManager,
  39.         AttributeManager $attributeManager
  40.     ) {
  41.         $this->personManager $personManager;
  42.         $this->tagManager $tagManager;
  43.         $this->attributeManager $attributeManager;
  44.     }
  45.     /**
  46.      * @Route("/", name="ginger_dashboard")
  47.      *
  48.      * @param Request $request
  49.      *
  50.      * @return Response
  51.      */
  52.     public function indexAction(Request $request)
  53.     {
  54.         $genderQuery $this->getDoctrine()
  55.           ->getRepository(PersonInterface::class)
  56.           ->createQueryBuilder('person')
  57.           ->select('person.gender''count(person.id) AS count')
  58.           ->andWhere('person.gender IN (\'m\', \'f\')')
  59.           ->groupBy('person.gender')
  60.           ->getQuery()
  61.         ;
  62.         $stats = [
  63.             'totalPersons'      => $this->personManager->getTotalCount(),
  64.             'totalDuplicates'   => $this->personManager->getDuplicatesCount(),
  65.             'totalTags'         => $this->tagManager->getTotalCountByType(),
  66.             'personGenders'     => $genderQuery->getResult(),
  67.         ];
  68.         return $this->render('@DWGinger/dashboard/index.html.twig', [
  69.             'stats' => $stats,
  70.         ]);
  71.     }
  72. }