<?php
namespace App\Repository;
use App\Entity\SeoTexteReferencementDiplome;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use App\Service\Slugify;
/**
* @method SeoTexteReferencementDiplome|null find($id, $lockMode = null, $lockVersion = null)
* @method SeoTexteReferencementDiplome|null findOneBy(array $criteria, array $orderBy = null)
* @method SeoTexteReferencementDiplome[] findAll()
* @method SeoTexteReferencementDiplome[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SeoTexteReferencementDiplomeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SeoTexteReferencementDiplome::class);
}
// /**
// * @return SeoTexteReferencementDiplome[] Returns an array of SeoTexteReferencementDiplome objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('s')
->andWhere('s.exampleField = :val')
->setParameter('val', $value)
->orderBy('s.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
public function getTitreEtTexte($formation, $filiere = null, $diplome = null, $lieu = null): ?array
{
$ret = [null, null];
// Gérer uniquement le cas où on a des diplomes, c-a-d lycee/pro/sup
if ($formation == null or $formation == '' or $formation == '%')
return $ret;
// ATT : $formation se termine par "-", il faut l'enlever, !! s'il existe à la fin !!
if (substr($formation, -1) == "-")
$formation = substr($formation, 0, -1);
$q = $this->createQueryBuilder('s');
// if ($formation) {
// $q->andWhere('s.formation = :p1');
// $q->setParameter('p1', $formation);
// }
//
// if ($filiere) {
// $q->andWhere('s.secteur = :p2');
// $q->setParameter('p2', $filiere);
// } else {
// $q->andWhere('s.secteur = \'\'');
// }
if ($diplome) {
$q->andWhere('s.diplome = :p3');
$q->setParameter('p3', $diplome);
} elseif ($filiere) {
$q->andWhere('s.secteur = :p2');
$q->setParameter('p2', $filiere);
$q->andWhere('s.diplome IS NULL');
// $q->andWhere('s.diplome = \'\'');
} elseif ($formation) {
$q->andWhere('s.formation = :p1');
$q->setParameter('p1', $formation);
$q->andWhere('s.diplome IS NULL');
$q->andWhere('s.secteur IS NULL');
// $q->andWhere('s.diplome = \'\'');
// $q->andWhere('s.secteur = \'\'');
}
$res = $q->getQuery()->enableResultCache(3600)->getResult();
if ($res) {
if($lieu && $lieu->getSlug() != 'default') {
$className = get_class($lieu); // if(in_array($className, ['Region', 'Departement', 'Ville']));
if(strpos($className, "Region") !== false) {
$ret = [
$res[0]->getTitreRegional(),
sprintf("<!-- p#REG#%s -->%s", $res[0]->getId(), $res[0]->getTexteRegional())
];
} elseif(strpos($className, "Departement") !== false) {
$ret = [
$res[0]->getTitreDepartemental(),
sprintf("<!-- p#DPT#%s -->%s", $res[0]->getId(), $res[0]->getTexteDepartemental())
];
} elseif(strpos($className, "Ville") !== false) {
$ret = [
$res[0]->getTitreVille(),
sprintf("<!-- p#VIL#%s -->%s", $res[0]->getId(), $res[0]->getTexteVille())
];
}
} else {
$ret = [
$res[0]->getTitreNational(),
sprintf("<!-- p#NAT#%s -->%s", $res[0]->getId(), $res[0]->getTexteNational())
];
}
}
return $ret;
}
}