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');
|
||||
|
||||
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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Reference in a new issue