From 5432c0c330911069e172c4d97d1b17010fa72d8b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 29 Nov 2020 17:27:14 +0100 Subject: [PATCH] add lights in datas --- src/Controller/MonitoringController.php | 9 ++++++++- templates/datas.html.twig | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Controller/MonitoringController.php b/src/Controller/MonitoringController.php index f301d12..0cd6a3b 100644 --- a/src/Controller/MonitoringController.php +++ b/src/Controller/MonitoringController.php @@ -9,6 +9,7 @@ use App\Motion\SnapshotRepository; use Symfony\Component\HttpFoundation\Response; use App\Repository\TemperatureRepository; use App\Repository\HygrometryRepository; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class MonitoringController extends AbstractController { @@ -23,7 +24,11 @@ class MonitoringController extends AbstractController /** * @Route("/datas", name="datas") */ - public function datas(TemperatureRepository $temperatureRepository, HygrometryRepository $hygrometryRepository): Response + public function datas( + TemperatureRepository $temperatureRepository, + HygrometryRepository $hygrometryRepository, + ParameterBagInterface $params + ): Response { $from = new \DateTime('now - 1 day'); $to = new \DateTime('now'); @@ -31,6 +36,8 @@ class MonitoringController extends AbstractController return $this->render('datas.html.twig', [ 'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100, 'DESC'), 'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100, 'DESC'), + 'lightOnAt' => (int) $params->get('light_on_at'), + 'lightOffAt' => (int) $params->get('light_off_at'), ]); } } diff --git a/templates/datas.html.twig b/templates/datas.html.twig index 7cade45..3519741 100644 --- a/templates/datas.html.twig +++ b/templates/datas.html.twig @@ -29,7 +29,17 @@ {% endif %} - {{ item.date.format('d/m H:i') }} + + {% set lightTime = item.date.format('Gi') %} + + {% if lightTime >= lightOnAt and lightTime <= lightOffAt %} + 🌕 + {% else %} + 🌑 + {% endif %} + + {{ item.date.format('d/m H:i') }} + {{ item.value|number_format(2, ',', '') }}° {% endfor %} @@ -64,7 +74,17 @@ {% endif %} - {{ item.date.format('d/m H:i') }} + + {% set lightTime = item.date.format('Gi') %} + + {% if lightTime >= lightOnAt and lightTime <= lightOffAt %} + 🌕 + {% else %} + 🌑 + {% endif %} + + {{ item.date.format('d/m H:i') }} + {{ item.value|number_format(2, ',', '') }}% {% endfor %}