Loading module/Application/config/merged/parcours-de-formation.config.php +48 Changes for module/Application/config/merged/parcours-de-formation.config.php: 48 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -24,7 +24,11 @@ return [ 'action' => [ 'index', 'afficher', 'ajouter', 'modifier', 'historiser', 'restaurer', 'detruire', ], 'privileges' => [ FormationPrivileges::FORMATION_INDEX, Loading Loading @@ -77,6 +81,17 @@ return [ ], 'may_terminate' => true, ], 'ajouter' => [ 'type' => Segment::class, 'options' => [ 'route' => '/ajouter/:type', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'ajouter', ], ], 'may_terminate' => true, ], 'modifier' => [ 'type' => Segment::class, 'options' => [ Loading @@ -88,6 +103,39 @@ return [ ], 'may_terminate' => true, ], 'historiser' => [ 'type' => Segment::class, 'options' => [ 'route' => '/historiser/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'historiser', ], ], 'may_terminate' => true, ], 'restaurer' => [ 'type' => Segment::class, 'options' => [ 'route' => '/restaurer/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'restaurer', ], ], 'may_terminate' => true, ], 'detruire' => [ 'type' => Segment::class, 'options' => [ 'route' => '/detruire/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'detruire', ], ], 'may_terminate' => true, ], ], ], ], Loading module/Application/src/Application/Controller/ParcoursDeFormationController.php +40 −2 Changes for module/Application/src/Application/Controller/ParcoursDeFormationController.php: 40 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Application\Controller; use Application\Entity\Db\ParcoursDeFormation; use Application\Form\ParcoursDeFormation\ParcoursDeFormationFormAwareTrait; use Application\Service\ParcoursDeFormation\ParcoursDeFormationServiceAwareTrait; use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; Loading Loading @@ -36,6 +37,35 @@ class ParcoursDeFormationController extends AbstractActionController ]); } public function ajouterAction() { $type = $this->params()->fromRoute('type'); $parcours = new ParcoursDeFormation(); $parcours->setType($type); $form = $this->getParcoursDeFormationForm(); $form->setAttribute('action', $this->url()->fromRoute('parcours-de-formation/ajouter', ['type' => $type], [], true)); $form->bind($parcours); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $this->getParcoursDeFormationService()->create($parcours); } } $vm = new ViewModel(); $vm->setTemplate('application/parcours-de-formation/parcours-form'); $vm->setVariables([ 'title' => "Ajout d'un parcours de formation", 'form' => $form, ]); return $vm; } public function modifierAction() { $parcours = $this->getParcoursDeFormationService()->getRequestedParcoursDeFormation($this); Loading @@ -44,10 +74,18 @@ class ParcoursDeFormationController extends AbstractActionController $form->setAttribute('action', $this->url()->fromRoute('parcours-de-formation/modifier', ['parcours-de-formation' => $parcours->getId()], [], true)); $form->bind($parcours); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $this->getParcoursDeFormationService()->update($parcours); } } $vm = new ViewModel(); $vm->setTemplate('application/default/default-form'); $vm->setTemplate('application/parcours-de-formation/parcours-form'); $vm->setVariables([ 'title' => "Modification d'un parcours de formation", 'form' => $form, Loading module/Application/src/Application/Entity/Db/ParcoursDeFormation.php +16 −1 Changes for module/Application/src/Application/Entity/Db/ParcoursDeFormation.php: 16 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,9 +3,10 @@ namespace Application\Entity\Db; use Doctrine\Common\Collections\ArrayCollection; use UnicaenUtilisateur\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\HistoriqueAwareTrait; class ParcoursDeFormation { class ParcoursDeFormation implements HistoriqueAwareInterface { use HistoriqueAwareTrait; const TYPE_CATEGORIE = 'Catégorie'; Loading Loading @@ -109,6 +110,7 @@ class ParcoursDeFormation { */ public function getFormations() { if ($this->formations === null) return []; return $this->formations->toArray(); } Loading Loading @@ -140,4 +142,17 @@ class ParcoursDeFormation { $this->formations->removeElement($formation); return $this; } /** * @param Formation[] $formations * @return ParcoursDeFormation */ public function setFormations($formations) { $this->formations->clear(); foreach($formations as $formation) { $this->formations->add($formation); } return $this; } } No newline at end of file module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationForm.php +43 Changes for module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationForm.php: 43 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,8 +7,11 @@ use Application\Service\Formation\FormationServiceAwareTrait; use Application\Service\Metier\MetierServiceAwareTrait; use Zend\Form\Element\Button; use Zend\Form\Element\Select; use Zend\Form\Element\Text; use Zend\Form\Element\Textarea; use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; class ParcoursDeFormationForm extends Form { use MetierServiceAwareTrait; Loading @@ -16,6 +19,18 @@ class ParcoursDeFormationForm extends Form { public function init() { // libelle $this->add([ 'type' => Text::class, 'name' => 'libelle', 'options' => [ 'label' => "Libelle :", ], 'attributes' => [ 'id' => 'libelle', ], ]); $this->add([ 'type' => Select::class, 'name' => 'type', Loading Loading @@ -113,5 +128,33 @@ class ParcoursDeFormationForm extends Form { 'class' => 'btn btn-primary', ], ]); //inputFilter $this->setInputFilter((new Factory())->createInputFilter([ 'libelle' => [ 'required' => true, ], 'description' => [ 'required' => false, ], 'type' => [ 'required' => true, 'validators' => [[ 'name' => Callback::class, 'options' => [ 'messages' => [ Callback::INVALID_VALUE => "Le champ de référence (Catégorie ou métier) doit être saisi", ], 'callback' => function ($value, $context = []) { if($context['type'] === ParcoursDeFormation::TYPE_CATEGORIE) return $context['categorie'] !== ''; if($context['type'] === ParcoursDeFormation::TYPE_METIER) return $context['metier'] !== ''; return $value !== ''; }, //'break_chain_on_failure' => true, ], ]], ], 'metier' => [ 'required' => false, ], 'categorie' => [ 'required' => false, ], 'formations' => [ 'required' => false, ], ])); } } No newline at end of file module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationHydrator.php +53 −3 Changes for module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationHydrator.php: 53 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -2,18 +2,68 @@ namespace Application\Form\ParcoursDeFormation; use Application\Entity\Db\ParcoursDeFormation; use Application\Service\Formation\FormationServiceAwareTrait; use Zend\Hydrator\HydratorInterface; class ParcoursDeFormationHydrator implements HydratorInterface { use FormationServiceAwareTrait; /** * @param ParcoursDeFormation $object * @return array */ public function extract($object) { // TODO: Implement extract() method. $formationId = []; if ($object->getFormations() !== null) { foreach ($object->getFormations() as $formation) { $formationId[] = $formation->getId(); } } $data = [ 'type' => $object->getType(), 'libelle' => $object->getLibelle(), 'description' => $object->getDescription(), 'formations' => $formationId, ]; if ($object->getType() === ParcoursDeFormation::TYPE_CATEGORIE) $data['categorie'] = $object->getReference(); if ($object->getType() === ParcoursDeFormation::TYPE_METIER) $data['metier'] = $object->getReference(); return $data; } /** * @param array $data * @param ParcoursDeFormation $object * @return ParcoursDeFormation */ public function hydrate(array $data, $object) { // TODO: Implement hydrate() method. $libelle = (isset($data['libelle']) AND trim($data['libelle'])!=='')?$data['libelle']:null; $description = (isset($data['description']) AND trim($data['description'])!=='')?$data['description']:null; $type = (isset($data['type']))?$data['type']:null; $formations = []; if (isset($data['formations'])) { foreach ($data['formations'] as $formationId) { $formation = $this->getFormationService()->getFormation($formationId); if ($formation !== null) $formations[] = $formation; } } $reference = null; if ($type === ParcoursDeFormation::TYPE_CATEGORIE) $reference = $data['categorie']; if ($type === ParcoursDeFormation::TYPE_METIER) $reference = $data['metier']; $object->setLibelle($libelle); $object->setType($type); $object->setReference($reference); $object->setDescription($description); $object->setFormations($formations); return $object; } } No newline at end of file Loading
module/Application/config/merged/parcours-de-formation.config.php +48 Changes for module/Application/config/merged/parcours-de-formation.config.php: 48 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -24,7 +24,11 @@ return [ 'action' => [ 'index', 'afficher', 'ajouter', 'modifier', 'historiser', 'restaurer', 'detruire', ], 'privileges' => [ FormationPrivileges::FORMATION_INDEX, Loading Loading @@ -77,6 +81,17 @@ return [ ], 'may_terminate' => true, ], 'ajouter' => [ 'type' => Segment::class, 'options' => [ 'route' => '/ajouter/:type', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'ajouter', ], ], 'may_terminate' => true, ], 'modifier' => [ 'type' => Segment::class, 'options' => [ Loading @@ -88,6 +103,39 @@ return [ ], 'may_terminate' => true, ], 'historiser' => [ 'type' => Segment::class, 'options' => [ 'route' => '/historiser/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'historiser', ], ], 'may_terminate' => true, ], 'restaurer' => [ 'type' => Segment::class, 'options' => [ 'route' => '/restaurer/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'restaurer', ], ], 'may_terminate' => true, ], 'detruire' => [ 'type' => Segment::class, 'options' => [ 'route' => '/detruire/:parcours-de-formation', 'defaults' => [ 'controller' => ParcoursDeFormationController::class, 'action' => 'detruire', ], ], 'may_terminate' => true, ], ], ], ], Loading
module/Application/src/Application/Controller/ParcoursDeFormationController.php +40 −2 Changes for module/Application/src/Application/Controller/ParcoursDeFormationController.php: 40 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Application\Controller; use Application\Entity\Db\ParcoursDeFormation; use Application\Form\ParcoursDeFormation\ParcoursDeFormationFormAwareTrait; use Application\Service\ParcoursDeFormation\ParcoursDeFormationServiceAwareTrait; use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; Loading Loading @@ -36,6 +37,35 @@ class ParcoursDeFormationController extends AbstractActionController ]); } public function ajouterAction() { $type = $this->params()->fromRoute('type'); $parcours = new ParcoursDeFormation(); $parcours->setType($type); $form = $this->getParcoursDeFormationForm(); $form->setAttribute('action', $this->url()->fromRoute('parcours-de-formation/ajouter', ['type' => $type], [], true)); $form->bind($parcours); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $this->getParcoursDeFormationService()->create($parcours); } } $vm = new ViewModel(); $vm->setTemplate('application/parcours-de-formation/parcours-form'); $vm->setVariables([ 'title' => "Ajout d'un parcours de formation", 'form' => $form, ]); return $vm; } public function modifierAction() { $parcours = $this->getParcoursDeFormationService()->getRequestedParcoursDeFormation($this); Loading @@ -44,10 +74,18 @@ class ParcoursDeFormationController extends AbstractActionController $form->setAttribute('action', $this->url()->fromRoute('parcours-de-formation/modifier', ['parcours-de-formation' => $parcours->getId()], [], true)); $form->bind($parcours); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $this->getParcoursDeFormationService()->update($parcours); } } $vm = new ViewModel(); $vm->setTemplate('application/default/default-form'); $vm->setTemplate('application/parcours-de-formation/parcours-form'); $vm->setVariables([ 'title' => "Modification d'un parcours de formation", 'form' => $form, Loading
module/Application/src/Application/Entity/Db/ParcoursDeFormation.php +16 −1 Changes for module/Application/src/Application/Entity/Db/ParcoursDeFormation.php: 16 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,9 +3,10 @@ namespace Application\Entity\Db; use Doctrine\Common\Collections\ArrayCollection; use UnicaenUtilisateur\Entity\HistoriqueAwareInterface; use UnicaenUtilisateur\Entity\HistoriqueAwareTrait; class ParcoursDeFormation { class ParcoursDeFormation implements HistoriqueAwareInterface { use HistoriqueAwareTrait; const TYPE_CATEGORIE = 'Catégorie'; Loading Loading @@ -109,6 +110,7 @@ class ParcoursDeFormation { */ public function getFormations() { if ($this->formations === null) return []; return $this->formations->toArray(); } Loading Loading @@ -140,4 +142,17 @@ class ParcoursDeFormation { $this->formations->removeElement($formation); return $this; } /** * @param Formation[] $formations * @return ParcoursDeFormation */ public function setFormations($formations) { $this->formations->clear(); foreach($formations as $formation) { $this->formations->add($formation); } return $this; } } No newline at end of file
module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationForm.php +43 Changes for module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationForm.php: 43 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,8 +7,11 @@ use Application\Service\Formation\FormationServiceAwareTrait; use Application\Service\Metier\MetierServiceAwareTrait; use Zend\Form\Element\Button; use Zend\Form\Element\Select; use Zend\Form\Element\Text; use Zend\Form\Element\Textarea; use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; class ParcoursDeFormationForm extends Form { use MetierServiceAwareTrait; Loading @@ -16,6 +19,18 @@ class ParcoursDeFormationForm extends Form { public function init() { // libelle $this->add([ 'type' => Text::class, 'name' => 'libelle', 'options' => [ 'label' => "Libelle :", ], 'attributes' => [ 'id' => 'libelle', ], ]); $this->add([ 'type' => Select::class, 'name' => 'type', Loading Loading @@ -113,5 +128,33 @@ class ParcoursDeFormationForm extends Form { 'class' => 'btn btn-primary', ], ]); //inputFilter $this->setInputFilter((new Factory())->createInputFilter([ 'libelle' => [ 'required' => true, ], 'description' => [ 'required' => false, ], 'type' => [ 'required' => true, 'validators' => [[ 'name' => Callback::class, 'options' => [ 'messages' => [ Callback::INVALID_VALUE => "Le champ de référence (Catégorie ou métier) doit être saisi", ], 'callback' => function ($value, $context = []) { if($context['type'] === ParcoursDeFormation::TYPE_CATEGORIE) return $context['categorie'] !== ''; if($context['type'] === ParcoursDeFormation::TYPE_METIER) return $context['metier'] !== ''; return $value !== ''; }, //'break_chain_on_failure' => true, ], ]], ], 'metier' => [ 'required' => false, ], 'categorie' => [ 'required' => false, ], 'formations' => [ 'required' => false, ], ])); } } No newline at end of file
module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationHydrator.php +53 −3 Changes for module/Application/src/Application/Form/ParcoursDeFormation/ParcoursDeFormationHydrator.php: 53 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -2,18 +2,68 @@ namespace Application\Form\ParcoursDeFormation; use Application\Entity\Db\ParcoursDeFormation; use Application\Service\Formation\FormationServiceAwareTrait; use Zend\Hydrator\HydratorInterface; class ParcoursDeFormationHydrator implements HydratorInterface { use FormationServiceAwareTrait; /** * @param ParcoursDeFormation $object * @return array */ public function extract($object) { // TODO: Implement extract() method. $formationId = []; if ($object->getFormations() !== null) { foreach ($object->getFormations() as $formation) { $formationId[] = $formation->getId(); } } $data = [ 'type' => $object->getType(), 'libelle' => $object->getLibelle(), 'description' => $object->getDescription(), 'formations' => $formationId, ]; if ($object->getType() === ParcoursDeFormation::TYPE_CATEGORIE) $data['categorie'] = $object->getReference(); if ($object->getType() === ParcoursDeFormation::TYPE_METIER) $data['metier'] = $object->getReference(); return $data; } /** * @param array $data * @param ParcoursDeFormation $object * @return ParcoursDeFormation */ public function hydrate(array $data, $object) { // TODO: Implement hydrate() method. $libelle = (isset($data['libelle']) AND trim($data['libelle'])!=='')?$data['libelle']:null; $description = (isset($data['description']) AND trim($data['description'])!=='')?$data['description']:null; $type = (isset($data['type']))?$data['type']:null; $formations = []; if (isset($data['formations'])) { foreach ($data['formations'] as $formationId) { $formation = $this->getFormationService()->getFormation($formationId); if ($formation !== null) $formations[] = $formation; } } $reference = null; if ($type === ParcoursDeFormation::TYPE_CATEGORIE) $reference = $data['categorie']; if ($type === ParcoursDeFormation::TYPE_METIER) $reference = $data['metier']; $object->setLibelle($libelle); $object->setType($type); $object->setReference($reference); $object->setDescription($description); $object->setFormations($formations); return $object; } } No newline at end of file