Commit c722c14e authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Nouvel élément de formulaire dédié aux structures

parent 9c50c754
Loading
Loading
Loading
Loading
+1
Changes for module/Lieu/config/structure.config.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -95,5 +95,6 @@ return [

    'forms' => [
        Form\StructureSaisieForm::class => Form\StructureSaisieFormFactory::class,
        Form\Element\Structure::class   => Form\Element\StructureFactory::class,
    ],
];
+60
Changes for module/Lieu/src/Form/Element/Structure.php: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Lieu\Form\Element;

use Doctrine\Common\Collections\Collection;
use Laminas\Form\Element\Select;
use Lieu\Service\StructureServiceAwareTrait;
use Lieu\Entity\Db\Structure as StructureEntity;

class Structure extends Select
{
    use StructureServiceAwareTrait;

    private array $optionsBuilding = [];

    public function init()
    {
        parent::init();

        $this->setLabel('Structure');
        $this->setAttribute('class', 'selectpicker');
        $this->setAttribute('data-live-search', 'true');
        $this->setEmptyOption('- Aucune -');
        $this->populateOptions();
    }



    protected function populateOptions()
    {
        $this->optionsBuilding = [];

        $tree = $this->getServiceStructure()->getTree();
        $this->subPopulate($tree, 1);

        $this->setValueOptions($this->optionsBuilding);
        $this->optionsBuilding = [];
    }



    /**
     * @param array|StructureEntity[] $structures
     * @param int $level
     * @return void
     */
    protected function subPopulate(array|Collection $structures, int $level)
    {
        foreach($structures as $structure){
            $this->optionsBuilding[$structure->getId()] = [
                'value' => $structure->getId(),
                'label' => $structure->getLibelleCourt(),
                'attributes' => [
                    'style' => 'padding-left:'.(($level-1)*2+1).'em',
                ],
            ];
            $this->subPopulate($structure->getStructures(), $level + 1);
        }
    }
}
 No newline at end of file
+x+16
Changes for module/Lieu/src/Form/Element/StructureFactory.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Lieu\Form\Element;

use Psr\Container\ContainerInterface;

class StructureFactory
{

    public function __invoke(ContainerInterface $container, $requestedName, $options = null)
    {
        $element = new Structure();

        return $element;
    }
}
 No newline at end of file
+2 −21
Changes for module/Paiement/src/Form/CentreCout/CentreCoutStructureSaisieForm.php: 2 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Application\Form\AbstractForm;
use Application\Service\Traits\SourceServiceAwareTrait;
use Laminas\Form\Element\Csrf;
use Laminas\Hydrator\HydratorInterface;
use Lieu\Form\Element\Structure;
use Lieu\Service\StructureServiceAwareTrait;
use Paiement\Service\CentreCoutServiceAwareTrait;
use Paiement\Service\CentreCoutStructureServiceAwareTrait;
@@ -36,17 +37,8 @@ class CentreCoutStructureSaisieForm extends AbstractForm

        $this->add([
            'name'       => 'structure',
            'options'    => [
                'label' => 'Structure',
            ],
            'attributes' => [
                'class'            => 'selectpicker',
                'data-live-search' => 'true',
            ],
            'type'       => 'Select',
            'type'       => Structure::class,
        ]);
        $this->get('structure')
            ->setValueOptions(\UnicaenApp\Util::collectionAsOptions($this->getStructures()));

        $this->add(new Csrf('security'));
        $this->add([
@@ -63,17 +55,6 @@ class CentreCoutStructureSaisieForm extends AbstractForm



    public function getStructures()
    {
        $serviceStructure = $this->getServiceStructure();
        $qb               = $serviceStructure->finderByHistorique();
        $structures       = $serviceStructure->getList($qb);

        return $structures;
    }



    /**
     * Should return an array specification compatible with
     * {@link Laminas\InputFilter\Factory::createInputFilter()}.