Commit 69181972 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge branch 'connor' into connor-trigger

parents a9bbf1e1 a72fabf5
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan

    public function index2Action()
    {
        $types = $this->getOrganizationService()->getOrganizationTypesSelect();
        $types = $this->getOrganizationService()->getOrganizationTypesSelectHierarchie2();


        $sorting = [
@@ -295,7 +295,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,
        );
+10 −1
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 = [];
+113 −14
Original line number Diff line number Diff line
@@ -652,18 +652,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 = [];
@@ -687,6 +699,60 @@ 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;
    }

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

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

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

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

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

    public function searchOrganizations(string $search, int $page, array $filters = []): array
    {
        $body = [
@@ -779,15 +857,19 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana

        // Filtre sur les types d'organisation
        if (array_key_exists('type', $filters)) {
            $types = $this->getOrganizationTypesSelect();
            $out = [];
            foreach ($types as $key=>$type) {
                if( in_array($key, $filters['type']) ){
                    $out[] = $type;
            $allTypes = $this->getEntityManager()->getRepository(OrganizationType::class)->findAll();
            $typesToSearchFor = [];
            foreach ($allTypes as $a) {
                foreach ($filters['type'] as $key) {
                    if ($a->getId() == $key) {
                        $this->addWithSubTypes2($typesToSearchFor, $a);
                        continue;
                    }
                }
            if(count($out)){
                $filtersQuery[] = ['terms' => ['typeorg' => $out]];
            }

            if(count($typesToSearchFor)){
                $filtersQuery[] = ['terms' => ['typeorg' => $typesToSearchFor]];
            }
        }

@@ -942,6 +1024,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
@@ -1033,15 +1127,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 = $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);
    }
  },

Loading