Commit d7be20c0 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Merge branch 'Motif_Non_Paiement' into 'master'

Motif non paiement

See merge request !41
parents bde2dffc 17a37d13
<?php
namespace Application;
use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;
return [
'router' => [
'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,
],
],
];
<?php
namespace Application\Controller;
use Application\Entity\Db\MotifNonPaiement;
use Application\Service\Traits\MotifNonPaiementServiceAwareTrait;
use Application\Exception\DbException;
use Application\Form\MotifNonPaiement\Traits\MotifNonPaiementSaisieFormAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
class MotifNonPaiementController extends AbstractController
{
use MotifNonPaiementServiceAwareTrait;
use MotifNonPaiementSaisieFormAwareTrait;
public function indexAction()
{
$this->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'));
}
}
<?php
namespace Application\Form\MotifNonPaiement;
use Application\Form\AbstractForm;
use Zend\Form\Element\Csrf;
use Zend\Stdlib\Hydrator\HydratorInterface;
/**
* Description of MotifNonPaiementSaisieForm
*
* @author ZVENIGOROSKY Alexandre <alexandre.zvenigorosky@unicaen.fr>
*/
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
<?php
namespace Application\Form\MotifNonPaiement\Traits;
use Application\Form\MotifNonPaiement\MotifNonPaiementSaisieForm;
/**
* Description of MotifNonPaiementSaisieFormAwareTrait
*
* @author UnicaenCode
*/
trait MotifNonPaiementSaisieFormAwareTrait
{
/**
* @var MotifNonPaiementSaisieForm
*/
private $formMotifNonPaiementSaisie;
/**
* @param MotifNonPaiementSaisieForm $formMotifNonPaiementSaisie
*
* @return self
*/
public function setFormMotifNonPaiementSaisie(MotifNonPaiementSaisieForm $formMotifNonPaiementSaisie)
{
$this->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);
}
}
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $motifNonPaiements \Application\Entity\Db\MotifNonPaiement[]
*/
use Application\Provider\Privilege\Privileges;
$title = "Motifs de non paiement";
$this->headTitle()->append($title);
$canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MOTIF_NON_PAIEMENT_EDITION));
?>
<h1 class="page-header"><?= $title ?></h1>
<table class="table table-bordered table-sort">
<thead>
<th style="word-wrap: break-word ; ">Code</th>
<th style="word-wrap: break-word ; ">Libelle Court</th>
<th style="word-wrap: break-word ; ">Libelle Long</th>
<?php if ($canEdit) echo '<th>Actions</th>' ?>
</thead>
<tbody>
<?php foreach ($motifNonPaiements as $fr): ?>
<tr>
<td style="word-wrap: break-word ; "><?= $fr->getCode() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getLibelleCourt() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getLibelleLong() ?></td>
<?php if ($canEdit) { ?>
<td style="text-align:center;width:1px;white-space: nowrap">
<a class="ajax-modal" data-event="motif-non-paiement-saisie"
href="<?= $this->url('motif-non-paiement/saisir', ['motifNonPaiement' => $fr->getId()]) ?>"
title="Modifier la MotifNonPaiement">
<span class="glyphicon glyphicon-edit"></span></a>
<a class="pop-ajax"
href="<?= $this->url('motif-non-paiement/supprimer', ['motifNonPaiement' => $fr->getId()]) ?>"
title="Supprimer la MotifNonPaiement"
data-content="<p class='lead text-danger'><strong>Attention!</strong> Confirmez-vous cette suppression ?</p>"
data-confirm="true"
data-confirm-button="Oui"
data-cancel-button="Non"
data-submit-reload="true"
>
<span class="glyphicon glyphicon-remove"></span>
</a>
</td>
<?php } ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if ($canEdit): ?>
<a class="btn btn-primary ajax-modal" data-event="motif-non-paiement-saisie"
href="<?= $this->url('motif-non-paiement/saisir') ?>">
<span class="glyphicon glyphicon-edit"></span>
Ajouter un motif de non paiement</a>
<script type="text/javascript">
$(function () {
$("body").on("motif-non-paiement-saisie", function (event, data) {
window.location.reload();
});
});
</script>
<?php endif ?>
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\MotifNonPaiement\MotifNonPaiementSaisieForm
*/
echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
echo $this->form($form);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment