<?php
namespace App\Repository;
use App\Entity\SAV;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<SAV>
*
* @method SAV|null find($id, $lockMode = null, $lockVersion = null)
* @method SAV|null findOneBy(array $criteria, array $orderBy = null)
* @method SAV[] findAll()
* @method SAV[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SAVRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SAV::class);
}
public function add(SAV $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(SAV $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/**
* @return SAV[] Returns an array of SAV objects
*/
public function findSAVenCours(): array
{
return $this->createQueryBuilder('s')
->andWhere('s.dateCloture IS NULL OR s.dateCloture >= :today')
->andWhere('s.installation = false')
->setParameter('today', (new DateTime('now'))->setTime(00,01,0))
->getQuery()
->getResult()
;
}
/**
* @return SAV[] Returns an array of SAV objects
*/
public function findAllSAVsByMachine($machine): array
{
return $this->createQueryBuilder('s')
->andWhere('s.machine = :machine')
->setParameter('machine', $machine->getId())
->andWhere('s.installation = false')
->getQuery()
->getResult()
;
}
// public function findOneBySomeField($value): ?SAV
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}