Commit 0f2bbbc8 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

update_structures mettant à jour les ids et le flag "enseignement"

parent 0eaa1d2a
Loading
Loading
Loading
Loading
+17 −1
Changes for data/ddl/package/OSE_DIVERS/body.sql: 17 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -70,8 +70,9 @@ CREATE OR REPLACE PACKAGE BODY "OSE_DIVERS" AS



  PROCEDURE update_structure_ids IS
  PROCEDURE update_structures IS
  BEGIN
    -- mise à jour des listes d'IDs
    FOR str IN (
      SELECT
        id, COALESCE(ids,'-') oids,
@@ -86,6 +87,21 @@ CREATE OR REPLACE PACKAGE BODY "OSE_DIVERS" AS
        UPDATE structure SET ids = str.nids WHERE id = str.id;
      END IF;
    END LOOP;

    -- mise à 1 du témoin enseignement si deséléments sont dans la structure
    FOR str IN (
      SELECT DISTINCT
        ep.structure_id id
      FROM
        element_pedagogique ep
        JOIN structure str ON str.id = ep.structure_id
      WHERE
        ep.histo_destruction IS NULL
        AND str.enseignement = 0
    ) LOOP
        UPDATE structure SET enseignement = 1 WHERE id = str.id;
    END LOOP;

  END;


+1 −1
Changes for data/ddl/package/OSE_DIVERS/definition.sql: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ CREATE OR REPLACE PACKAGE "OSE_DIVERS" AS
  FUNCTION GET_OSE_UTILISATEUR_ID RETURN NUMERIC;
  FUNCTION GET_OSE_SOURCE_ID RETURN NUMERIC;

  PROCEDURE update_structure_ids;
  PROCEDURE update_structures;

  PROCEDURE intervenant_horodatage_service( INTERVENANT_ID NUMERIC, TYPE_VOLUME_HORAIRE_ID NUMERIC, REFERENTIEL NUMERIC, HISTO_MODIFICATEUR_ID NUMERIC, HISTO_MODIFICATION DATE );

+85 −45
Changes for module/Lieu/src/Service/StructureService.php: 85 added lines, 45 removed lines.
Original line number Diff line number Diff line
@@ -29,10 +29,6 @@ class StructureService extends AbstractEntityService
    use MiseEnPaiementServiceAwareTrait;
    use MiseEnPaiementIntervenantStructureServiceAwareTrait;

    /** @var Structure[] */
    private array $treeStructures;



    public function getEntityClass()
    {
@@ -62,36 +58,89 @@ class StructureService extends AbstractEntityService

    public function getTreeArray(): array
    {
        $tree = $this->getTree();

        $ta = [];
        foreach ($tree as $structure) {
            $ta[$structure->getId()] = $this->getStructureArray($structure);
        }

        return $ta;
    }



    /**
     * @return array|Structure[]
     */
    public function getTree(?Structure $root = null, bool $onlyEnseignement = false): array
    {
        $cStructure = $this->getServiceContext()->getStructure();

        if ($root && $cStructure) {
            if ($cStructure->inStructure($root)) {
                // le ROOT est une sous-structure des structures autorisées
                $root = $cStructure;
            }
            if (!$root->inStructure($cStructure)) {
                // le root n'est pas une sous-structure autorisée => liste vide
                return [];
            }
        } elseif (!$root && $cStructure) {
            // pas de root définie => on se base sur la structure du contexte
            $root = $cStructure;
        }

        if ($root) {
            $id = $root->getId();

            $pFilter = "AND p.ids LIKE '%-$id-%'";
            $strFilter = "AND str.ids LIKE '%-$id-%'";
            $subFilter = "AND sub.ids LIKE '%-$id-%'";
        } else {
            $pFilter = "";
            $strFilter = "";
            $subFilter = "";
        }

        if ($onlyEnseignement){
            $pFilter .= ' AND p.enseignement = true';
            $strFilter .= ' AND str.enseignement = true';
            $subFilter .= ' AND sub.enseignement = true';
        }

        $dql = "
        SELECT 
            s, src, sp
            str, p, sub
        FROM
            " . Structure::class . " s 
            JOIN s.source src
            LEFT JOIN s.structure sp WITH sp.histoDestruction IS NULL
        WHERE s.histoDestruction IS NULL 
        ORDER BY s.libelleCourt
            " . Structure::class . " str
            LEFT JOIN str.structure p WITH p.histoDestruction IS NULL $pFilter
            LEFT JOIN str.structures sub WITH sub.histoDestruction IS NULL $subFilter
        WHERE
            str.histoDestruction IS NULL
            $strFilter 
        ORDER BY
            str.libelleCourt
        ";

        $this->treeStructures = [];
        $query = $this->getEntityManager()->createQuery($dql);

        /** @var Structure[] $r */
        $r = $query->getResult();
        $this->treeStructures = [];
        foreach ($r as $str) {
            $this->treeStructures[$str->getId()] = $str;
        /** @var Structure[] $strs */
        $strs = $this->getEntityManager()->createQuery($dql)->getResult();
        $result = [];
        foreach ($strs as $str) {
            $found = false;
            foreach( $strs as $sstr){
                foreach($sstr->getStructures() as $ssstr){
                    if ($str == $ssstr){
                        $found = true; // trouvé comme sous-structure
                    }
                }
        unset($r);

        $ta = [];
        foreach ($this->treeStructures as $structure) {
            if (null === $structure->getStructure()) {
                $ta[$structure->getId()] = $this->getStructureArray($structure);
            }
            if (!$found) {
                $result[$str->getId()] = $str;
            }
        }

        return $ta;
        return $result;
    }


@@ -168,26 +217,6 @@ class StructureService extends AbstractEntityService



    /**
     *
     * @param QueryBuilder $qb
     * @param string $alias
     *
     * @return QueryBuilder
     */
    public function finderByContext(QueryBuilder $qb = null, $alias = null)
    {
        [$qb, $alias] = $this->initQuery($qb, $alias);

        if ($cStructure = $this->getServiceContext()->getStructure()) {
            $this->finderById($cStructure->getId(), $qb, $alias);
        }

        return $qb;
    }



    /**
     * Ne recherche que les structures où il y a des enseignements
     *
@@ -230,6 +259,17 @@ class StructureService extends AbstractEntityService



    public function save($entity)
    {
        parent::save($entity); // TODO: Change the autogenerated stub

        $this->getEntityManager()->getConnection()->executeStatement('BEGIN OSE_DIVERS.UPDATE_STRUCTURES(); END;');

        return $entity;
    }



    /**
     *
     * @param QueryBuilder|null $qb