src/Repository/BFEditionRepository.php line 144

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\BFEdition;
  4. use App\Entity\BFSubscription;
  5. use App\Entity\BFUser;
  6. use App\Object\FestivalSearch;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\ORM\Query\Expr;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. /**
  11.  * @method BFEdition|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method BFEdition|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method BFEdition[]    findAll()
  14.  * @method BFEdition[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class BFEditionRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryBFEdition::class);
  21.     }
  22.     
  23.     /**
  24.     * @return BFEdition[]
  25.     */
  26.     public function findNearestIsactive(bool $isactive=trueint $maxnumber=9): array
  27.     {
  28.         $qb $this->createQueryBuilder('e')
  29.             ->andwhere('e.isactive = :isactive')
  30.             ->andWhere('e.startdate >= :now OR :now BETWEEN e.startdate AND e.enddate')
  31.             ->setParameter('isactive'$isactive)
  32.             ->setParameter('now'date('Y-m-d'))
  33.             ->orderBy('e.startdate''ASC')
  34.             ->addOrderBy('e.enddate''ASC');
  35.         
  36.         $query $qb->getQuery();
  37.         
  38.         $query->setMaxResults($maxnumber);
  39.         
  40.         return $query->execute();
  41.     }
  42.     
  43.     /**
  44.     * @return BFEdition[]
  45.     */
  46.     public function findNearestSubscriptions(BFUser $userbool $isactive=trueint $maxnumber=3): array
  47.     {
  48.         $qb $this->createQueryBuilder('e')
  49.             ->innerJoin(BFSubscription::class, 's''WITH''e.festival = s.festival')
  50.             ->andwhere('e.isactive = :isactive')
  51.             ->andWhere('e.startdate >= :now OR :now BETWEEN e.startdate AND e.enddate')
  52.             ->andWhere('s.user = :user')
  53.             ->setParameter('isactive'$isactive)
  54.             ->setParameter('now'date('Y-m-d'))
  55.             ->setParameter('user'$user)
  56.             ->orderBy('e.startdate''ASC')
  57.             ->addOrderBy('e.enddate''ASC');
  58.         
  59.         $query $qb->getQuery();
  60.         
  61.         $query->setMaxResults($maxnumber);
  62.         
  63.         return $query->execute();
  64.     }
  65.     
  66.     /**
  67.     * @return BFEdition[]
  68.     */
  69.     public function findAllSubscriptions(BFUser $userbool $isactive=true): array
  70.     {
  71.         $qb $this->createQueryBuilder('e')
  72.             ->innerJoin(BFSubscription::class, 's''WITH''e.festival = s.festival')
  73.             ->andwhere('e.isactive = :isactive')
  74.             ->andWhere('e.startdate >= :now OR :now BETWEEN e.startdate AND e.enddate')
  75.             ->andWhere('s.user = :user')
  76.             ->setParameter('isactive'$isactive)
  77.             ->setParameter('now'date('Y-m-d'))
  78.             ->setParameter('user'$user)
  79.             ->orderBy('e.startdate''ASC')
  80.             ->addOrderBy('e.enddate''ASC');
  81.         
  82.         $query $qb->getQuery();
  83.                 
  84.         return $query->execute();
  85.     }
  86.     
  87.     /**
  88.     * @return BFEdition[]
  89.     */
  90.     public function findAllPossible(FestivalSearch $festivalsearch): array
  91.     {
  92.         $qb $this->createQueryBuilder('e')
  93.                 ->andwhere('e.isactive = :isactive')
  94.                 ->andWhere('e.startdate >= :now OR :date BETWEEN e.startdate AND e.enddate')
  95.                 ->orderBy('e.startdate''ASC')
  96.                 ->addOrderBy('e.enddate''ASC')
  97.                 ->setParameter('isactive'true);
  98.                 
  99.         
  100.         if($festivalsearch->hasLocation())
  101.         {
  102.             $location explode(','$festivalsearch->getLocation())[0];
  103.             
  104.             if($festivalsearch->getPlaceid()!=null)
  105.             {
  106.                 $qb->andwhere('e.placeid is not null OR e.location LIKE :location');
  107.             }
  108.             else
  109.             {
  110.                 $qb->andwhere('e.location LIKE :location');
  111.             }
  112.             
  113.             $qb->setParameter('location''%'.$location.'%');            
  114.         }        
  115.         
  116.         if($festivalsearch->hasDate())
  117.         {
  118.             $datetime \DateTime::createFromFormat('d/m/Y',$festivalsearch->getDate());
  119.             $nowdatetime\DateTime::createFromFormat('d/m/Y'date('d/m/Y'));
  120.             if($datetime<$nowdatetime)
  121.             {
  122.                 $qb->setParameter('now'date('Y-m-d'));
  123.             }
  124.             else
  125.             {
  126.                 $qb->setParameter('now'$datetime->format('Y-m-d'));
  127.             }
  128.             
  129.             $qb->setParameter('date'$datetime->format('Y-m-d'));
  130.         }
  131.         else
  132.         {
  133.             $qb->setParameter('now'date('Y-m-d'));
  134.             $qb->setParameter('date'date('Y-m-d'));
  135.         }
  136.         
  137.                 
  138.         $query $qb->getQuery();
  139.                 
  140.         return $query->execute();
  141.     }
  142.     
  143.     // /**
  144.     //  * @return BFEdition[] Returns an array of BFEdition objects
  145.     //  */
  146.     /*
  147.     public function findByExampleField($value)
  148.     {
  149.         return $this->createQueryBuilder('b')
  150.             ->andWhere('b.exampleField = :val')
  151.             ->setParameter('val', $value)
  152.             ->orderBy('b.id', 'ASC')
  153.             ->setMaxResults(10)
  154.             ->getQuery()
  155.             ->getResult()
  156.         ;
  157.     }
  158.     */
  159.     /*
  160.     public function findOneBySomeField($value): ?BFEdition
  161.     {
  162.         return $this->createQueryBuilder('b')
  163.             ->andWhere('b.exampleField = :val')
  164.             ->setParameter('val', $value)
  165.             ->getQuery()
  166.             ->getOneOrNullResult()
  167.         ;
  168.     }
  169.     */
  170. }