diff --git a/src/Controller/MonitoringController.php b/src/Controller/MonitoringController.php index c917f3c..f301d12 100644 --- a/src/Controller/MonitoringController.php +++ b/src/Controller/MonitoringController.php @@ -29,8 +29,8 @@ class MonitoringController extends AbstractController $to = new \DateTime('now'); return $this->render('datas.html.twig', [ - 'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100), - 'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100), + 'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100, 'DESC'), + 'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100, 'DESC'), ]); } } diff --git a/src/Repository/HygrometryRepository.php b/src/Repository/HygrometryRepository.php index 7f98e88..ce867d3 100644 --- a/src/Repository/HygrometryRepository.php +++ b/src/Repository/HygrometryRepository.php @@ -19,7 +19,7 @@ class HygrometryRepository extends ServiceEntityRepository parent::__construct($registry, Hygrometry::class); } - public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, int $limit = null) + public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, ?int $limit = null, string $dateOrder = 'ASC') { $query = $this->createQueryBuilder('h') ->orderBy('h.date') diff --git a/src/Repository/TemperatureRepository.php b/src/Repository/TemperatureRepository.php index b1cf81c..235987d 100644 --- a/src/Repository/TemperatureRepository.php +++ b/src/Repository/TemperatureRepository.php @@ -19,10 +19,10 @@ class TemperatureRepository extends ServiceEntityRepository parent::__construct($registry, Temperature::class); } - public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, int $limit = null) + public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, ?int $limit = null, string $dateOrder = 'ASC') { $query = $this->createQueryBuilder('t') - ->orderBy('t.date') + ->orderBy('t.date', $dateOrder) ->andWhere('t.date >= :fromDate') ->andWhere('t.date <= :toDate') ->setParameter('fromDate', $fromDate->format('Y-m-d H:i:s')) diff --git a/templates/datas.html.twig b/templates/datas.html.twig index a71db96..7cade45 100644 --- a/templates/datas.html.twig +++ b/templates/datas.html.twig @@ -19,7 +19,7 @@ - {% for item in temperatures|reverse %} + {% for item in temperatures %} {% if item.value >= 27 %} {% set class = 'table-info' %} {% elseif item.value <= 22 %} @@ -54,7 +54,7 @@ - {% for item in hygrometries|reverse %} + {% for item in hygrometries %} {% if item.value >= 50 %} {% set class = 'table-danger' %} {% elseif item.value >= 40 %}