src/Repository/ItemsRepository.php line 176

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Items;
  4. use Doctrine\ORM\Query;
  5. use App\Entity\Etablissement;
  6. use App\Entity\ItemsInsertion;
  7. use Doctrine\ORM\Query\Expr\Join;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  10. /**
  11.  * @method Items|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method Items|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method Items[]    findAll()
  14.  * @method Items[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class ItemsRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryItems::class);
  21.     }
  22.     // /**
  23.     //  * @return Items[] Returns an array of Items objects
  24.     //  */
  25.     /*
  26.     public function findByExampleField($value)
  27.     {
  28.         return $this->createQueryBuilder('i')
  29.             ->andWhere('i.exampleField = :val')
  30.             ->setParameter('val', $value)
  31.             ->orderBy('i.id', 'ASC')
  32.             ->setMaxResults(10)
  33.             ->getQuery()
  34.             ->getResult()
  35.         ;
  36.     }
  37.     */
  38.     /*
  39.     public function findOneBySomeField($value): ?Items
  40.     {
  41.         return $this->createQueryBuilder('i')
  42.             ->andWhere('i.exampleField = :val')
  43.             ->setParameter('val', $value)
  44.             ->getQuery()
  45.             ->getOneOrNullResult()
  46.         ;
  47.     }
  48.     */
  49.     public function getNiveaux($typeOnglet) {
  50.         switch ($typeOnglet) {
  51.             case 'ecole':
  52.                 $niveaux = [
  53.                     '01-MATER'  => "Maternelle",
  54.                     '02-ELEM'   => "Ecole élémentaire",
  55.                     '03-PRIM'   => "Les deux"
  56.                 ];
  57.                 break;
  58.             case 'professionnel':
  59.                 $niveaux = [
  60.                     'LYCPRO-CAP-'  => "CAP",
  61.                     'LYCPRO-BACP-' => "Bac Pro",
  62.                     'LYCPRO-FPC'   => "Formation Pro Continue"
  63.                 ];
  64.                 break;
  65.             default:
  66.                 $niveaux = [
  67.                     '000'  => "AUCUN !!!"
  68.                 ];
  69.                 break;
  70.         }
  71.         return $niveaux;
  72.     }
  73.     public function getFilieres($niveau null) {
  74.         return $this->createQueryBuilder('i')
  75.             ->join(ItemsInsertion::class, 'ii'Join::WITH'i.id = ii.pere')
  76.             ->andWhere("i.formation = 'oui'")
  77.             ->andWhere('i.niveau = 3')
  78.             ->andWhere('i.id LIKE :niveau')
  79. //            ->andWhere($queryBuilder->expr()->like('i.id', ':niveau'))
  80.             ->groupBy('i.id')
  81.             ->orderBy('i.libelle''ASC')
  82.             ->setParameter('niveau'$niveau '%')
  83.             ->getQuery()
  84.             ->enableResultCache(3600)
  85.             ->getResult()
  86.         ;
  87.     }
  88.     public function getFilieresFiltred($niveau null$idsFiltresContexte null) {
  89.         $q $this->createQueryBuilder('i')
  90.             ->join(ItemsInsertion::class, 'ii'Join::WITH'i.id = ii.pere')
  91.             ->andWhere("i.formation = 'oui'")
  92.             ->andWhere('i.niveau = 3')
  93.             ->andWhere('i.id LIKE :niveau');
  94.         if(!is_null($idsFiltresContexte)) {
  95.             $q->andWhere('i.id IN (:idsFiltresContexte)')
  96.                 ->setParameter('idsFiltresContexte'$idsFiltresContexte);
  97.         }
  98.         $q->groupBy('i.id')
  99.             ->orderBy('i.libelle''ASC')
  100.             ->setParameter('niveau'$niveau '%');
  101.         return $q->getQuery()
  102.             ->enableResultCache(3600)
  103.             ->getResult()
  104.         ;
  105.     }
  106.     public function getDiplomes($niveau null, array $filieres null$idsFiltresContexte null) {
  107.         $q $this->createQueryBuilder('i');
  108.         $q->join(ItemsInsertion::class, 'ii'Join::WITH'i.id = ii.identifiant');
  109.         $q->andWhere("i.formation = 'oui'");
  110.         $q->andWhere('i.niveau = 4');
  111.         if(!is_null($idsFiltresContexte)) {
  112.             $q->andWhere('i.id IN (:idsFiltresContexte)');
  113.             $q->setParameter('idsFiltresContexte'$idsFiltresContexte);
  114.         }   
  115.         if ($filieres != null) {
  116.             $sql "";
  117.             $n count($filieres);
  118.             $i 0;
  119.             foreach ($filieres as $filiere) {
  120.                 $sql .= " i.id LIKE '$filiere%' ";
  121.                 if(++$i $n)
  122.                     $sql .= " OR ";
  123.             }
  124.             $q->andWhere($sql);
  125.         } else {
  126.             $q->andWhere('i.id LIKE :niveau');
  127.             $q->setParameter('niveau'$niveau '%');
  128.         }
  129.         $q->orderBy('i.libelle''ASC');
  130.         return $q->getQuery()
  131.             ->enableResultCache(3600)
  132.             ->getResult();
  133.     }
  134.     /**
  135.      * Renvoi la liste des LVx(A/B/C == 1/2/3) selon le niveau : COLLège, LYCée ou LYCéePRO
  136.      * @param string $lvx LV1 | LV2 | LV3
  137.      * @param string $niveau COLL | LYC | LYCPRO
  138.      * @param array $idsLanguesContexte Liste d'ids de langues pour filtrer les langues
  139.      */
  140.     public function getLVx($lvx$niveau$idsLanguesContexte null) {
  141.         switch ($niveau) {
  142.             case 'college':         $codeNiveau "COLL";      break;            
  143.             case 'lycee':           $codeNiveau "LYC";       break;            
  144.             case 'professionnel':   $codeNiveau "LYCPRO";    break; 
  145.             default :               return null;           
  146.         }
  147.         $idLike = \sprintf("%s-LANG-%s-"$codeNiveau$lvx);
  148.         $qb $this->createQueryBuilder('i')
  149.             ->andWhere('i.niveau = 4')
  150.             ->andWhere('i.id LIKE :idLike')
  151.             ->orderBy('i.libelle''ASC')
  152.             ->setParameter('idLike'$idLike '%');
  153.         if(!is_null($idsLanguesContexte)) {            
  154.             $qb->andWhere('i.id IN (:idsLanguesContexte)');
  155.             $qb->setParameter('idsLanguesContexte'$idsLanguesContexte);
  156.         }
  157.         return $qb->getQuery()
  158.             ->enableResultCache(3600)
  159.             ->getResult()
  160.         ;
  161.     }
  162.     /**
  163.      * Renvoi la liste des Enseignements de spécialité
  164.      */
  165.     public function getEnseignementsDeSpecialite($idsEdsContexte null) {
  166.         $idLike "LYC-FORMA2021-SPEC-";
  167.         $qb $this->createQueryBuilder('i')
  168.             ->andWhere('i.niveau = 4')
  169.             ->andWhere('i.id LIKE :idLike')
  170.             ->orderBy('i.libelle''ASC')
  171.             ->setParameter('idLike'$idLike '%');
  172.         if(!is_null($idsEdsContexte)) {
  173.             $qb->andWhere('i.id IN (:idsEdsContexte)');
  174.             $qb->setParameter('idsEdsContexte'$idsEdsContexte);
  175.         }
  176.         return $qb
  177.             ->getQuery()
  178.             ->enableResultCache(3600)
  179.             ->getResult()
  180.         ;
  181.     }
  182.     /**
  183.      * Renvoi un Items[] en calculant le nbr d'étabs pour chaque item
  184.      * Identique à getFilieres
  185.      */
  186.     public function getFilieresWithTotal($niveau null) {
  187.         
  188.         $qb $this->createQueryBuilder('i');
  189.         $qb->select(
  190.                 'i.id,
  191.                 i.libelle,
  192.                 i.libelleMEP,
  193.                 i.texteDefaut,
  194.                 i.onglet,
  195.                 i.niveau,
  196.                 i.formation,
  197.                 i.options,
  198.                 i.id,
  199.                 i.maj,
  200.                 COUNT(DISTINCT e.id) AS total'
  201.             )
  202.             ->join(ItemsInsertion::class, 'ii'Join::WITH'i.id = ii.pere')
  203.             ->join(Etablissement::class, 'e'Join::WITH'ii.etablissement = e.id')
  204.             ->andWhere("i.formation = 'oui'")
  205.             ->andWhere('i.niveau = 3')
  206.             ->andWhere('i.id LIKE :niveau')
  207.             ->groupBy('i.id')
  208.             ->orderBy('i.libelle''ASC')
  209.             ->setParameter('niveau'$niveau '%');
  210.         $result $qb
  211.             ->getQuery()
  212.             ->enableResultCache(3600 2)
  213.             ->getResult();
  214.         // Hydrate the results to ensure they are `Item` entities with the `total` count
  215.         $arrayItems = [];
  216.         foreach ($result as $key => $row) {
  217.             $items = new Items();
  218.             foreach ($row as $itemAttribute => $itemValue) {
  219.                 $func="set" ucwords($itemAttribute);
  220.                 $items->$func($itemValue);
  221.             }
  222.             $arrayItems[] = $items;
  223.         }
  224.         return $arrayItems;
  225.     }
  226. }