Commit 263c9bf4 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Recherche de thèses : amélioration de l'affichage et du tri des structures dans les filtres.

parent 095ca256
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ Journal des modifications
- [FIX] Utilisation de Structure::getCode() par getSourceCode() pour les établissements d'inscription (correction d'effets de bord des substitutions).
- [FIX] Module formation : élimination des ED historisées dans la liste des structures complémentaires ajoutables à une session.
- [FIX] Module formation : changement du type de retour dans le trait StructureAwareTrait.
- [FIX] Recherche de thèses : amélioration de l'affichage et du tri des structures dans les filtres.

7.0.0
-----
+100 −0
Changes for doc/release-notes/v7.0.1.md: 100 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -49,4 +49,104 @@ FROM information_schema.table_constraints tco
       JOIN information_schema.table_constraints rel_tco ON rco.unique_constraint_schema::name = rel_tco.constraint_schema::name AND rco.unique_constraint_name::name = rel_tco.constraint_name::name
WHERE tco.constraint_type::text = 'FOREIGN KEY'::text;

drop view if exists v_diff_structure;
drop view if exists src_structure;
create or replace view src_structure(id, source_code, code, source_id, type_structure_id, sigle, libelle) as
WITH pre AS (
  SELECT NULL::bigint AS id,
         tmp.source_code,
         ltrim(substr(tmp.source_code, strpos(tmp.source_code, '::')), ':')::varchar(64) AS code,
         src.id AS source_id,
         ts.id AS type_structure_id,
         nullif(trim(tmp.sigle), '')::varchar(64) as sigle,
         tmp.libelle
  FROM tmp_structure tmp
         JOIN type_structure ts ON ts.code::text = tmp.type_structure_id::text
         JOIN source src ON src.id = tmp.source_id
)
SELECT pre.id,
       pre.source_code,
       pre.code,
       pre.source_id,
       pre.type_structure_id,
       pre.sigle,
       pre.libelle
FROM pre;

create or replace function substit_update_substitution_if_exists(type character varying, p_npd character varying, p_substitue record) returns boolean
  language plpgsql
as $$declare
  v_count int;
  v_data record;
  v_substit_record record;
begin
  --
  -- Recherche et mise à jour de la substitution existante spécifiée par l'enregistrement substitué.
  --
  -- Retourne `true` s'il n'y a plus rien à faire (càd que le cas de l'enregistrement est traité) ;
  -- ou `false` dans le cas où il faudra rechercher si l'enregistrement est en doublon et doit faire l'objet
  -- d'une nouvelle substitution.
  --

  raise notice 'Recherche si l''enregistrement % est substitué...', p_substitue.id;

  execute format('select * from substit_%s where from_id = %s', type, p_substitue.id) into v_substit_record;
  if v_substit_record.to_id is null then
    raise notice '=> Aucune substitution trouvée.';
    return false;
  end if;

  if p_substitue.source_id = app_source_id() then
    raise notice '=> Oui mais l''enregistrement est dans la source application.';
    raise notice '=> Retrait de l''enregistrement et mise à jour du substituant...';
    perform substit_remove_from_substitution(type, v_substit_record.from_id, v_substit_record.to_id);
    return true;
  elseif v_substit_record.npd <> p_npd then
    raise notice '=> Oui mais le NPD de l''enregistrement (%) a changé par rapport à celui de la substitution (%).', p_npd, v_substit_record.npd;
    raise notice '=> Retrait de l''enregistrement et mise à jour du substituant...';
    perform substit_remove_from_substitution(type, v_substit_record.from_id, v_substit_record.to_id);
    return false;
  elseif v_substit_record.npd = p_npd then
    raise notice '=> Oui et le NPD de l''enregistrement égale celui de la substitution (%).', p_npd;
    raise notice '=> Mise à jour de l''enregistrement substituant...';
    execute format('select count(*) from substit_fetch_data_for_substituant_%s(%L) limit 1', type, p_npd) into v_count;
    if v_count = 0 then
      raise exception 'Impossible de mettre à jour le substituant car aucun doublon de type % trouvé avec le NPD %', type, p_npd;
    end if;
    execute format('select * from substit_fetch_data_for_substituant_%s(%L) limit 1', type, p_npd) into v_data;
    perform substit_update_substituant(type, v_substit_record.to_id, v_data);
    return true;
  end if;

  return false;
end
$$;

create or replace function substit_restore_substitue(type character varying, p_substitue_id bigint, p_substituant_id bigint) returns void
  language plpgsql
as $$declare
  v_message text;
  v_record record;
begin
  v_message = format('Restauration de l''ex-substitué %s dans %L : ', p_substitue_id, type);

  execute format('select * from %I where id = %s', type, p_substitue_id) into v_record;

  -- si le substitué historisé est trouvé, on le restaure
  if v_record.id is not null and v_record.histo_destruction is not null then
    execute format('update %I set histo_destruction = null, histo_destructeur_id = null where id = %s', type, p_substitue_id);
    v_message = v_message || 'dehistorisation ok.';
--     elsif v_record.id is not null and v_record.histo_destruction is null then
--         -- on ne devrait pas être dans ce cas, le substitué est censé avoir été historisé.
--         raise exception 'Anomalie rencontrée lors de la restauration de l''ex-substitué % dans % : il devrait être historisé', p_substitue_id, type;
  elsif v_record.id is null then
    -- le substitué n'est pas trouvé !
    raise exception 'Anomalie rencontrée lors de la restauration de l''ex-substitué % dans % : il est introuvable', p_substitue_id, type;
  end if;

  raise notice '%', v_message;

  perform substit_insert_log(type, 'SUBSTITE_RESTORE', p_substitue_id, p_substituant_id, null, v_message);
end
$$;
```
+1 −1
Changes for module/Application/src/Application/Controller/ListeDiffusionController.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ class ListeDiffusionController extends AbstractController

        /** @var EcoleDoctorale[] $ecolesDoctorales */
        $etablissements = $this->etablissementService->getRepository()->findAllEtablissementsInscriptions(true);
        $ecolesDoctorales = $this->structureService->findAllStructuresAffichablesByType(TypeStructure::CODE_ECOLE_DOCTORALE, 'libelle', false);
        $ecolesDoctorales = $this->structureService->findAllStructuresAffichablesByType(TypeStructure::CODE_ECOLE_DOCTORALE, 'structure.libelle', false);
        $codesRolesAvecTemoinsED = [
            Role::CODE_DOCTORANT => true,
            Role::CODE_DIRECTEUR_THESE => true,
+2 −2
Changes for module/Application/src/Application/Controller/StatistiqueController.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@ class StatistiqueController extends AbstractController
        $theses = null;

        /** TODO prendre les non substitué **/
        $ecoles = $this->getStructureService()->findAllStructuresAffichablesByType(TypeStructure::CODE_ECOLE_DOCTORALE, 'libelle');
        $unites = $this->getStructureService()->findAllStructuresAffichablesByType(TypeStructure::CODE_UNITE_RECHERCHE, 'libelle');
        $ecoles = $this->getStructureService()->findAllStructuresAffichablesByType(TypeStructure::CODE_ECOLE_DOCTORALE, 'structure.libelle');
        $unites = $this->getStructureService()->findAllStructuresAffichablesByType(TypeStructure::CODE_UNITE_RECHERCHE, 'structure.libelle');
        $etablissements = $this->getEtablissementService()->getRepository()->findAllEtablissementsInscriptions();

        /**
+2 −2
Changes for module/Application/src/Application/Service/Rapport/RapportSearchService.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -148,12 +148,12 @@ class RapportSearchService extends SearchService
    private function fetchEcolesDoctorales(): array
    {
        return $this->structureService->findAllStructuresAffichablesByType(
            TypeStructure::CODE_ECOLE_DOCTORALE, 'sigle', true);
            TypeStructure::CODE_ECOLE_DOCTORALE, 'structure.sigle');
    }

    private function fetchUnitesRecherches(): array
    {
        return $this->structureService->findAllStructuresAffichablesByType(TypeStructure::CODE_UNITE_RECHERCHE, 'code', false);
        return $this->structureService->findAllStructuresAffichablesByType(TypeStructure::CODE_UNITE_RECHERCHE, 'structure.code', false);
    }

    private function fetchOriginesFinancements(): array
Loading