src/Repository/ItemsInsertionRepository.php line 61

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (C) Office National de Publication et de Communication - All Rights Reserved
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited by law
  7.  * This file is proprietary and confidential
  8.  */
  9. namespace App\Repository;
  10. use App\Entity\ItemsInsertion;
  11. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. /**
  14.  * @method null|ItemsInsertion find($id, $lockMode = null, $lockVersion = null)
  15.  * @method null|ItemsInsertion findOneBy(array $criteria, array $orderBy = null)
  16.  * @method ItemsInsertion[]    findAll()
  17.  * @method ItemsInsertion[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  18.  */
  19. final class ItemsInsertionRepository extends ServiceEntityRepository
  20. {
  21.     public function __construct(ManagerRegistry $registry)
  22.     {
  23.         parent::__construct($registryItemsInsertion::class);
  24.     }
  25.     public function getDiplomes($niveau null, array $filieres null) {
  26.         $q $this->createQueryBuilder('ii');
  27.         if ($filieres != null) {
  28.             $sql "";
  29.             $n count($filieres);
  30.             $i 0;
  31.             foreach ($filieres as $filiere) {
  32.                 $sql .= " ii.pere LIKE '$filiere%' ";
  33.                 if(++$i $n)
  34.                     $sql .= " OR ";
  35.             }
  36.             $q->andWhere($sql);
  37.         } else {
  38.             $q->andWhere('ii.id LIKE :niveau');
  39.             $q->setParameter('niveau'$niveau '%');
  40.         }
  41.         return $q->groupBy('ii.identifiant')->getQuery()->enableResultCache(3600)->getResult();
  42.     }
  43.     public function getDiplomeLibelle($niveau) {
  44.         return $this->createQueryBuilder('ii')
  45.             ->andWhere(" ii.identifiant LIKE :niveau ")
  46.             ->orWhere("ii.slug LIKE :niveau ")
  47.             ->setParameter('niveau'$niveau '%')
  48.             ->setMaxResults(1)
  49.             ->getQuery()
  50.             ->enableResultCache(3600)
  51.             ->getOneOrNullResult()
  52.         ;
  53.     }
  54.     public function getDiplomePlus(int $limit 20): array
  55.     {
  56.         $builder $this->createQueryBuilder('ii');
  57.         $builder
  58.             ->select('ii')
  59.             ->andWhere('ii.diplomePlus = 1')
  60.             ->setMaxResults($limit)
  61.             ->orderBy('RAND()')
  62.         ;
  63.         return $builder
  64.             ->getQuery()
  65.             ->getResult();
  66.     }
  67.     public function getDiplomePlusByEtablissements($etabs): array
  68.     {
  69.         $builder $this->createQueryBuilder('ii');
  70.         $builder
  71.             ->select('ii')
  72.             ->andWhere('ii.etablissement IN (:etabs)')
  73.             ->andWhere('ii.diplomePlus = 1')
  74.             ->setParameter('etabs'$etabs)
  75.             ->orderBy('RAND()')
  76.         ;
  77.         return $builder
  78.             ->getQuery()
  79.             ->enableResultCache(3600)
  80.             ->getResult();
  81.     }
  82. }