<?php
declare(strict_types=1);
namespace Hitso\Bundle\AdminBundle\Controller\Admin;
use Hitso\Bundle\CommonBundle\Controller\Controller;
use Hitso\Bundle\CommonBundle\Entity\Log\Crud;
use Hitso\Bundle\CommonBundle\Entity\VisitLog;
use Hitso\Bundle\CommonBundle\Interfaces\ApprovedAtInterface;
use Hitso\Bundle\CommonBundle\Repository\UserLogEntryRepository;
use Hitso\Bundle\CommonBundle\Repository\VisitLogRepository;
use Hitso\Bundle\ContentBundle\Repository\ArticleRepository;
use Hitso\Bundle\ContentBundle\Repository\CommentRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Routing\Annotation\Route;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
/**
* @Security("has_role('ROLE_WITH_ACCESS_TO_ADMIN')")
*/
class DashboardController extends Controller
{
/**
* @Route("/", name="hitso_admin_dashboard")
*/
public function indexAction(
UserLogEntryRepository $logRepository,
VisitLogRepository $visitRepository,
CommentRepository $commentRepository,
ArticleRepository $articleRepository,
Breadcrumbs $breadcrumbs
) {
$logEntries = $logRepository->getRecentByTypeAndSite([Crud::class], 'admin', 4);
$lastGoogleVisit = $visitRepository->getLastTime(VisitLog::TYPE_GOOGLE);
$lastApiTest = $visitRepository->getLastTime(VisitLog::TYPE_API_TEST);
$monitorChartData = $visitRepository->getChartData(VisitLog::TYPE_MONITOR);
$lastHitsoMonitoringVisit = $visitRepository->getLastTime(VisitLog::TYPE_HITSO_MONITORING);
$analyticsReport = null;
$pendingComments = $commentRepository->getCommentCountByStatus(ApprovedAtInterface::APPROVAL_STATUS_WAITING);
$articlesCount = $articleRepository->getContentCount();
$articlesCountNotPublished = $articleRepository->getContentCountUnpublished();
$breadcrumbs->addItem('Dashboard');
return $this->displayTemplate('index', [
'logs' => $logEntries,
'lastGoogleVisit' => $lastGoogleVisit,
'lastApiTest' => $lastApiTest,
'monitorChartData' => [
'values' => array_values($monitorChartData),
'labels' => array_keys($monitorChartData),
],
'analyticsReport' => $analyticsReport,
'pendingComments' => $pendingComments,
'lastHitsoMonitoringVisit' => $lastHitsoMonitoringVisit,
'articlesCount' => $articlesCount,
'articlesCountNotPublished' => $articlesCountNotPublished,
]);
}
/**
* @Security("is_granted('ROLE_ADMIN_LOG_ACCESS')")
* @Route("/log", name="hitso_admin_dashboard_log")
*/
public function logAction(Breadcrumbs $breadcrumbs)
{
$breadcrumbs->addItem('Dziennik zdarzeĆ');
return $this->displayTemplate('log');
}
}