Commit f3e5f9df authored by Alexandre Zvenigorosky's avatar Alexandre Zvenigorosky
Browse files

Affichage des années

parent 8722a4de
<?php
namespace Application;
use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;
return [
'router' => [
'routes' => [
'departement' => [
'type' => 'Literal',
'options' => [
'route' => '/departement',
'defaults' => [
'controller' => 'Application\Controller\Departement',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'delete' => [
'type' => 'Segment',
'options' => [
'route' => '/delete/:departement',
'constraints' => [
'departement' => '[0-9]*',
],
'defaults' => [
'action' => 'delete',
],
],
],
'saisie' => [
'type' => 'Segment',
'options' => [
'route' => '/saisie/[:departement]',
'constraints' => [
'departement' => '[0-9]*',
],
'defaults' => [
'action' => 'saisie',
],
],
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'departement' => [
'label' => 'Departement',
'icon' => 'fa fa-graduation-cap',
'route' => 'departement',
'resource' => PrivilegeController::getResourceId('Application\Controller\Departement', 'index'),
'order' => 80,
'border-color' => '#BBCF55',
],
],
],
],
],
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\Departement',
'action' => ['index'],
'privileges' => Privileges::DROIT_PRIVILEGE_EDITION,
],
[
'controller' => 'Application\Controller\Departement',
'action' => ['saisie','delete'],
'privileges' => Privileges::DROIT_PRIVILEGE_VISUALISATION,
],
],
],
],
'controllers' => [
'invokables' => [
'Application\Controller\Departement' => Controller\DepartementController::class,
],
],
'service_manager' => [
'invokables' => [
Service\DepartementService::class => Service\DepartementService::class,
],
],
'view_helpers' => [
],
'form_elements' => [
'invokables' => [
Form\Departement\DepartementSaisieForm::class => Form\Departement\DepartementSaisieForm::class,
],
],
];
<?php
namespace Application\Controller;
use Application\Entity\Db\Departement;
use Application\Service\Traits\DepartementServiceAwareTrait;
use Application\Exception\DbException;
use Application\Form\Departement\Traits\DepartementSaisieFormAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
class DepartementController extends AbstractController
{
use DepartementServiceAwareTrait;
use DepartementSaisieFormAwareTrait;
public function indexAction()
{
$this->em()->getFilters()->enable('historique')->init([
Departement::class,
]);
$departements = $this->getServiceDepartement()->getList();
return compact('departements');
}
public function saisieAction()
{
/* @var $departement Departement */
$departement = $this->getEvent()->getParam('departement');
$form = $this->getFormDepartementSaisie();
if (empty($departement)) {
$title = 'Création d\'une nouvelle Departement';
$departement = $this->getServiceDepartement()->newEntity();
} else {
$title = 'Édition d\'une Departement';
}
$form->bindRequestSave($departement, $this->getRequest(), function (Departement $fr) {
try {
$this->getServiceDepartement()->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 deleteAction()
{
$departement = $this->getEvent()->getParam('departement');
try {
$this->getServiceDepartement()->delete($departement);
$this->flashMessenger()->addSuccessMessage("Departement supprimée avec succès.");
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
}
return new MessengerViewModel(compact('departement'));
}
}
<?php
namespace Application\Form\Departement;
use Application\Form\AbstractForm;
use Zend\Form\Element\Csrf;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Application\Service\Traits\SourceServiceAwareTrait;
/**
* Description of DepartementSaisieForm
*
* @author ZVENIGOROSKY Alexandre <alexandre.zvenigorosky@unicaen.fr>
*/
class DepartementSaisieForm extends AbstractForm
{
use SourceServiceAwareTrait;
public function init()
{
$hydrator = new DepartementHydrator();
$this->setHydrator($hydrator);
$this->setAttribute('action', $this->getCurrentUrl());
$this->add([
'name' => 'libelle-long',
'options' => [
'label' => "Libelle Long",
],
'type' => 'Text',
]);
$this->add([
'name' => 'libelle-court',
'options' => [
'label' => "Libelle Court",
],
'type' => 'Text',
]);
$this->add([
'name' => 'source-code',
'options' => [
'label' => "Source Code",
],
'type' => 'Text',
]);
$this->add([
'name' => 'code',
'options' => [
'label' => "Code",
],
'type' => 'Text',
]);
$this->add([
'name' => 'source',
'options' => [
'label' => 'Source',
],
'attributes' => [
'class' => 'selectpicker',
'data-live-search' => 'true',
],
'type' => 'Select',
]);
$this->get('source')
->setValueOptions(\UnicaenApp\Util::collectionAsOptions($this->getServiceSource()->getList()));
$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 [
'source' => [
'required' => true,
],
'source-code' => [
'required' => true,
],
];
}
}
class DepartementHydrator implements HydratorInterface
{
use SourceServiceAwareTrait;
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param \Application\Entity\Db\Departement $object
*
* @return object
*/
public function hydrate(array $data, $object)
{
$object->setLibelleLong($data['libelle-long']);
$object->setLibelleCourt($data['libelle-court']);
$object->setSourceCode($data['source-code']);
$object->setCode($data['code']);
if (array_key_exists('source', $data)) {
$object->setSource($this->getServiceSource()->get($data['source']));
}
return $object;
}
/**
* Extract values from an object
*
* @param \Application\Entity\Db\Departement $object
*
* @return array
*/
public function extract($object)
{
$data = [
'id' => $object->getId()
,'libelle-long' => $object->getLibelleLong()
,'libelle-court' => $object->getLibelleCourt()
,'source-code' => $object->getSourceCode()
,'code' => $object->getCode()
,'source' => ($s = $object->getSource()) ? $s->getId() : null,
];
return $data;
}
}
\ No newline at end of file
<?php
namespace Application\Form\Departement\Traits;
use Application\Form\Departement\DepartementSaisieForm;
/**
* Description of DepartementSaisieFormAwareTrait
*
* @author UnicaenCode
*/
trait DepartementSaisieFormAwareTrait
{
/**
* @var DepartementSaisieForm
*/
private $formDepartementSaisie;
/**
* @param DepartementSaisieForm $formDepartementSaisie
*
* @return self
*/
public function setFormDepartementSaisie(DepartementSaisieForm $formDepartementSaisie)
{
$this->formDepartementSaisie = $formDepartementSaisie;
return $this;
}
/**
* Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement.
*
* @return DepartementSaisieForm
*/
public function getFormDepartementSaisie()
{
if (!empty($this->formDepartementSaisie)) {
return $this->formDepartementSaisie;
}
return \Application::$container->get('FormElementManager')->get(DepartementSaisieForm::class);
}
}
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $departements \Application\Entity\Db\Departement[]
*/
use Application\Provider\Privilege\Privileges;
$this->headTitle()->append("DEPARTEMENTs");
$canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEGE_VISUALISATION));
?>
<h1 class="page-header">DEPARTEMENTs</h1>
<table class="table table-bordered table-sort">
<thead>
<th style="word-wrap: break-word ; ">Libelle Long</th>
<th style="word-wrap: break-word ; ">Libelle Court</th>
<th style="word-wrap: break-word ; ">Source</th>
<th style="word-wrap: break-word ; ">Source Code</th>
<th style="word-wrap: break-word ; ">Code</th>
<?php if ($canEdit) echo '<th>Actions</th>' ?>
</thead>
<tbody>
<?php foreach ($departements as $fr): ?>
<tr>
<td style="word-wrap: break-word ; "><?= $fr->getLibelleLong() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getLibelleCourt() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getSource() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getSourceCode() ?></td>
<td style="word-wrap: break-word ; "><?= $fr->getCode() ?></td>
<?php if ($canEdit) { ?>
<td style="text-align:center;width:1px;white-space: nowrap">
<a class="ajax-modal" data-event="departement-saisie"
href="<?= $this->url('departement/saisie', ['departement' => $fr->getId()]) ?>"
title="Modifier la Departement">
<span class="glyphicon glyphicon-edit"></span></a>
<a class="pop-ajax"
href="<?= $this->url('departement/delete', ['departement' => $fr->getId()]) ?>"
title="Supprimer la Departement"
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="departement-saisie"
href="<?= $this->url('departement/saisie') ?>"
title="Ajouter une DEPARTEMENT">
<span class="glyphicon glyphicon-edit"></span>
Ajouter une DEPARTEMENT</a>
<script type="text/javascript">
$(function () {
$("body").on("departement-saisie", function (event, data) {
window.location.reload();
});
});
</script>
<?php endif ?>
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\Departement\DepartementSaisieForm
*/
echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
echo $this->form($form);
Markdown is supported
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