src/Repository/SeoTexteReferencementDiplomeRepository.php line 85

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\SeoTexteReferencementDiplome;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use App\Service\Slugify;
  7. /**
  8.  * @method SeoTexteReferencementDiplome|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method SeoTexteReferencementDiplome|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method SeoTexteReferencementDiplome[]    findAll()
  11.  * @method SeoTexteReferencementDiplome[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class SeoTexteReferencementDiplomeRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registrySeoTexteReferencementDiplome::class);
  18.     }
  19.     // /**
  20.     //  * @return SeoTexteReferencementDiplome[] Returns an array of SeoTexteReferencementDiplome objects
  21.     //  */
  22.     /*
  23.     public function findByExampleField($value)
  24.     {
  25.         return $this->createQueryBuilder('s')
  26.             ->andWhere('s.exampleField = :val')
  27.             ->setParameter('val', $value)
  28.             ->orderBy('s.id', 'ASC')
  29.             ->setMaxResults(10)
  30.             ->getQuery()
  31.             ->getResult()
  32.         ;
  33.     }
  34.     */
  35.     public function getTitreEtTexte($formation$filiere null$diplome null$lieu null): ?array
  36.     {
  37.         $ret =  [nullnull];
  38.         // Gérer uniquement le cas où on a des diplomes, c-a-d lycee/pro/sup
  39.         if ($formation == null or $formation == '' or $formation == '%')
  40.             return $ret;
  41.         // ATT : $formation se termine par "-", il faut l'enlever, !! s'il existe à la fin !!
  42.         if (substr($formation, -1) == "-")
  43.             $formation substr($formation0, -1);
  44.         $q $this->createQueryBuilder('s');
  45.         // if ($formation) {
  46.         //     $q->andWhere('s.formation = :p1');
  47.         //     $q->setParameter('p1', $formation);
  48.         // }
  49.         //
  50.         // if ($filiere) {
  51.         //     $q->andWhere('s.secteur = :p2');
  52.         //     $q->setParameter('p2', $filiere);
  53.         // } else {
  54.         //     $q->andWhere('s.secteur = \'\'');
  55.         // }
  56.         if ($diplome) {
  57.             $q->andWhere('s.diplome = :p3');
  58.             $q->setParameter('p3'$diplome);
  59.         } elseif ($filiere) {
  60.             $q->andWhere('s.secteur = :p2');
  61.             $q->setParameter('p2'$filiere);
  62.             $q->andWhere('s.diplome IS NULL');
  63.             // $q->andWhere('s.diplome = \'\'');
  64.         } elseif ($formation) {
  65.             $q->andWhere('s.formation = :p1');
  66.             $q->setParameter('p1'$formation);
  67.             $q->andWhere('s.diplome IS NULL');
  68.             $q->andWhere('s.secteur IS NULL');
  69.             // $q->andWhere('s.diplome = \'\'');
  70.             // $q->andWhere('s.secteur = \'\'');
  71.         }
  72.         $res $q->getQuery()->enableResultCache(3600)->getResult();
  73.         if ($res) {
  74.             if($lieu && $lieu->getSlug() != 'default') {
  75.                 $className get_class($lieu); //  if(in_array($className, ['Region', 'Departement', 'Ville']));
  76.                 if(strpos($className"Region") !== false) {
  77.                     $ret =  [
  78.                                 $res[0]->getTitreRegional(),
  79.                                 sprintf("<!-- p#REG#%s -->%s"$res[0]->getId(), $res[0]->getTexteRegional())
  80.                             ];
  81.                 } elseif(strpos($className"Departement") !== false) {
  82.                     $ret =  [
  83.                                 $res[0]->getTitreDepartemental(),
  84.                                 sprintf("<!-- p#DPT#%s -->%s"$res[0]->getId(), $res[0]->getTexteDepartemental())
  85.                             ];
  86.                 } elseif(strpos($className"Ville") !== false) {
  87.                     $ret =  [
  88.                                 $res[0]->getTitreVille(),
  89.                                 sprintf("<!-- p#VIL#%s -->%s"$res[0]->getId(), $res[0]->getTexteVille())
  90.                             ];
  91.                 }
  92.             } else {
  93.                 $ret =  [
  94.                             $res[0]->getTitreNational(),
  95.                             sprintf("<!-- p#NAT#%s -->%s"$res[0]->getId(), $res[0]->getTexteNational())
  96.                         ];
  97.             }
  98.         }
  99.         return $ret;
  100.     }
  101. }