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');
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'),
]);
}
}

View File

@ -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')

View File

@ -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'))

View File

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