71 lines
2.9 KiB
PHP
71 lines
2.9 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');
|
|
|
|
$mode = $request->query->getString('mode', 'daily');
|
|
$projectId = $request->query->getInt('project') ?: null;
|
|
$customerId = $request->query->getInt('customer') ?: null;
|
|
$activityId = $request->query->getInt('activity') ?: null;
|
|
|
|
$range = ['begin' => $begin->format('Y-m-d'), 'end' => $end->format('Y-m-d')];
|
|
|
|
return match ($mode) {
|
|
'hourly' => new JsonResponse([
|
|
'hours' => $service->getHourlyAggregation($user, $begin, $end, $projectId, $customerId, $activityId),
|
|
'range' => $range,
|
|
]),
|
|
'dayhour' => new JsonResponse([
|
|
'matrix' => $service->getDayHourAggregation($user, $begin, $end, $projectId, $customerId, $activityId, $user->getFirstDayOfWeek()),
|
|
'range' => $range,
|
|
]),
|
|
default => new JsonResponse([
|
|
'days' => $service->getDailyAggregation($user, $begin, $end, $projectId, $customerId, $activityId),
|
|
'range' => $range,
|
|
]),
|
|
};
|
|
}
|
|
|
|
#[Route(path: '/customers', name: 'heatmap_customers', methods: ['GET'])]
|
|
#[IsGranted('view_own_timesheet')]
|
|
public function customers(HeatmapService $service): JsonResponse
|
|
{
|
|
return new JsonResponse($service->getUserCustomers($this->getUser()));
|
|
}
|
|
|
|
#[Route(path: '/projects', name: 'heatmap_projects', methods: ['GET'])]
|
|
#[IsGranted('view_own_timesheet')]
|
|
public function projects(Request $request, HeatmapService $service): JsonResponse
|
|
{
|
|
$customerId = $request->query->getInt('customer') ?: null;
|
|
|
|
return new JsonResponse($service->getUserProjects($this->getUser(), $customerId));
|
|
}
|
|
|
|
#[Route(path: '/activities', name: 'heatmap_activities', methods: ['GET'])]
|
|
#[IsGranted('view_own_timesheet')]
|
|
public function activities(Request $request, HeatmapService $service): JsonResponse
|
|
{
|
|
$projectId = $request->query->getInt('project') ?: null;
|
|
|
|
return new JsonResponse($service->getUserActivities($this->getUser(), $projectId));
|
|
}
|
|
}
|