Skip to content
Snippets Groups Projects
Commit 71a5b923 authored by Alexandre Zvenigorosky's avatar Alexandre Zvenigorosky
Browse files

Affichage des années

parent f3e5f9df
No related branches found
No related tags found
No related merge requests found
Showing
with 604 additions and 30 deletions
<?php
namespace Application;
use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;
return [
'router' => [
'routes' => [
'corps' => [
'type' => 'Literal',
'options' => [
'route' => '/corps',
'defaults' => [
'controller' => 'Application\Controller\Corps',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'delete' => [
'type' => 'Segment',
'options' => [
'route' => '/delete/:corps',
'constraints' => [
'corps' => '[0-9]*',
],
'defaults' => [
'action' => 'delete',
],
],
],
'saisie' => [
'type' => 'Segment',
'options' => [
'route' => '/saisie/[:corps]',
'constraints' => [
'corps' => '[0-9]*',
],
'defaults' => [
'action' => 'saisie',
],
],
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'corps' => [
'label' => 'Corps',
'icon' => 'fa fa-graduation-cap',
'route' => 'corps',
'resource' => PrivilegeController::getResourceId('Application\Controller\Corps', 'index'),
'order' => 80,
'border-color' => '#BBCF55',
],
],
],
],
],
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\Corps',
'action' => ['index'],
'privileges' => Privileges::DROIT_PRIVILEGE_EDITION,
],
[
'controller' => 'Application\Controller\Corps',
'action' => ['saisie','delete'],
'privileges' => Privileges::DROIT_PRIVILEGE_VISUALISATION,
],
],
],
],
'controllers' => [
'invokables' => [
'Application\Controller\Corps' => Controller\CorpsController::class,
],
],
'service_manager' => [
'invokables' => [
Service\CorpsService::class => Service\CorpsService::class,
],
],
'view_helpers' => [
],
'form_elements' => [
'invokables' => [
Form\Corps\CorpsSaisieForm::class => Form\Corps\CorpsSaisieForm::class,
],
],
];
<?php
namespace Application\Controller;
use Application\Entity\Db\Corps;
use Application\Service\Traits\CorpsServiceAwareTrait;
use Application\Exception\DbException;
use Application\Form\Corps\Traits\CorpsSaisieFormAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
class CorpsController extends AbstractController
{
use CorpsServiceAwareTrait;
use CorpsSaisieFormAwareTrait;
public function indexAction()
{
$this->em()->getFilters()->enable('historique')->init([
Corps::class,
]);
$corpss = $this->getServiceCorps()->getList();
return compact('corpss');
}
public function saisieAction()
{
/* @var $corps Corps */
$corps = $this->getEvent()->getParam('corps');
$form = $this->getFormCorpsSaisie();
if (empty($corps)) {
$title = 'Création d\'une nouvelle Corps';
$corps = $this->getServiceCorps()->newEntity();
} else {
$title = 'Édition d\'une Corps';
}
$form->bindRequestSave($corps, $this->getRequest(), function (Corps $fr) {
try {
$this->getServiceCorps()->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()
{
$corps = $this->getEvent()->getParam('corps');
try {
$this->getServiceCorps()->delete($corps);
$this->flashMessenger()->addSuccessMessage("Corps supprimée avec succès.");
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
}
return new MessengerViewModel(compact('corps'));
}
}
...@@ -30,6 +30,72 @@ class Corps implements HistoriqueAwareInterface, ImportAwareInterface ...@@ -30,6 +30,72 @@ class Corps implements HistoriqueAwareInterface, ImportAwareInterface
*/ */
protected $id; protected $id;
/**
* @var string
*/
protected $sourceCode;
/**
* @var sinteger
*/
protected $sourceId;
/**
* Retourne la représentation littérale de cet objet.
*
* @return string
*/
public function __toString()
{
return $this->getCode() . " - " . $this->getLibelleLong();
}
/**
* @return string
*/
public function getSourceCode()
{
return $this->sourceCode;
}
/**
* @param string $sourceCode
*
* @return Corps
*/
public function setSourceCode($sourceCode)
{
$this->sourceCode = $sourceCode;
return $this;
}
/**
* @return integer
*/
public function getSourceId()
{
return $this->sourceId;
}
/**
* @param integer $sourceId
*
* @return Corps
*/
public function setSourceId($sourceId)
{
$this->sourceId = $sourceId;
return $this;
}
/** /**
...@@ -98,22 +164,4 @@ class Corps implements HistoriqueAwareInterface, ImportAwareInterface ...@@ -98,22 +164,4 @@ class Corps implements HistoriqueAwareInterface, ImportAwareInterface
return $this->id; return $this->id;
} }
/**************************************************************************************************
* Début ajout
**************************************************************************************************/
/**
* Retourne la représentation littérale de cet objet.
*
* @return string
*/
public function __toString()
{
return $this->getLibelleLong();
}
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Db\Corps" table="CORPS"> <entity name="Application\Entity\Db\Corps" table="CORPS">
<indexes>
<index name="IDX_3DE73A2B59860CDC" columns="HISTO_CREATEUR_ID"/>
<index name="IDX_3DE73A2B7E9E2204" columns="HISTO_DESTRUCTEUR_ID"/>
<index name="IDX_3DE73A2B63F06898" columns="HISTO_MODIFICATEUR_ID"/>
<index name="IDX_3DE73A2BE9B3446E" columns="SOURCE_ID"/>
</indexes>
<unique-constraints>
<unique-constraint name="corps_source_un" columns="SOURCE_CODE"/>
</unique-constraints>
<id name="id" type="integer" column="ID"> <id name="id" type="integer" column="ID">
<generator strategy="SEQUENCE"/> <generator strategy="SEQUENCE"/>
</id> </id>
<field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
<field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
<field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
<field name="libelleCourt" type="string" column="LIBELLE_COURT" length="20" nullable="false"/> <field name="libelleCourt" type="string" column="LIBELLE_COURT" length="20" nullable="false"/>
<field name="libelleLong" type="string" column="LIBELLE_LONG" length="40" nullable="false"/> <field name="libelleLong" type="string" column="LIBELLE_LONG" length="40" nullable="false"/>
<field name="sourceId" type="integer" column="SOURCE_ID" nullable="false"/>
<field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="true"/> <field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="true"/>
<field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
<field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
<field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
<many-to-one field="source" target-entity="UnicaenImport\Entity\Db\Source"> <many-to-one field="source" target-entity="UnicaenImport\Entity\Db\Source">
<join-columns> <join-columns>
<join-column name="SOURCE_ID" referenced-column-name="ID"/> <join-column name="SOURCE_ID" referenced-column-name="ID"/>
......
<?php
namespace Application\Form\Corps;
use Application\Form\AbstractForm;
use Zend\Form\Element\Csrf;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Application\Service\Traits\SourceServiceAwareTrait;
/**
* Description of CorpsSaisieForm
*
* @author ZVENIGOROSKY Alexandre <alexandre.zvenigorosky@unicaen.fr>
*/
class CorpsSaisieForm extends AbstractForm
{
use SourceServiceAwareTrait;
public function init()
{
$hydrator = new CorpsHydrator();
$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' => '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 [
'libelle-long' => [
'required' => true,
],
'libelle-court' => [
'required' => true,
],
'source' => [
'required' => true,
],
];
}
}
class CorpsHydrator implements HydratorInterface
{
use SourceServiceAwareTrait;
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param \Application\Entity\Db\Corps $object
*
* @return object
*/
public function hydrate(array $data, $object)
{
$object->setLibelleLong($data['libelle-long']);
$object->setLibelleCourt($data['libelle-court']);
$object->setSourceCode($data['source-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\Corps $object
*
* @return array
*/
public function extract($object)
{
$data = [
'id' => $object->getId()
,'libelle-long' => $object->getLibelleLong()
,'libelle-court' => $object->getLibelleCourt()
,'source-code' => $object->getSourceCode()
,'source' => ($s = $object->getSource()) ? $s->getId() : null,
];
return $data;
}
}
\ No newline at end of file
<?php
namespace Application\Form\Corps\Traits;
use Application\Form\Corps\CorpsSaisieForm;
/**
* Description of CorpsSaisieFormAwareTrait
*
* @author UnicaenCode
*/
trait CorpsSaisieFormAwareTrait
{
/**
* @var CorpsSaisieForm
*/
private $formCorpsSaisie;
/**
* @param CorpsSaisieForm $formCorpsSaisie
*
* @return self
*/
public function setFormCorpsSaisie(CorpsSaisieForm $formCorpsSaisie)
{
$this->formCorpsSaisie = $formCorpsSaisie;
return $this;
}
/**
* Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement.
*
* @return CorpsSaisieForm
*/
public function getFormCorpsSaisie()
{
if (!empty($this->formCorpsSaisie)) {
return $this->formCorpsSaisie;
}
return \Application::$container->get('FormElementManager')->get(CorpsSaisieForm::class);
}
}
<?php
namespace Application\Service;
use Doctrine\ORM\QueryBuilder;
/**
* Description of Corps
*
*/
class CorpsService extends AbstractEntityService
{
/**
* retourne la classe des entit?s
*
* @return string
* @throws RuntimeException
*/
public function getEntityClass()
{
return \Application\Entity\Db\Corps::class;
}
/**
* Retourne l'alias d'entit? courante
*
* @return string
*/
public function getAlias()
{
return 'fr';
}
public function getList(QueryBuilder $qb = null, $alias = null)
{
list($qb, $alias) = $this->initQuery();
return parent::getList($qb, $alias);
}
}
<?php
namespace Application\Service\Traits;
use Application\Service\CorpsService;
/**
* Description of CorpsAwareTrait
*
* @author UnicaenCode
*/
trait CorpsServiceAwareTrait
{
/**
* @var CorpsService
*/
private $serviceCorps;
/**
* @param CorpsService $serviceCorps
*
* @return self
*/
public function setServiceCorps(CorpsService $serviceCorps)
{
$this->serviceCorps = $serviceCorps;
return $this;
}
/**
* @return CorpsService
*/
public function getServiceCorps()
{
if (empty($this->serviceCorps)) {
$this->serviceCorps = \Application::$container->get(CorpsService::class);
}
return $this->serviceCorps;
}
}
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $corpss \Application\Entity\Db\Corps[]
*/
use Application\Provider\Privilege\Privileges;
$this->headTitle()->append("CORPSs");
$canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEGE_VISUALISATION));
?>
<h1 class="page-header">CORPSs</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>
<?php if ($canEdit) echo '<th>Actions</th>' ?>
</thead>
<tbody>
<?php foreach ($corpss 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>
<?php if ($canEdit) { ?>
<td style="text-align:center;width:1px;white-space: nowrap">
<a class="ajax-modal" data-event="corps-saisie"
href="<?= $this->url('corps/saisie', ['corps' => $fr->getId()]) ?>"
title="Modifier la Corps">
<span class="glyphicon glyphicon-edit"></span></a>
<a class="pop-ajax"
href="<?= $this->url('corps/delete', ['corps' => $fr->getId()]) ?>"
title="Supprimer la Corps"
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="corps-saisie"
href="<?= $this->url('corps/saisie') ?>"
title="Ajouter une CORPS">
<span class="glyphicon glyphicon-edit"></span>
Ajouter une CORPS</a>
<script type="text/javascript">
$(function () {
$("body").on("corps-saisie", function (event, data) {
window.location.reload();
});
});
</script>
<?php endif ?>
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\Corps\CorpsSaisieForm
*/
echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
echo $this->form($form);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment