murph-core/src/core/Controller/Analytic/AnalyticController.php

35 lines
1.1 KiB
PHP
Raw Normal View History

2022-03-13 19:32:32 +01:00
<?php
namespace App\Core\Controller\Analytic;
use App\Core\Analytic\DateRangeAnalytic;
use App\Core\Entity\Site\Node;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
2022-11-19 19:35:28 +01:00
#[Route(path: '/admin/analytic')]
2022-03-13 19:32:32 +01:00
class AnalyticController extends AbstractController
{
2022-11-19 19:35:28 +01:00
#[Route(path: '/stats/{node}/{range}', name: 'admin_analytic_stats')]
2022-03-13 19:32:32 +01:00
public function stats(Node $node, DateRangeAnalytic $analytic, string $range = '7days'): Response
{
if (!in_array($range, ['7days', '30days', '90days', '1year'])) {
throw $this->createNotFoundException();
}
$analytic
->setDateRange(new \DateTime('now - '.$range), new \DateTime())
->setNode($node)
;
return $this->render('@Core/analytic/stats.html.twig', [
'range' => $range,
'views' => $analytic->getViews(),
'pathViews' => $analytic->getPathViews(),
'referers' => $analytic->getReferers(),
'node' => $node,
]);
}
}