Commit 71a5b923 authored by Alexandre Zvenigorosky's avatar Alexandre Zvenigorosky
Browse files

Affichage des années

parent f3e5f9df
<?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
*/
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
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"?>
<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">
<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">
<generator strategy="SEQUENCE"/>
</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="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="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">
<join-columns>
<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");