Commit 5c37e8ce authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

Ajout gestion de la hiérarchie des types d'organisations. Redmine #65733.

parent 9a73ed89
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            'direction'  => $direction,
            'directions' => $directions,
            'search'     => $search,
            'types'      => $this->getOrganizationService()->getOrganizationTypesSelect(),
            'types'      => $this->getOrganizationService()->getOrganizationTypesSelectHierarchie(),
            'type'       => $type,
            'active'     => $active,
        );
+11 −2
Original line number Diff line number Diff line
@@ -48,7 +48,16 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input
        $typesSelect[] = "";

        foreach ($this->types as $id => $t) {
            $typesSelect[$id] = (string)$t;
            $prefix = "";
            $tmpt = $t;
            while ($tmpt->getRoot()) {
                $prefix .= "      ";
                $tmpt = $tmpt->getRoot();
            }
            if ($prefix != "") {
                $prefix .= ' - ';
            }
            $typesSelect[$id] = $prefix . (string)$t;
        }

        $typesEtablissementPcruSelect = [];
+60 −7
Original line number Diff line number Diff line
@@ -637,18 +637,30 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        return $types;
    }

    private function addSubOrganizationTypes(&$options, $types, $type) {
        foreach ($types as $subtype) {
            if ($subtype->getRoot() != null && $subtype->getRoot()->getId() != $subtype->getId() && $subtype->getRoot()->getId() == $type->getId()) {
                $options[$subtype->getId()] = $subtype;
                $this->addSubOrganizationTypes($options, $types, $subtype);
            }
        }
    }

    public function getOrganizationTypesObject()
    {
        $options = [];

        $types = $this->getEntityManager()->getRepository(OrganizationType::class)->findBy([], ['label' => 'ASC']);
        foreach ($types as $type) {
            if ($type->getRoot()) {
                continue;
            }
            $options[$type->getId()] = $type;
            $this->addSubOrganizationTypes($options, $types, $type);
        }
        return $options;
    }


    public function getOrganizationTypesEtablissementPcruObject()
    {
        $options = [];
@@ -671,6 +683,30 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        return $options;
    }

    private function addSubOrganizationTypesSelectHierarchie(&$options, $types, $type, $prefix) {
        foreach ($types as $subtype) {
            if ($subtype->getRoot() != null && $subtype->getRoot()->getId() != $subtype->getId() && $subtype->getRoot()->getId() == $type->getId()) {
                $options[$subtype->getId()] = $prefix . ' - ' . (string)$subtype;
                $this->addSubOrganizationTypesSelectHierarchie($options, $types, $subtype, $prefix . '    ');
            }
        }
    }

    public function getOrganizationTypesSelectHierarchie()
    {
        $options = [];

        $types = $this->getEntityManager()->getRepository(OrganizationType::class)->findBy([], ['label' => 'ASC']);
        foreach ($types as $type) {
            if ($type->getRoot()) {
               continue;
            }
            $options[$type->getId()] = (string)$type;
            $this->addSubOrganizationTypesSelectHierarchie($options, $types, $type, '    ');
        }
        return $options;
    }

    public function searchUpdate(Organization $organization): void
    {
        $this->updateIndex($organization);
@@ -821,6 +857,18 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        return $qb;
    }

    private function addWithSubTypes(&$typesToSearchFor, $type) {
        foreach ($typesToSearchFor as $t) {
            if ($t->getId() == $type->getId()) {
                return;
            }
        }
        $typesToSearchFor[] = $type;
        foreach ($type->getChildren() as $c) {
            $this->addWithSubTypes($typesToSearchFor, $c);
        }
    }

    public function getSearchQuery($search, $filter)
    {
        // Path 2024/12/09
@@ -912,15 +960,20 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
            }

            if (count($cleanTypes) > 0) {
                $types = $this->getEntityManager()->getRepository(OrganizationType::class)->createQueryBuilder('t')
                    ->where('t.id IN (:types)')
                    ->setParameter('types', $cleanTypes)
                    ->getQuery()
                    ->getResult();
                $allTypes = $types = $this->getEntityManager()->getRepository(OrganizationType::class)->findAll();
                $typesToSearchFor = [];
                foreach ($allTypes as $a) {
                    foreach ($cleanTypes as $c) {
                        if ($a->getId() == $c) {
                            $this->addWithSubTypes($typesToSearchFor, $a);
                            continue;
                        }
                    }
                }

                $qb->leftJoin('o.typeObj', 't')
                    ->andWhere('t.id IN(:type)')
                    ->setParameter('type', $types);
                    ->setParameter('type', $typesToSearchFor);
            }
        }

+2 −2
Original line number Diff line number Diff line
<section class="container">
    <h1>
        <i class="icon-building-filled"></i>
        Gestion des types d'oganisation
        Gestion des types d'organisation
    </h1>
    <div id="admintypeorganization"
         data-url="<?= $this->url('administration/organizationtype') ?>"
+20 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
            <label for="form_label">Sous Type de : </label>
            <select name="root_id" id="" v-model="formData.root_id" class="form-control">
              <option value="">Aucun</option>
              <option :value="type.id" v-for="(type, i) in organizationtypes" >{{ type.label }}</option>
              <option :value="type.id" v-for="(type, i) in filterOrganizationtypesFlat(formData.id)" >{{ type.label }}</option>
            </select>
          </div>
          <div class="form-group">
@@ -81,6 +81,7 @@ export default {
  data() {
    return {
      organizationtypes: [],
      organizationtypesflat: [],
      error: null,
      pendingMsg: "",
      formData: null,
@@ -128,6 +129,13 @@ export default {
      };
    },

    addSubOrga(o, prefix) {
      for (let s of o.children) {
        this.organizationtypesflat.push({label: prefix + ' - ' + s.label, id: s.id});
        this.addSubOrga(s, prefix + '    ');
      }
    },

    /**
     * Chargement des jalons depuis l'API
     */
@@ -139,12 +147,22 @@ export default {
      axios.get(this.url).then(
          success => {
            this.organizationtypes = success.data.organizationtypes;
            this.organizationtypesflat = [];
            for (let o of this.organizationtypes) {
              this.organizationtypesflat.push({label: o.label, id: o.id});
              this.addSubOrga(o, '    ');
            }

            console.log("SUCCESS", success);
          },
          error => {
            this.error = "Impossible de charger les types d'oganisations : " + error.body
          }
      ).then(n => { this.pendingMsg = ""; });
    },

    filterOrganizationtypesFlat(idToExclude) {
      return this.organizationtypesflat.filter(o => o.id != idToExclude);
    }
  },