Commit b90cc8c7 authored by Thomas Hamel's avatar Thomas Hamel
Browse files

ajout de la possibilité de select le type d'étab (à partir des types déjà...

ajout de la possibilité de select le type d'étab (à partir des types déjà existants) pour un titre d'accès
parent 5a25a9e5
Loading
Loading
Loading
Loading
+6 −0
Changes for doc/release-notes/8.x.0/01_saisie_these.sql: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -255,6 +255,12 @@ WHERE unaccent(lower(t.lib_pays_cotut)) = unaccent(lower(p.libelle))
   OR (
    unaccent(lower(t.lib_pays_cotut)) = 'cote d ivoire' AND unaccent(lower(p.libelle)) = 'cote d''ivoire'
    )
   OR (
    unaccent(lower(t.lib_pays_cotut)) = replace(lower(p.libelle), '-', ' ')
    )
   OR (
    unaccent(lower(t.lib_pays_cotut)) = replace(lower(p.libelle_iso), '-', ' ')
    )
    RETURNING t.*
    )
SELECT * FROM updated_these;
+2 −1
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.TitreAcces.dcm.xml: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Application\Entity\Db\TitreAcces" table="TITRE_ACCES">
    <entity name="Application\Entity\Db\TitreAcces" table="TITRE_ACCES"
            repository-class="Application\Entity\Db\Repository\TitreAccesRepository">
        <id name="id" type="integer" column="id">
            <generator strategy="SEQUENCE"/>
        </id>
+19 −0
Changes for module/Application/src/Application/Entity/Db/Repository/TitreAccesRepository.php: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db\Repository;

class TitreAccesRepository extends DefaultEntityRepository
{
    /**
     * Récupérer les types distincts d'établissement (typeEtabTitreAcces)
     */
    public function findDistinctTypeEtabTitreAcces()
    {
        return $this->createQueryBuilder('ta')
            ->select('DISTINCT ta.typeEtabTitreAcces')
            ->where('ta.typeEtabTitreAcces IS NOT NULL')
            ->addOrderBy('ta.typeEtabTitreAcces', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
+4 −1
Changes for module/Application/src/Application/Entity/Db/TitreAcces.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -90,10 +90,13 @@ class TitreAcces implements HistoriqueAwareInterface
            );
        }

        //pour afficher les établissements provenant de thèse d'un SI
        $etabLibelle = $this->getEtablissement() ?: $this->getLibelleEtabTitreAcces();

        return sprintf("%s (%s), %s (%s)",
            $this->getLibelleTitreAcces(),
            $this->getTitreAccesInterneExterneToString(),
            $this->getEtablissement(),
            $etabLibelle,
            $etab
        );
    }
+39 −5
Changes for module/Application/src/Application/Service/TitreAcces/TitreAccesService.php: 39 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2,8 +2,7 @@

namespace Application\Service\TitreAcces;

use Application\Entity\Db\Pays;
use Application\Entity\Db\Repository\DefaultEntityRepository;
use Application\Entity\Db\Repository\TitreAccesRepository;
use Application\Entity\Db\TitreAcces;
use Application\Service\BaseService;
use Application\Service\Source\SourceServiceAwareTrait;
@@ -13,11 +12,11 @@ class TitreAccesService extends BaseService
    use SourceServiceAwareTrait;

    /**
     * @return DefaultEntityRepository
     * @return TitreAccesRepository
     */
    public function getRepository(): DefaultEntityRepository
    public function getRepository(): TitreAccesRepository
    {
        /** @var DefaultEntityRepository $repo */
        /** @var TitreAccesRepository $repo */
        $repo = $this->entityManager->getRepository(TitreAcces::class);

        return $repo;
@@ -34,4 +33,39 @@ class TitreAccesService extends BaseService

        return $titreAcces;
    }

    /**
     * Récupérer les types distincts pour les utiliser dans un formulaire select
     */
    public function getTypeEtabOptions(): array
    {
        $distinctTypes = $this->getRepository()->findDistinctTypeEtabTitreAcces();

        $normalizedResults = [];
        $filteredResults = [];

        foreach ($distinctTypes as $row) {
            $normalizedValue = strtolower($this->removeAccents($row['typeEtabTitreAcces']));

            if (!in_array($normalizedValue, $normalizedResults)) {
                $normalizedResults[] = $normalizedValue;
                $filteredResults[] = $row;
            }
        }

        $options = [];
        foreach ($filteredResults as $type) {
            $options[$type['typeEtabTitreAcces']] = $type['typeEtabTitreAcces'];
        }

        return $options;
    }

    private function removeAccents($string): array|string
    {
        $search = ['à', 'â', 'ä', 'á', 'ã', 'å', 'é', 'è', 'ê', 'ë', 'í', 'ì', 'î', 'ï', 'ó', 'ò', 'ô', 'ö', 'õ', 'ú', 'ù', 'û', 'ü', 'ç', 'ñ'];
        $replace = ['a', 'a', 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'c', 'n'];

        return str_replace($search, $replace, $string);
    }
}
 No newline at end of file
Loading