| Current Path : /var/www/v3.cesa.co.za/src/EventBundle/Repository/ |
| Current File : /var/www/v3.cesa.co.za/src/EventBundle/Repository/SchoolEventRepository.php |
<?php
namespace App\EventBundle\Repository;
use App\EventBundle\Entity\SchoolEvent;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<SchoolEvent>
*
* @method SchoolEvent|null find($id, $lockMode = null, $lockVersion = null)
* @method SchoolEvent|null findOneBy(array $criteria, array $orderBy = null)
* @method SchoolEvent[] findAll()
* @method SchoolEvent[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SchoolEventRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SchoolEvent::class);
}
public function findAllForAPI(int $limit = 0, int $offset = -1, $criteria = [])
{
$startDate = new \DateTime('now');
$startDate->modify('-1 years');
$qb = $this->createQueryBuilder('s')
->select('s.id')
->where('s.start_date >= :startDate')
->setParameter('startDate', $startDate)
// ->andWhere('s.cancelled = 0 OR s.cancelled IS NULL')
->orderBy('s.start_date', 'ASC');
if (isset($criteria['trainer_id']) && $criteria['trainer_id'] > 0) {
$qb->join('s.training_provider', 'tp')
->andWhere('tp.id = :trainer_id')
->setParameter('trainer_id', $criteria['trainer_id']);
}
if ($offset >= 0) {
$qb->setFirstResult($offset);
}
if ($limit > 0) {
$qb->setMaxResults($limit);
}
return $qb
->getQuery()
->setHint(\Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD, true)
->getArrayResult();
}
// /**
// * @return SchoolEvent[] Returns an array of SchoolEvent objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?SchoolEvent
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}