36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace KimaiPlugin\KimaiHeatmapBundle\Controller;
|
|
|
|
use KimaiPlugin\KimaiHeatmapBundle\Service\HeatmapService;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
#[Route(path: '/heatmap')]
|
|
#[IsGranted('IS_AUTHENTICATED_REMEMBERED')]
|
|
class HeatmapController extends AbstractController
|
|
{
|
|
#[Route(path: '/data', name: 'heatmap_data', methods: ['GET'])]
|
|
#[IsGranted('view_own_timesheet')]
|
|
public function data(Request $request, HeatmapService $service): JsonResponse
|
|
{
|
|
$user = $this->getUser();
|
|
$end = new \DateTimeImmutable('today');
|
|
$begin = $end->modify('-1 year');
|
|
|
|
$projectId = $request->query->getInt('project') ?: null;
|
|
|
|
$days = $service->getDailyAggregation($user, $begin, $end, $projectId);
|
|
|
|
return new JsonResponse([
|
|
'days' => $days,
|
|
'range' => [
|
|
'begin' => $begin->format('Y-m-d'),
|
|
'end' => $end->format('Y-m-d'),
|
|
],
|
|
]);
|
|
}
|
|
}
|