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

autosave

parent 1a827462
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -2,10 +2,13 @@

namespace Autoform;

use Autoform\Controller\ChampController;
use Autoform\Controller\ChampControllerFactory;
use Autoform\Form\Champ\ChampForm;
use Autoform\Form\Champ\ChampFormFactory;
use Autoform\Form\Champ\ChampHydrator;
use Autoform\Form\Champ\ChampHydratorFactory;
use Autoform\Provider\Privilege\FormulairePrivileges;
use Autoform\Service\Champ\ChampService;
use Autoform\Service\Champ\ChampServiceFactory;
use Autoform\View\Helper\ChampAsInputHelperFactory;
@@ -16,16 +19,43 @@ use Autoform\View\Helper\InstanceAsFormulaireHelper;
use Autoform\View\Helper\InstanceAsTextHelper;
use Autoform\View\Helper\ValidationAsTextHelper;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Segment;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [],
            PrivilegeController::class => [
                [
                    'controller' => ChampController::class,
                    'action' => [
                        'sauver',
                    ],
                    'privileges' => [
                        FormulairePrivileges::MODIFIER,
                    ],
                ],

            ],
        ],
    ],

    'router' => [
        'routes' => [
            'autoform' => [
                'child_routes' => [
                    'champ' => [
                        'type' => Segment::class,
                        'may_terminate' => true,
                        'options' => [
                            'route'    => '/champ[/:instance/:champ]',
                            'defaults' => [
                                'controller' => ChampController::class,
                                'action' => 'sauver',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

@@ -35,7 +65,9 @@ return [
        ],
    ],
    'controllers'     => [
        'factories' => [],
        'factories' => [
            ChampController::class => ChampControllerFactory::class,
        ],
    ],
    'form_elements' => [
        'factories' => [
+0 −1
Original line number Diff line number Diff line
@@ -370,7 +370,6 @@ return [
        'factories' => [
            CategorieService::class => CategorieServiceFactory::class,
            FormulaireService::class => FormulaireServiceFactory::class,
            FormulaireInstanceService::class => FormulaireInstanceServiceFactory::class,
            FormulaireReponseService::class => FormulaireReponseServiceFactory::class,
        ],
    ],
+87 −0
Original line number Diff line number Diff line
<?php

namespace Autoform;

use Autoform\Controller\InstanceController;
use Autoform\Controller\InstanceControllerFactory;
use Autoform\Provider\Privilege\FormulairePrivileges;
use Autoform\Service\Formulaire\FormulaireInstanceService;
use Autoform\Service\Formulaire\FormulaireInstanceServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => InstanceController::class,
                    'action' => [
                        'modifier',
                    ],
                    'privileges' => [
                        FormulairePrivileges::MODIFIER,
                    ],
                ],

            ],
        ],
    ],

    'router' => [
        'routes' => [
            'autoform' => [
                'child_routes' => [
                    'instance' => [
                        'type' => Literal::class,
                        'may_terminate' => true,
                        'options' => [
                            'route'    => '/instance',
                        ],
                        'child_routes' => [
                            'modifier' => [
                                'type' => Segment::class,
                                'may_terminate' => true,
                                'options' => [
                                    'route'    => '/modifier/:instance',
                                    'defaults' => [
                                        'controller' => InstanceController::class,
                                        'action'     => 'modifier',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

    'service_manager' => [
        'factories' => [
            FormulaireInstanceService::class => FormulaireInstanceServiceFactory::class,
        ],
    ],
    'controllers'     => [
        'factories' => [
            InstanceController::class => InstanceControllerFactory::class,
        ],
    ],
    'form_elements' => [
        'factories' => [
        ],
    ],
    'hydrators' => [
        'factories' => [
        ],
    ],

    'view_helpers' => [
        'invokables' => [
        ],
        'factories' => [
        ],
    ],

];
 No newline at end of file
+42 −0
Original line number Diff line number Diff line
<?php

namespace Autoform\Controller;

use Autoform\Entity\Db\FormulaireReponse;
use Autoform\Service\Champ\ChampServiceAwareTrait;
use Autoform\Service\Formulaire\FormulaireInstanceServiceAwareTrait;
use Autoform\Service\Formulaire\FormulaireReponseServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class ChampController extends AbstractActionController {
    use ChampServiceAwareTrait;
    use FormulaireInstanceServiceAwareTrait;
    use FormulaireReponseServiceAwareTrait;

    public function sauverAction()
    {
        $instance = $this->getFormulaireInstanceService()->getRequestedFormulaireInstance($this);
        $champ = $this->getChampService()->getRequestedChamp($this);
        $data = $this->params()->fromQuery('data');

        $reponse = $this->getFormulaireReponseService()->getFormulaireReponseByInstanceAndChamp($instance, $champ);

        if (!$reponse) {
            $reponse = new FormulaireReponse();
            $reponse->setFormulaireInstance($instance);
            $reponse->setChamp($champ);
            $this->getFormulaireReponseService()->create($reponse);
        }

//        $string = $this->getFormulaireReponseService()->getValueFomData($reponse->getChamp(), $data);
        $reponse->setReponse($data);
        $this->getFormulaireReponseService()->update($reponse);

        $vm = new ViewModel([
            'title' => "Mise à jour du champs",
            'texte' => "Mise à jour effectuée",
        ]);
        return $vm;
    }
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
<?php

namespace Autoform\Controller;

use Autoform\Service\Champ\ChampService;
use Autoform\Service\Formulaire\FormulaireInstanceService;
use Autoform\Service\Formulaire\FormulaireReponseService;
use Interop\Container\ContainerInterface;

class ChampControllerFactory {

    /**
     * @param ContainerInterface $container
     * @return ChampController
     */
    public function __invoke(ContainerInterface $container)
    {
        /**
         * @var ChampService $champService
         * @var FormulaireInstanceService $instanceService
         * @var FormulaireReponseService $reponseService
         */
        $champService = $container->get(ChampService::class);
        $instanceService = $container->get(FormulaireInstanceService::class);
        $reponseService = $container->get(FormulaireReponseService::class);

        $controller = new ChampController();
        $controller->setChampService($champService);
        $controller->setFormulaireInstanceService($instanceService);
        $controller->setFormulaireReponseService($reponseService);
        return $controller;
    }
}
 No newline at end of file
Loading