src/Hitso/Bundle/AdminBundle/Controller/Admin/DashboardController.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hitso\Bundle\AdminBundle\Controller\Admin;
  4. use Hitso\Bundle\CommonBundle\Controller\Controller;
  5. use Hitso\Bundle\CommonBundle\Entity\Log\Crud;
  6. use Hitso\Bundle\CommonBundle\Entity\VisitLog;
  7. use Hitso\Bundle\CommonBundle\Interfaces\ApprovedAtInterface;
  8. use Hitso\Bundle\CommonBundle\Repository\UserLogEntryRepository;
  9. use Hitso\Bundle\CommonBundle\Repository\VisitLogRepository;
  10. use Hitso\Bundle\ContentBundle\Repository\ArticleRepository;
  11. use Hitso\Bundle\ContentBundle\Repository\CommentRepository;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
  15. /**
  16.  * @Security("has_role('ROLE_WITH_ACCESS_TO_ADMIN')")
  17.  */
  18. class DashboardController extends Controller
  19. {
  20.     /**
  21.      * @Route("/", name="hitso_admin_dashboard")
  22.      */
  23.     public function indexAction(
  24.         UserLogEntryRepository $logRepository,
  25.         VisitLogRepository $visitRepository,
  26.         CommentRepository $commentRepository,
  27.         ArticleRepository $articleRepository,
  28.         Breadcrumbs $breadcrumbs
  29.     ) {
  30.         $logEntries                $logRepository->getRecentByTypeAndSite([Crud::class], 'admin'4);
  31.         $lastGoogleVisit           $visitRepository->getLastTime(VisitLog::TYPE_GOOGLE);
  32.         $lastApiTest               $visitRepository->getLastTime(VisitLog::TYPE_API_TEST);
  33.         $monitorChartData          $visitRepository->getChartData(VisitLog::TYPE_MONITOR);
  34.         $lastHitsoMonitoringVisit  $visitRepository->getLastTime(VisitLog::TYPE_HITSO_MONITORING);
  35.         $analyticsReport           null;
  36.         $pendingComments           $commentRepository->getCommentCountByStatus(ApprovedAtInterface::APPROVAL_STATUS_WAITING);
  37.         $articlesCount             $articleRepository->getContentCount();
  38.         $articlesCountNotPublished $articleRepository->getContentCountUnpublished();
  39.         $breadcrumbs->addItem('Dashboard');
  40.         return $this->displayTemplate('index', [
  41.             'logs'                      => $logEntries,
  42.             'lastGoogleVisit'           => $lastGoogleVisit,
  43.             'lastApiTest'               => $lastApiTest,
  44.             'monitorChartData'          => [
  45.                 'values' => array_values($monitorChartData),
  46.                 'labels' => array_keys($monitorChartData),
  47.             ],
  48.             'analyticsReport'           => $analyticsReport,
  49.             'pendingComments'           => $pendingComments,
  50.             'lastHitsoMonitoringVisit'  => $lastHitsoMonitoringVisit,
  51.             'articlesCount'             => $articlesCount,
  52.             'articlesCountNotPublished' => $articlesCountNotPublished,
  53.         ]);
  54.     }
  55.     /**
  56.      * @Security("is_granted('ROLE_ADMIN_LOG_ACCESS')")
  57.      * @Route("/log", name="hitso_admin_dashboard_log")
  58.      */
  59.     public function logAction(Breadcrumbs $breadcrumbs)
  60.     {
  61.         $breadcrumbs->addItem('Dziennik zdarzeƄ');
  62.         return $this->displayTemplate('log');
  63.     }
  64. }