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

...

parent fceb1946
Loading
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -38,6 +38,13 @@ return [
                        AutoformformulairePrivileges::FORMULAIRE_INDEX,
                    ],
                ],
                [
                    'controller' => FormulaireController::class,
                    'action' => [
                        'formulairechamps',
                    ],
                    'roles' => [],
                ],
                [
                    'controller' => FormulaireController::class,
                    'action' => [
@@ -81,7 +88,7 @@ return [
                        'bouger-champ',
                        'swap-champ',

                        'creer-instance'
                        'creer-instance',
                    ],
                    'privileges' => [
                        AutoformformulairePrivileges::FORMULAIRE_MODIFIER,
@@ -112,6 +119,17 @@ return [

    'router' => [
        'routes' => [
            'formulairechamps' => [
                'type' => Segment::class,
                'may_terminate' => true,
                'options' => [
                    'route'    => '/formulairechamps[/:formulaire]',
                    'defaults' => [
                        'controller' => FormulaireController::class,
                        'action'     => 'formulairechamps',
                    ],
                ],
            ],
            'autoform' => [
                'child_routes' => [
                    'formulaires' => [
@@ -136,7 +154,17 @@ return [
                            ],
                        ],
                    ],

                    'merde' => [
                        'type' => Segment::class,
                        'may_terminate' => true,
                        'options' => [
                            'route'    => '/merde[/:formulaire]',
                            'defaults' => [
                                /** @see FormulaireController::getChampsAction() */
                                'action'     => 'merde',
                            ],
                        ],
                    ],
                    'formulaire' => [
                        'type' => Segment::class,
                        'may_terminate' => false,
+35 −0
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ namespace UnicaenAutoform\Controller;
use JetBrains\PhpStorm\NoReturn;
use Laminas\Http\Request;
use Laminas\Http\Response;
use Laminas\Json\Json;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\JsonModel;
use Laminas\View\Model\ViewModel;
use UnicaenAutoform\Entity\Db\Categorie;
use UnicaenAutoform\Entity\Db\Champ;
@@ -493,4 +495,37 @@ class FormulaireController extends AbstractActionController

        return $this->redirect()->toRoute('autoform/formulaire/afficher-formulaire', ['formulaire' => $formulaire->getId(), 'instance' => $instance->getId()], [], true);
    }

    public function formulairechampsAction(): JsonModel
    {
        $formulaire = $this->getFormulaireService()->getRequestedFormulaire($this);
        if ($formulaire === null) { return new JsonModel([]);}

        $result = [];
        $categories = $formulaire->getCategories();
        $categories = array_filter($categories, function (Categorie $c) {return $c->estNonHistorise(); });
        usort($categories, function (Categorie $a,Categorie $b) { return $a->getOrdre() <=> $b->getOrdre(); });

        foreach ($categories as $categorie) {
            $categorieJson = [
                'label' => $categorie->getLibelle(),
                'options' => [],
            ];

            $champs = $categorie->getChamps();
            $champs = array_filter($champs, function (Champ $c) {return $c->estNonHistorise(); });
            usort($champs, function (Champ $a,Champ $b) { return $a->getOrdre() <=> $b->getOrdre(); });

            foreach ($champs as $champ) {
                $categorieJson['options'][] = [
                    'value' => $champ->getId(),
                    'text' => $champ->getLibelle(),
                ];
            }

            $result[] = $categorieJson;
        }

        return new JsonModel($result);
    }
}
 No newline at end of file