40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?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);
|
|
}
|
|
|
|
public function findByDateRange(\DateTime $fromDate, \DateTime $toDate, ?int $limit = null, string $dateOrder = 'ASC')
|
|
{
|
|
$query = $this->createQueryBuilder('h')
|
|
->orderBy('h.date', $dateOrder)
|
|
->andWhere('h.date >= :fromDate')
|
|
->andWhere('h.date <= :toDate')
|
|
->setParameter('fromDate', $fromDate->format('Y-m-d H:i:s'))
|
|
->setParameter('toDate', $toDate->format('Y-m-d H:i:s'));
|
|
|
|
if ($limit !== null) {
|
|
$query->setMaxResults($limit);
|
|
}
|
|
|
|
return $query
|
|
->getQuery()
|
|
->getResult();
|
|
}
|
|
}
|