feat(04-01): add getUserProjects service, widget data, and Twig data attributes

This commit is contained in:
Christopher Mühl 2026-04-08 15:29:53 +02:00
parent c8a5f0da08
commit 3df754ea62
No known key found for this signature in database
GPG key ID: 925AC7D69955293F
3 changed files with 32 additions and 2 deletions

View file

@ -6,6 +6,8 @@
<link rel="stylesheet" href="{{ asset('bundles/kimaiheatmap/heatmap.css') }}">
<div id="heatmap-container"
data-url="{{ path('heatmap_data') }}"
data-projects="{{ data.projects|json_encode }}"
data-timesheet-url="{{ path('timesheet') }}"
style="min-height: 150px; overflow-x: auto;">
</div>
<script src="{{ asset('bundles/kimaiheatmap/heatmap.js') }}"></script>

View file

@ -47,4 +47,23 @@ class HeatmapService
];
}, $results);
}
/**
* @return array<int, array{id: int, name: string}>
*/
public function getUserProjects(User $user): array
{
$qb = $this->repository->createQueryBuilder('t');
$qb->select('DISTINCT IDENTITY(t.project) as projectId, p.name')
->join('t.project', 'p')
->andWhere($qb->expr()->eq('t.user', ':user'))
->andWhere($qb->expr()->isNotNull('t.end'))
->setParameter('user', $user)
->orderBy('p.name', 'ASC');
return array_map(fn(array $row) => [
'id' => (int) $row['projectId'],
'name' => $row['name'],
], $qb->getQuery()->getResult());
}
}

View file

@ -4,9 +4,14 @@ namespace KimaiPlugin\KimaiHeatmapBundle\Widget;
use App\Widget\Type\AbstractWidget;
use App\Widget\WidgetInterface;
use KimaiPlugin\KimaiHeatmapBundle\Service\HeatmapService;
final class HeatmapWidget extends AbstractWidget
class HeatmapWidget extends AbstractWidget
{
public function __construct(private readonly HeatmapService $service)
{
}
public function getId(): string
{
return 'HeatmapWidget';
@ -34,7 +39,11 @@ final class HeatmapWidget extends AbstractWidget
public function getData(array $options = []): mixed
{
return null;
$user = $this->getUser();
return [
'projects' => $this->service->getUserProjects($user),
];
}
public function getTemplateName(): string