diff --git a/module/Application/config/motif-non-paiement.config.php b/module/Application/config/motif-non-paiement.config.php new file mode 100644 index 0000000000000000000000000000000000000000..395b8370ff9bf4f035084e66f3c4a4bd6164136d --- /dev/null +++ b/module/Application/config/motif-non-paiement.config.php @@ -0,0 +1,103 @@ + [ + 'routes' => [ + 'motif-non-paiement' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/motif-non-paiement', + 'defaults' => [ + 'controller' => 'Application\Controller\MotifNonPaiement', + 'action' => 'index', + ], + ], + 'may_terminate' => true, + 'child_routes' => [ + 'supprimer' => [ + 'type' => 'Segment', + 'options' => [ + 'route' => '/supprimer/:motifNonPaiement', + 'constraints' => [ + 'motifNonPaiement' => '[0-9]*', + ], + 'defaults' => [ + 'action' => 'supprimer', + ], + ], + ], + 'saisir' => [ + 'type' => 'Segment', + 'options' => [ + 'route' => '/saisir/[:motifNonPaiement]', + 'constraints' => [ + 'motifNonPaiement' => '[0-9]*', + ], + 'defaults' => [ + 'action' => 'saisir', + ], + ], + ], + ], + ], + ], + ], + 'navigation' => [ + 'default' => [ + 'home' => [ + 'pages' => [ + 'administration' => [ + 'pages' => [ + 'motif-non-paiement' => [ + 'label' => 'Motifs de non paiement', + 'icon' => 'fa fa-graduation-cap', + 'route' => 'motif-non-paiement', + 'resource' => PrivilegeController::getResourceId('Application\Controller\MotifNonPaiement', 'index'), + 'order' => 80, + 'border-color' => '#BBCF55', + ], + ], + ], + ], + ], + ], + ], + 'bjyauthorize' => [ + 'guards' => [ + PrivilegeController::class => [ + [ + 'controller' => 'Application\Controller\MotifNonPaiement', + 'action' => ['index'], + 'privileges' => Privileges::MOTIF_NON_PAIEMENT_VISUALISATION, + ], + [ + 'controller' => 'Application\Controller\MotifNonPaiement', + 'action' => ['saisir', 'supprimer'], + 'privileges' => Privileges::MOTIF_NON_PAIEMENT_EDITION, + ], + ], + ], + ], + 'controllers' => [ + 'invokables' => [ + 'Application\Controller\MotifNonPaiement' => Controller\MotifNonPaiementController::class, + ], + ], + 'service_manager' => [ + 'invokables' => [ + Service\MotifNonPaiementService::class => Service\MotifNonPaiementService::class, + ], + ], + 'view_helpers' => [ + ], + 'form_elements' => [ + 'invokables' => [ + Form\MotifNonPaiement\Saisie::class => Form\MotifNonPaiement\Saisie::class, + ], + ], +]; diff --git a/module/Application/src/Application/Controller/MotifNonPaiementController.php b/module/Application/src/Application/Controller/MotifNonPaiementController.php new file mode 100644 index 0000000000000000000000000000000000000000..9f1482317662d549ca714c28d6f1ff9742a0e0bd --- /dev/null +++ b/module/Application/src/Application/Controller/MotifNonPaiementController.php @@ -0,0 +1,72 @@ +em()->getFilters()->enable('historique')->init([ + MotifNonPaiement::class, + ]); + + $motifNonPaiements = $this->getServiceMotifNonPaiement()->getList(); + + return compact('motifNonPaiements'); + } + + + + public function saisirAction() + { + /* @var $motifNonPaiement MotifNonPaiement */ + $motifNonPaiement = $this->getEvent()->getParam('motifNonPaiement'); + + $form = $this->getFormMotifNonPaiementSaisie(); + if (empty($motifNonPaiement)) { + $title = 'Création d\'un nouveau motif de non paiement'; + $motifNonPaiement = $this->getServiceMotifNonPaiement()->newEntity(); + } else { + $title = 'Édition d\'un motif de non paiement'; + } + + $form->bindRequestSave($motifNonPaiement, $this->getRequest(), function (MotifNonPaiement $fr) { + try { + $this->getServiceMotifNonPaiement()->save($fr); + $this->flashMessenger()->addSuccessMessage('Enregistrement effectué'); + } catch (\Exception $e) { + $e = DbException::translate($e); + $this->flashMessenger()->addErrorMessage($e->getMessage() . ':' . $fr->getId()); + } + }); + + return compact('form', 'title'); + } + + + + public function supprimerAction() + { + $motifNonPaiement = $this->getEvent()->getParam('motifNonPaiement'); + + try { + $this->getServiceMotifNonPaiement()->delete($motifNonPaiement); + $this->flashMessenger()->addSuccessMessage("Motif de non paiement supprimée avec succès."); + } catch (\Exception $e) { + $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage()); + } + + return new MessengerViewModel(compact('motifNonPaiement')); + } +} diff --git a/module/Application/src/Application/Form/MotifNonPaiement/MotifNonPaiementSaisieForm.php b/module/Application/src/Application/Form/MotifNonPaiement/MotifNonPaiementSaisieForm.php new file mode 100644 index 0000000000000000000000000000000000000000..cb6ce484817fb40f9c7b47acdbfdba4d1b99c0c9 --- /dev/null +++ b/module/Application/src/Application/Form/MotifNonPaiement/MotifNonPaiementSaisieForm.php @@ -0,0 +1,132 @@ + + */ +class MotifNonPaiementSaisieForm extends AbstractForm +{ + + public function init() + { + $hydrator = new MotifNonPaiementHydrator(); + $this->setHydrator($hydrator); + + $this->setAttribute('action', $this->getCurrentUrl()); + $this->add([ + 'name' => 'code', + 'options' => [ + 'label' => "Code", + ], + 'type' => 'Text', + ]); + $this->add([ + 'name' => 'libelle-court', + 'options' => [ + 'label' => "Libelle Court", + ], + 'type' => 'Text', + ]); + $this->add([ + 'name' => 'libelle-long', + 'options' => [ + 'label' => "Libelle Long", + ], + 'type' => 'Text', + ]); + + $this->add(new Csrf('security')); + $this->add([ + 'name' => 'submit', + 'type' => 'Submit', + 'attributes' => [ + 'value' => "Enregistrer", + 'class' => 'btn btn-primary', + ], + ]); + + return $this; + } + + + + /** + * Should return an array specification compatible with + * {@link Zend\InputFilter\Factory::createInputFilter()}. + * + * @return array + */ + public function getInputFilterSpecification() + { + return [ + 'code' => [ + 'required' => true, + ], + + 'libelle-court' => [ + 'required' => true, + ], + + 'libelle-long' => [ + 'required' => true, + ], + + ]; + } + +} + + + + + +class MotifNonPaiementHydrator implements HydratorInterface +{ + + /** + * Hydrate $object with the provided $data. + * + * @param array $data + * @param \Application\Entity\Db\MotifNonPaiement $object + * + * @return object + */ + public function hydrate(array $data, $object) + { + $object->setCode($data['code']); + $object->setLibelleCourt($data['libelle-court']); + $object->setLibelleLong($data['libelle-long']); + + return $object; + } + + + + /** + * Extract values from an object + * + * @param \Application\Entity\Db\MotifNonPaiement $object + * + * @return array + */ + public function extract($object) + { + $data = [ + 'id' => $object->getId() + , 'code' => $object->getCode() + , 'libelle-court' => $object->getLibelleCourt() + , 'libelle-long' => $object->getLibelleLong() + , + ]; + + return $data; + } +} + \ No newline at end of file diff --git a/module/Application/src/Application/Form/MotifNonPaiement/Traits/MotifNonPaiementSaisieFormAwareTrait.php b/module/Application/src/Application/Form/MotifNonPaiement/Traits/MotifNonPaiementSaisieFormAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..2450c09908d5bda35701e56e92170475dfa12a53 --- /dev/null +++ b/module/Application/src/Application/Form/MotifNonPaiement/Traits/MotifNonPaiementSaisieFormAwareTrait.php @@ -0,0 +1,48 @@ +formMotifNonPaiementSaisie = $formMotifNonPaiementSaisie; + + return $this; + } + + + + /** + * Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement. + * + * @return MotifNonPaiementSaisieForm + */ + public function getFormMotifNonPaiementSaisie() + { + if (!empty($this->formMotifNonPaiementSaisie)) { + return $this->formMotifNonPaiementSaisie; + } + + return \Application::$container->get('FormElementManager')->get(MotifNonPaiementSaisieForm::class); + } +} diff --git a/module/Application/view/application/motif-non-paiement/index.phtml b/module/Application/view/application/motif-non-paiement/index.phtml new file mode 100644 index 0000000000000000000000000000000000000000..b11ebf432a782e8a9a23b64e90e9b8f264063925 --- /dev/null +++ b/module/Application/view/application/motif-non-paiement/index.phtml @@ -0,0 +1,67 @@ +headTitle()->append($title); + +$canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MOTIF_NON_PAIEMENT_EDITION)); + +?> +

+ + + + + + + Actions' ?> + + + + + + + + + + + + + +
CodeLibelle CourtLibelle Long
getCode() ?>getLibelleCourt() ?>getLibelleLong() ?> + + + + + +
+ + + + Ajouter un motif de non paiement + + + diff --git a/module/Application/view/application/motif-non-paiement/saisir.phtml b/module/Application/view/application/motif-non-paiement/saisir.phtml new file mode 100644 index 0000000000000000000000000000000000000000..41a85d0559553ab89ceb32b9b0c6857dedd7ea38 --- /dev/null +++ b/module/Application/view/application/motif-non-paiement/saisir.phtml @@ -0,0 +1,8 @@ +messenger()->addCurrentMessagesFromFlashMessenger(); +echo $this->form($form);