<?php
namespace App\Repository;
use App\Entity\FilmProjectProgressReport;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<FilmProjectProgressReport>
*
* @method FilmProjectProgressReport|null find($id, $lockMode = null, $lockVersion = null)
* @method FilmProjectProgressReport|null findOneBy(array $criteria, array $orderBy = null)
* @method FilmProjectProgressReport[] findAll()
* @method FilmProjectProgressReport[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class FilmProjectProgressReportRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, FilmProjectProgressReport::class);
}
// /**
// * @return FilmProjectProgressReport[] Returns an array of FilmProjectProgressReport objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('f.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?FilmProjectProgressReport
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
public function findByYear(int $year, int $filmProjectId): ?FilmProjectProgressReport
{
$startDate = new \DateTime("$year-01-01 00:00:00");
$endDate = new \DateTime("$year-12-31 23:59:59");
return $this->createQueryBuilder('e')
->leftJoin('e.filmProject','f')
->andWhere('e.createdAt >= :startDate')
->andWhere('e.createdAt <= :endDate')
->andWhere('f.id = :filmProjectId')
->setParameter('startDate', $startDate)
->setParameter('endDate', $endDate)
->setParameter('filmProjectId', $filmProjectId)
->getQuery()
->getOneOrNullResult()
;
}
public function findAllByYear(int $year): array
{
$startDate = new \DateTime("$year-01-01 00:00:00");
$endDate = new \DateTime("$year-12-31 23:59:59");
return $this->createQueryBuilder('e')
->leftJoin('e.filmProject','f')
->andWhere('e.createdAt >= :startDate')
->andWhere('e.createdAt <= :endDate')
->setParameter('startDate', $startDate)
->setParameter('endDate', $endDate)
->getQuery()
->getResult()
;
}
public function findAllCompleted(): array
{
$completed = 'completed';
return $this->createQueryBuilder('e')
->andWhere('e.status = :status')
->setParameter('status', $completed)
->getQuery()
->getResult()
;
}
}