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

Factorisation du change de niveau de *Element

parent 5d9f06c8
Loading
Loading
Loading
Loading
+0 −12
Changes for module/Application/config/merged/application.config.php: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ return [
                        'modifier-groupe',
                        'historiser-groupe',
                        'restaurer-groupe',
                        'changer-niveau',
                    ],
                    'privileges' => [
                        ApplicationPrivileges::APPLICATION_EDITER,
@@ -127,17 +126,6 @@ return [
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'changer-niveau' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/changer-niveau/:application-element[/:clef]',
                            'defaults' => [
                                'controller' => ApplicationController::class,
                                'action'     => 'changer-niveau',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'groupe' => [
                        'type' => Literal::class,
                        'may_terminate' => false,
+0 −20
Changes for module/Application/config/merged/competence.config.php: 0 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -152,15 +152,6 @@ return [
                        CompetencePrivileges::COMPETENCE_EFFACER,
                    ],
                ],
                [
                    'controller' => CompetenceController::class,
                    'action' => [
                        'changer-niveau',
                    ],
                    'privileges' => [
                        CompetencePrivileges::COMPETENCE_EFFACER,
                    ],
                ],
            ],
        ],
    ],
@@ -178,17 +169,6 @@ return [
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'changer-niveau' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/changer-niveau/:competence-element[/:clef]',
                            'defaults' => [
                                'controller' => CompetenceController::class,
                                'action'     => 'changer-niveau',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'ajouter' => [
                        'type'  => Segment::class,
                        'options' => [
+23 −0
Changes for module/Application/config/merged/element.config.php: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@ namespace Application;

use Application\Controller\ElementController;
use Application\Controller\ElementControllerFactory;
use Application\Provider\Privilege\AgentPrivileges;
use Application\Provider\Privilege\ApplicationPrivileges;
use Application\Provider\Privilege\CompetencePrivileges;
use Application\Provider\Privilege\FicheMetierPrivileges;
use Formation\Provider\Privilege\FormationPrivileges;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
@@ -37,6 +39,16 @@ return [
                        FormationPrivileges::FORMATION_SUPPRIMER,
                    ],
                ],
                [
                    'controller' => ElementController::class,
                    'action' => [
                        'changer-niveau',
                    ],
                    'privileges' => [
                        AgentPrivileges::AGENT_ELEMENT_MODIFIER,
                        FicheMetierPrivileges::FICHEMETIER_MODIFIER,
                    ],
                ],
            ],
        ],
    ],
@@ -75,6 +87,17 @@ return [
                        ],
                        'may_terminate' => true,
                    ],
                    'changer-niveau' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/changer-niveau/:type/:id[/:clef]',
                            'defaults' => [
                                'controller' => ElementController::class,
                                'action'     => 'changer-niveau',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                ],
            ],
        ],
+0 −28
Changes for module/Application/src/Application/Controller/CompetenceController.php: 0 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -505,32 +505,4 @@ class CompetenceController extends AbstractActionController
        }
        exit();
    }

    /** Niveau de maitrise d'un  */
    public function changerNiveauAction() {
        $competenceElement = $this->getCompetenceElementService()->getRequestedCompetenceElement($this);
        $clef=$this->params()->fromRoute('clef');

        $form = $this->getSelectionCompetenceMaitriseForm();
        $form->setAttribute('action', $this->url()->fromRoute('competence/changer-niveau', ['competence-element' => $competenceElement->getId(), 'clef' => $clef], [], true));
        $form->bind($competenceElement);
        if ($clef === 'masquer') $form->masquerClef();

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getCompetenceElementService()->update($competenceElement);
            }
        }

        $vm = new ViewModel([
            'title' => "Changer le niveau de maîtrise",
            'form' => $form,
        ]);
        $vm->setTemplate('application/default/default-form');
        return $vm;
    }

}
 No newline at end of file
+40 −0
Changes for module/Application/src/Application/Controller/ElementController.php: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Application\Controller;

use Application\Form\SelectionCompetenceMaitrise\SelectionCompetenceMaitriseFormAwareTrait;
use Application\Service\ApplicationElement\ApplicationElementServiceAwareTrait;
use Application\Service\CompetenceElement\CompetenceElementServiceAwareTrait;
use Formation\Service\FormationElement\FormationElementServiceAwareTrait;
@@ -13,6 +14,7 @@ class ElementController extends AbstractActionController {
    use ApplicationElementServiceAwareTrait;
    use CompetenceElementServiceAwareTrait;
    use FormationElementServiceAwareTrait;
    use SelectionCompetenceMaitriseFormAwareTrait;

    const TYPE_APPLICATION = 'Application';
    const TYPE_COMPETENCE = 'Competence';
@@ -85,4 +87,42 @@ class ElementController extends AbstractActionController {
        return $vm;
    }

    public function changerNiveauAction() {
        $elementType = $this->params()->fromRoute('type');
        $elementId = $this->params()->fromRoute('id');
        $clef=$this->params()->fromRoute('clef');

        $element = null; $service = null;
        switch ($elementType) {
            case ElementController::TYPE_APPLICATION :
                $element = $this->getApplicationElementService()->getApplicationElement($elementId);
                $service = $this->getApplicationElementService();
                break;
            case ElementController::TYPE_COMPETENCE :
                $element = $this->getCompetenceElementService()->getCompetenceElement($elementId);
                $service = $this->getCompetenceElementService();
                break;
        }

        $form = $this->getSelectionCompetenceMaitriseForm();
        $form->setAttribute('action', $this->url()->fromRoute('element/changer-niveau', ['type' => $elementType, 'id' => $element->getId(), 'clef' => $clef], [], true));
        $form->bind($element);
        if ($clef === 'masquer') $form->masquerClef();

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $service->update($element);
            }
        }

        $vm = new ViewModel([
            'title' => "Changer le niveau de maîtrise",
            'form' => $form,
        ]);
        $vm->setTemplate('application/default/default-form');
        return $vm;
    }
}
 No newline at end of file
Loading