terrarium-web/src/Controller/EventController.php

40 lines
997 B
PHP
Raw Normal View History

2020-03-21 18:39:12 +01:00
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;
use App\Motion\SnapshotRepository;
class EventController extends AbstractController
{
/**
2020-03-22 15:31:46 +01:00
* @Route("/events/{date}", name="events")
2020-03-21 18:39:12 +01:00
*/
2020-03-22 15:31:46 +01:00
public function events(SnapshotRepository $snapshotRepository, string $date = null)
2020-03-21 18:39:12 +01:00
{
2020-03-22 15:31:46 +01:00
$date = $date ?? date('Y-m-d');
$snapshots = $snapshotRepository->find([
'order' => 'DESC',
]);
$days = [];
foreach ($snapshots as $snapshot) {
$day = $snapshot->getDate()->format('d/m');
if (!in_array($day, $days)) {
$days[$snapshot->getDate()->format('Y-m-d')] = $day;
}
}
2020-03-21 18:39:12 +01:00
return $this->render('events.html.twig', [
'snapshots' => $snapshots,
2020-03-22 15:31:46 +01:00
'days' => $days,
'date' => $date,
2020-03-21 18:39:12 +01:00
]);
}
}