show datas ordered by most recent

This commit is contained in:
Simon Vieille 2020-04-23 15:04:47 +02:00
parent 04c8300092
commit f322e40d88
Signed by: deblan
GPG key ID: 03383D15A1D31745
4 changed files with 7 additions and 7 deletions

View file

@ -29,8 +29,8 @@ class MonitoringController extends AbstractController
$to = new \DateTime('now'); $to = new \DateTime('now');
return $this->render('datas.html.twig', [ return $this->render('datas.html.twig', [
'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100), 'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100, 'DESC'),
'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100), 'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100, 'DESC'),
]); ]);
} }
} }

View file

@ -19,7 +19,7 @@ class HygrometryRepository extends ServiceEntityRepository
parent::__construct($registry, Hygrometry::class); 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') $query = $this->createQueryBuilder('h')
->orderBy('h.date') ->orderBy('h.date')

View file

@ -19,10 +19,10 @@ class TemperatureRepository extends ServiceEntityRepository
parent::__construct($registry, Temperature::class); 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') $query = $this->createQueryBuilder('t')
->orderBy('t.date') ->orderBy('t.date', $dateOrder)
->andWhere('t.date >= :fromDate') ->andWhere('t.date >= :fromDate')
->andWhere('t.date <= :toDate') ->andWhere('t.date <= :toDate')
->setParameter('fromDate', $fromDate->format('Y-m-d H:i:s')) ->setParameter('fromDate', $fromDate->format('Y-m-d H:i:s'))

View file

@ -19,7 +19,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for item in temperatures|reverse %} {% for item in temperatures %}
{% if item.value >= 27 %} {% if item.value >= 27 %}
{% set class = 'table-info' %} {% set class = 'table-info' %}
{% elseif item.value <= 22 %} {% elseif item.value <= 22 %}
@ -54,7 +54,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for item in hygrometries|reverse %} {% for item in hygrometries %}
{% if item.value >= 50 %} {% if item.value >= 50 %}
{% set class = 'table-danger' %} {% set class = 'table-danger' %}
{% elseif item.value >= 40 %} {% elseif item.value >= 40 %}