Commit bcafd346 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Correction de requêtes concernant les listes de diff

parent b9e056c3
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -27,16 +27,16 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * Rôle concerné.
     *
     * @var string
     * @var string|null
     */
    protected $role;
    protected ?string $role = null;

    /**
     * Etablissement concerné éventuel.
     *
     * @var Etablissement
     */
    protected $etablissement;
    protected ?Etablissement $etablissement = null;

    /**
     * @inheritDoc
@@ -57,7 +57,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @inheritDoc
     */
    public function canHandleListeDiffusion()
    public function canHandleListeDiffusion(): bool
    {
        $this->parseAdresse();

@@ -79,7 +79,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
     *
     * @return string
     */
    public function createMemberIncludeFileContent()
    public function createMemberIncludeFileContent(): string
    {
        $entities = $this->fetchMembers();
        $this->extractEmailsFromEntities($entities);
@@ -90,7 +90,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @return Individu[]
     */
    protected function fetchMembers()
    protected function fetchMembers(): array
    {
        switch ($this->role) {
            case 'dirtheses':
@@ -111,7 +111,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @return Acteur[]
     */
    protected function fetchActeursDirecteursTheses()
    protected function fetchActeursDirecteursTheses(): array
    {
        $critereEd = $this->computeCritereED();

@@ -125,7 +125,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @return Doctorant[]
     */
    protected function fetchDoctorants()
    protected function fetchDoctorants(): array
    {
        $critereEd = $this->computeCritereED();

@@ -138,11 +138,11 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @return array|null
     */
    protected function computeCritereED()
    protected function computeCritereED(): ?array
    {
        if ($this->parserResult instanceof ListeDiffusionAddressParserResultWithED) {
            $sigleSansEspace = $this->parserResult->getEcoleDoctorale();
            return ["REPLACE(s.sigle,' ','')" => $sigleSansEspace];
            return ["REPLACE(%s.sigle,' ','')" => $sigleSansEspace];
        } elseif ($this->parserResult instanceof ListeDiffusionAddressParserResult) {
            return null;
        } else {
@@ -153,7 +153,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
    /**
     * @return Individu[]
     */
    protected function fetchIndividusWithRole()
    protected function fetchIndividusWithRole(): array
    {
        $code = strtoupper($this->role);
        $structure = $this->etablissement->getStructure();
@@ -167,7 +167,7 @@ class ListeDiffusionHandler extends ListeDiffusionAbstractHandler
     * @param string $prefix
     * @return string
     */
    public function generateResultFileName(string $prefix)
    public function generateResultFileName(string $prefix): string
    {
        return sprintf('%sinclude_%s.inc',
            $prefix,
+13 −3
Original line number Diff line number Diff line
@@ -52,10 +52,20 @@ class RoleService extends BaseService
     */
    public function findOneByCodeAndStructure(string $code, Structure $structure): ?Role
    {
        /** @var Role|null $role */
        $role = $this->getRepository()->findOneBy(['code' => $code, 'structure' => $structure]);
        $qb = $this->getRepository()->createQueryBuilder('r')
            ->andWhere('r.code = :code')
            ->setParameter('code', $code)
            ->leftJoin('r.structure', 's')->addSelect('s')
            ->leftJoin('s.structureSubstituante', 'structureSubstituante')->addSelect('structureSubstituante')
            ->andWhere('s = :structure OR structureSubstituante = :structure')
            ->setParameter('structure', $structure)
        ;

        return $role;
        try {
            return $qb->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Anomalie : Plusieurs Role ont été trouvés", null, $e);
        }
    }

    /**
+18 −11
Original line number Diff line number Diff line
@@ -73,29 +73,36 @@ class DoctorantRepository extends DefaultEntityRepository
            ->join('d.theses', 't', Join::WITH, 't.etatThese = :etat')->setParameter('etat', These::ETAT_EN_COURS)
            ->join('t.ecoleDoctorale', 'ed')
            ->join('ed.structure', 's')
            ->leftJoin('s.structureSubstituante', 'structureSubstituante')->addSelect('structureSubstituante')
            ->andWhere('d.histoDestruction is null')
            ->addOrderBy('i.nomUsuel')
            ->addOrderBy('i.prenom1');

        // l'ED ne doit pas être substituée
        $qb->addSelect('structureSubstituante')
            ->leftJoin("s.structureSubstituante", "structureSubstituante")
            ->andWhere("structureSubstituante is null");

        if ($ecoleDoctorale !== null) {
            if ($ecoleDoctorale instanceof EcoleDoctorale) {
                $qb->andWhere('ed = :ed');
                $qb
                    ->andWhere('s = :structure OR structureSubstituante = :structure')
                    ->setParameter('structure', $ecoleDoctorale->getStructure(false));
            } elseif (is_array($ecoleDoctorale)) {
                $qb->andWhere(key($ecoleDoctorale) . ' = :ed');
                $ecoleDoctorale = current($ecoleDoctorale);
                $leftPart = key($ecoleDoctorale);
                $rightPart = current($ecoleDoctorale);
                $qb
                    ->andWhere(sprintf($leftPart, 's') . ' = :value OR ' . sprintf($leftPart, 'structureSubstituante'). ' = :value')
                    ->setParameter('value', $rightPart);
            } else {
                $qb->andWhere('s.code = :ed');
                $qb
                    ->andWhere('s.code = :code OR structureSubstituante.code = :code')
                    ->setParameter('code', $ecoleDoctorale);
            }
            $qb->setParameter('ed', $ecoleDoctorale);
        }

        if ($etablissement !== null) {
            $qb->join('t.etablissement', 'e', Join::WITH, 'e = :etab')->setParameter('etab', $etablissement);
            $qb
                ->join('t.etablissement', 'e')->addSelect('e')
                ->join('e.structure', 'setab')->addSelect('setab')
                ->leftJoin('setab.structureSubstituante', 'structureSubstituanteEtab')->addSelect('structureSubstituanteEtab')
                ->andWhere('setab = :structureEtab OR structureSubstituanteEtab = :structureEtab')
                ->setParameter('structureEtab', $etablissement->getStructure(false));
        }

        return $qb->getQuery()->getResult();
+34 −11
Original line number Diff line number Diff line
@@ -155,31 +155,54 @@ class ActeurRepository extends DefaultEntityRepository
            ->join('a.these', 't', Join::WITH, 't.etatThese = :etat')->setParameter('etat', These::ETAT_EN_COURS)
            ->join('t.ecoleDoctorale', 'ed')
            ->join('ed.structure', 's')
            ->leftJoin('s.structureSubstituante', 'structureSubstituante')->addSelect('structureSubstituante')
            ->andWhere('a.histoDestruction is null')
            ->addOrderBy('i.nomUsuel')
            ->addOrderBy('i.prenom1');

        // l'ED ne doit pas être substituée
        $qb->addSelect('structureSubstituante')
            ->leftJoin("s.structureSubstituante", "structureSubstituante")
            ->andWhere("structureSubstituante is null");

        if ($ecoleDoctorale !== null) {
            if ($ecoleDoctorale instanceof EcoleDoctorale) {
                $qb->andWhere('ed = :ed');
                $qb
                    ->andWhere('s = :structure OR structureSubstituante = :structure')
                    ->setParameter('structure', $ecoleDoctorale->getStructure(false));
            } elseif (is_array($ecoleDoctorale)) {
                $qb->andWhere(key($ecoleDoctorale) . ' = :ed');
                $ecoleDoctorale = current($ecoleDoctorale);
                $leftPart = key($ecoleDoctorale);
                $rightPart = current($ecoleDoctorale);
                $qb
                    ->andWhere(sprintf($leftPart, 's') . ' = :value OR ' . sprintf($leftPart, 'structureSubstituante'). ' = :value')
                    ->setParameter('value', $rightPart);
            } else {
                $qb->andWhere('s.code = :ed');
                $qb
                    ->andWhere('s.code = :code OR structureSubstituante.code = :code')
                    ->setParameter('code', $ecoleDoctorale);
            }
            $qb->setParameter('ed', $ecoleDoctorale);
        }

        if ($etablissement !== null) {
            $qb->join('t.etablissement', 'e', Join::WITH, 'e = :etab')->setParameter('etab', $etablissement);
            $qb
                ->join('t.etablissement', 'e')->addSelect('e')
                ->join('e.structure', 'setab')->addSelect('setab')
                ->leftJoin('setab.structureSubstituante', 'structureSubstituanteEtab')->addSelect('structureSubstituanteEtab')
                ->andWhere('setab = :structureEtab OR structureSubstituanteEtab = :structureEtab')
                ->setParameter('structureEtab', $etablissement->getStructure(false));
        }

//        if ($ecoleDoctorale !== null) {
//            if ($ecoleDoctorale instanceof EcoleDoctorale) {
//                $qb->andWhere('ed = :ed');
//            } elseif (is_array($ecoleDoctorale)) {
//                $qb->andWhere(key($ecoleDoctorale) . ' = :ed');
//                $ecoleDoctorale = current($ecoleDoctorale);
//            } else {
//                $qb->andWhere('s.code = :ed');
//            }
//            $qb->setParameter('ed', $ecoleDoctorale);
//        }
//
//        if ($etablissement !== null) {
//            $qb->join('t.etablissement', 'e', Join::WITH, 'e = :etab')->setParameter('etab', $etablissement);
//        }

        return $qb->getQuery()->getResult();
    }