terrarium-web/src/Repository/HygrometryRepository.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2020-03-16 14:19:25 +01:00
<?php
namespace App\Repository;
use App\Entity\Hygrometry;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* @method Hygrometry|null find($id, $lockMode = null, $lockVersion = null)
* @method Hygrometry|null findOneBy(array $criteria, array $orderBy = null)
* @method Hygrometry[] findAll()
* @method Hygrometry[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class HygrometryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Hygrometry::class);
}
2020-04-23 15:04:47 +02:00
public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, ?int $limit = null, string $dateOrder = 'ASC')
2020-03-16 14:19:25 +01:00
{
2020-04-23 14:46:39 +02:00
$query = $this->createQueryBuilder('h')
2020-04-28 16:08:00 +02:00
->orderBy('h.date', $dateOrder)
->andWhere('h.date >= :fromDate')
->andWhere('h.date <= :toDate')
->setParameter('fromDate', $fromDate->format('Y-m-d H:i:s'))
2020-04-23 14:46:39 +02:00
->setParameter('toDate', $toDate->format('Y-m-d H:i:s'));
if ($limit !== null) {
$query->setMaxResults($limit);
}
return $query
2020-03-16 14:19:25 +01:00
->getQuery()
2020-04-23 14:46:39 +02:00
->getResult();
2020-03-16 14:19:25 +01:00
}
}