show datas ordered by most recent
This commit is contained in:
parent
04c8300092
commit
f322e40d88
|
@ -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'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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')
|
||||||
|
|
|
@ -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'))
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
Loading…
Reference in a new issue