Commit c99d8f1f authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout d'un group option pour les structures

parent bd5c84ed
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class AgentMissionSpecifiqueForm extends Form {
            'options' => [
                'label' => "Structure :",
                'empty_option' => 'Sélectionner la structure à affecter ...',
                'value_options' => $this->getStructureService()->getStructuresAsOptions(),
                'value_options' => $this->getStructureService()->getStructuresAsGroupOptions(),
            ],
            'attributes' => [
                'id' => 'structure',
+14 −5
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ class StructureService
    }

    /**
     * @param bool $ouverte
     * @return array
     */
    public function getStructuresAsGroupOptions($ouverte = true)
@@ -87,13 +88,21 @@ class StructureService
        $structures = $this->getStructures($ouverte);

        $dictionnary = [];

        $result = $qb->getQuery()->getResult();
        foreach ($structures as $structure) {
            $dictionnary[$structure->getType()][] = $structure;
        }

        $options = [];
        /** @var Structure $item */
        foreach ($result as $item) {
            if ($item->getId() !== null) $options[$item->getId()] = $item->getLibelleLong();
        foreach ($dictionnary as $type => $structuresStored) {
            $optionsoptions = [];
            foreach ($structuresStored as $structure) {
                $optionsoptions[$structure->getId()] = $structure->getLibelleCourt();
            }
            $array = [
                'label' => $type,
                'options' => $optionsoptions,
            ];
            $options[] = $array;
        }
        return $options;
    }