Commit 4667d596 authored by Alexandre Zvenigorosky's avatar Alexandre Zvenigorosky
Browse files

Merge branches 'Centres-cout' and 'master' of git.unicaen.fr:open-source/OSE into Centres-cout

# Conflicts:
#	composer.json
#	composer.lock
parent aa116d0a
......@@ -98,12 +98,12 @@ return [
[
'controller' => 'Application\Controller\CentreCout',
'action' => ['index'],
'privileges' => Privileges::DROIT_PRIVILEGE_EDITION,
'privileges' => Privileges::CENTRES_COUTS_ADMINISTRATION_VISUALISATION,
],
[
'controller' => 'Application\Controller\CentreCout',
'action' => ['saisie', 'delete','saisie-structure','delete-structure'],
'privileges' => Privileges::ODF_CENTRES_COUT_EDITION,
'privileges' => Privileges::CENTRES_COUTS_ADMINISTRATION_EDITION,
],
],
],
......
<?php
namespace Application;
use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;
return [
'router' => [
'routes' => [
'groupe-type-formation' => [
'type' => 'Literal',
'options' => [
'route' => '/groupe-type-formation',
'defaults' => [
'controller' => 'Application\Controller\GroupeTypeFormation',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'delete' => [
'type' => 'Segment',
'options' => [
'route' => '/delete/:groupe-type-formation',
'constraints' => [
'groupe-type-formation' => '[0-9]*',
],
'defaults' => [
'action' => 'delete',
],
],
],
'saisie' => [
'type' => 'Segment',
'options' => [
'route' => '/saisie/[:groupe-type-formation]',
'constraints' => [
'groupe-type-formation' => '[0-9]*',
],
'defaults' => [
'action' => 'saisie',
],
],
],
'type-formation-delete' => [
'type' => 'Segment',
'options' => [
'route' => '/type-formation-delete/:type-formation',
'constraints' => [
'type-formation' => '[0-9]*',
],
'defaults' => [
'action' => 'type-formation-delete',
],
],
],
'type-formation-saisie' => [
'type' => 'Segment',
'options' => [
'route' => '/type-formation-saisie/:groupe-type-formation[/:type-formation]',
'constraints' => [
'groupe-type-formation' => '[0-9]*',
'type-formation' => '[0-9]*',
],
'defaults' => [
'action' => 'type-formation-saisie',
],
],
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'groupe-type-formation' => [
'label' => 'Diplômes',
'icon' => 'fa fa-graduation-cap',
'route' => 'groupe-type-formation',
'resource' => PrivilegeController::getResourceId('Application\Controller\GroupeTypeFormation', 'index'),
'order' => 80,
'border-color' => '#BBCF55',
],
],
],
],
],
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\GroupeTypeFormation',
'action' => ['index'],
'privileges' => Privileges::DROIT_PRIVILEGE_EDITION,
],
[
'controller' => 'Application\Controller\GroupeTypeFormation',
'action' => ['saisie', 'delete', 'type-formation-saisie', 'type-formation-delete'],
'privileges' => Privileges::DROIT_PRIVILEGE_VISUALISATION,
],
],
],
],
'controllers' => [
'invokables' => [
'Application\Controller\GroupeTypeFormation' => Controller\GroupeTypeFormationController::class,
],
],
'service_manager' => [
'invokables' => [
Service\GroupeTypeFormationService::class => Service\GroupeTypeFormationService::class,
Service\GroupeTypeFormationService::class => Service\TypeFormationService::class,
],
],
'view_helpers' => [
],
'form_elements' => [
'invokables' => [
Form\GroupeTypeFormation\TypeFormationSaisieForm::class => Form\GroupeTypeFormation\TypeFormationSaisieForm::class,
Form\GroupeTypeFormation\GroupeTypeFormationSaisieForm::class => Form\GroupeTypeFormation\GroupeTypeFormationSaisieForm::class,
],
],
];
<?php
namespace Application\Controller;
use Application\Entity\Db\GroupeTypeFormation;
use Application\Service\Traits\GroupeTypeFormationServiceAwareTrait;
use Application\Entity\Db\TypeFormation;
use Application\Service\Traits\TypeFormationServiceAwareTrait;
use Application\Exception\DbException;
use Application\Form\GroupeTypeFormation\Traits\GroupeTypeFormationSaisieFormAwareTrait;
use Application\Form\GroupeTypeFormation\Traits\TypeFormationSaisieFormAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
class GroupeTypeFormationController extends AbstractController
{
use GroupeTypeFormationServiceAwareTrait;
use TypeFormationServiceAwareTrait;
use GroupeTypeFormationSaisieFormAwareTrait;
use TypeFormationSaisieFormAwareTrait;
public function indexAction()
{
$this->em()->getFilters()->enable('historique')->init([
GroupeTypeFormation::class,
]);
$this->em()->getFilters()->enable('historique')->init([
TypeFormation::class,
]);
$groupeTypeFormations = $this->getServiceGroupeTypeFormation()->getList();
$typeFormations = $this->getServiceTypeFormation()->getList();
return compact('groupeTypeFormations', 'typeFormations');
}
public function saisieAction()
{
/* @var $groupeTypeFormation GroupeTypeFormation */
$groupeTypeFormation = $this->getEvent()->getParam('groupe-type-formation');
$form = $this->getFormGroupeTypeFormationSaisie();
if (empty($groupeTypeFormation)) {
$title = 'Création d\'une nouvelle GroupeTypeFormation';
$groupeTypeFormation = $this->getServiceGroupeTypeFormation()->newEntity();
} else {
$title = 'Édition d\'une GroupeTypeFormation';
}
$form->bindRequestSave($groupeTypeFormation, $this->getRequest(), function (GroupeTypeFormation $fr) {
try {
$this->getServiceGroupeTypeFormation()->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()
{
$groupeTypeFormation = $this->getEvent()->getParam('groupe-type-formation');
try {
$this->getServiceGroupeTypeFormation()->delete($groupeTypeFormation);
$this->flashMessenger()->addSuccessMessage("GroupeTypeFormation supprimée avec succès.");
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
}
return new MessengerViewModel(compact('groupeTypeFormation'));
}
public function typeFormationSaisieAction()
{
/* @var $groupeTypeFormation GroupeTypeFormation */
/* @var $typeFormation TypeFormation */
$groupeTypeFormation = $this->getEvent()->getParam('groupe-type-formation');
$typeFormation = $this->getEvent()->getParam('type-formation');
$form = $this->getFormTypeFormationSaisie();
if (empty($typeFormation)) {
$title = 'Création d\'un nouveau type de formation';
$typeFormation = $this->getServiceTypeFormation()->newEntity()
->setGroupe($groupeTypeFormation);
$typeFormation->setServiceStatutaire(true);
} else {
$title = 'Édition d\'un Type de Formation';
}
$form->bindRequestSave($typeFormation, $this->getRequest(), function (TypeFormation $tf) {
try {
$this->getServiceTypeFormation()->save($tf);
$this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
} catch (\Exception $e) {
$e = DbException::translate($e);
$this->flashMessenger()->addErrorMessage($e->getMessage() . ':' . $tf->getId());
}
});
return compact('form', 'title');
}
public function typeFormationDeleteAction()
{
/* @var $typeFormation TypeFormation */
$typeFormation = $this->getEvent()->getParam('type-formation');
try {
$this->getServiceTypeFormation()->delete($typeFormation);
$this->flashMessenger()->addSuccessMessage("Type de Formation supprimée avec succès.");
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
}
return new MessengerViewModel(compact('type de formation'));
}
}
......@@ -138,7 +138,7 @@ class CentreCoutStructureHydrator implements HydratorInterface
$object->setStructure($this->getServiceStructure()->get($data['structure']));
}
$object->setSourceCode($data['code']);
$object->setCentreCout($this->getServiceCentreCout()->getById($data['centre-cout']));
$object->setCentreCout($this->getServiceCentreCout()->get($data['centre-cout']));
$object->setSource($this->getServiceSource()->getOse());
$object->setUniteBudgetaire($data['unite-budgetaire']);
......
<?php
namespace Application\Form\GroupeTypeFormation\Traits;
use Application\Form\GroupeTypeFormation\GroupeTypeFormationSaisieForm;
/**
* Description of GroupeTypeFormationSaisieFormAwareTrait
*
* @author UnicaenCode
*/
trait GroupeTypeFormationSaisieFormAwareTrait
{
/**
* @var GroupeTypeFormationSaisieForm
*/
private $formGroupeTypeFormationSaisie;
/**
* @param GroupeTypeFormationSaisieForm $formGroupeTypeFormationSaisie
*
* @return self
*/
public function setFormGroupeTypeFormationSaisie(GroupeTypeFormationSaisieForm $formGroupeTypeFormationSaisie)
{
$this->formGroupeTypeFormationSaisie = $formGroupeTypeFormationSaisie;
return $this;
}
/**
* Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement.
*
* @return GroupeTypeFormationSaisieForm
*/
public function getFormGroupeTypeFormationSaisie()
{
if (!empty($this->formGroupeTypeFormationSaisie)) {
return $this->formGroupeTypeFormationSaisie;
}
return \Application::$container->get('FormElementManager')->get(GroupeTypeFormationSaisieForm::class);
}
}
<?php
namespace Application\Form\GroupeTypeFormation\Traits;
use Application\Form\GroupeTypeFormation\TypeFormationSaisieForm;
/**
* Description of TypeFormationSaisieFormAwareTrait
*
* @author UnicaenCode
*/
trait TypeFormationSaisieFormAwareTrait
{
/**
* @var TypeFormationSaisieForm
*/
private $formTypeFormationSaisie;
/**
* @param TypeFormationSaisieForm $formTypeFormationSaisie
*
* @return self
*/
public function setFormTypeFormationSaisie(TypeFormationSaisieForm $formTypeFormationSaisie)
{
$this->formTypeFormationSaisie = $formTypeFormationSaisie;
return $this;
}
/**
* Retourne un nouveau formulaire ou fieldset systématiquement, sauf si ce dernier a été fourni manuellement.
*
* @return TypeFormationSaisieForm
*/
public function getFormTypeFormationSaisie()
{
if (!empty($this->formTypeFormationSaisie)) {
return $this->formTypeFormationSaisie;
}
return \Application::$container->get('FormElementManager')->get(TypeFormationSaisieForm::class);
}
}
<?php
namespace Application\Form\GroupeTypeFormation;
use Application\Form\AbstractForm;
use Zend\Form\Element\Csrf;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Application\Service\Traits\SourceServiceAwareTrait;
use Application\Service\Traits\GroupeTypeFormationServiceAwareTrait;
/**
* Description of TypeFormationSaisieForm
*
* @author ZVENIGOROSKY Alexandre <alexandre.zvenigorosky@unicaen.fr>
*/
class TypeFormationSaisieForm extends AbstractForm
{
use SourceServiceAwareTrait;
use GroupeTypeFormationServiceAwareTrait;
public function init()
{
$hydrator = new TypeFormationHydrator();
$this->setHydrator($hydrator);
$this->setAttribute('action', $this->getCurrentUrl());
$this->add([
'name' => 'groupe-type-formation',
'options' => [
'label' => "Groupe de type de formation",
],
'type' => 'Hidden',
]);
$this->add([
'name' => 'libelle-court',
'options' => [
'label' => "Libelle Court",
],
'type' => 'Text',
]);
$this->add([
'name' => 'libelle-long',
'options' => [
'label' => "Libelle Long",
],
'type' => 'Text',
]);
$this->add([
'name' => 'source-code',
'options' => [
'label' => "Source Code",
],
'type' => 'Text',
]);
$this->add([
'name' => 'statutaire',
'options' => [
'label' => "Service statutaire",
"checked_value" => 'true',
"unchecked_value" => 'false',
],
'type' => 'Checkbox',
]);
$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-court' => [
'required' => true,
],
'libelle-long' => [
'required' => true,
],
'statutaire' => [
'required' => true,
],
];
}
}
class TypeFormationHydrator implements HydratorInterface
{
use SourceServiceAwareTrait;
use GroupeTypeFormationServiceAwareTrait;
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param \Application\Entity\Db\TypeFormation $object
*
* @return object
*/
public function hydrate(array $data, $object)
{
$object->setGroupe($this->getServiceGroupeTypeFormation()->getById($data['groupe-type-formation']));
$object->setLibelleCourt($data['libelle-court']);
$object->setLibelleLong($data['libelle-long']);
$object->setSourceCode($data['source-code']);
$object->setSource($this->getServiceSource()->getOse());
$object->setServiceStatutaire($data['statutaire']=='true');
return $object;
}
/**
* Extract values from an object
*
* @param \Application\Entity\Db\TypeFormation $object
*
* @return array
*/
public function extract($object)
{
$data = [
'id' => $object->getId()
, 'groupe-type-formation' => $object->getGroupe()->getId()
, 'libelle-court' => $object->getLibelleCourt()
, 'libelle-long' => $object->getLibelleLong()
, 'statutaire' => $object->isServiceStatutaire()?'true':'false'
, 'source-code' => $object->getSourceCode()
, 'source' => ($s = $object->getSource()) ? $s->getId() : null,
];
return $data;
}
}
......@@ -26,6 +26,8 @@ class Privileges extends \UnicaenAuth\Provider\Privilege\Privileges {
const BUDGET_TYPE_DOTATION_EDITION = 'budget-type-dotation-edition';
const BUDGET_TYPE_DOTATION_VISUALISATION = 'budget-type-dotation-visualisation';
const BUDGET_VISUALISATION = 'budget-visualisation';
const CENTRES_COUTS_ADMINISTRATION_EDITION = 'centres-couts-administration-edition';
const CENTRES_COUTS_ADMINISTRATION_VISUALISATION = 'centres-couts-administration-visualisation';
const CHARGENS_DEPASSEMENT_CSV = 'chargens-depassement-csv';
const CHARGENS_EXPORT_CSV = 'chargens-export-csv';
const CHARGENS_FORMATION_ACTIF_EDITION = 'chargens-formation-actif-edition';
......
......@@ -95,36 +95,4 @@ class CentreCoutService extends AbstractEntityService
return $result;
}
/**
* Retourne une entité à partir de son code
* Retourne null si le code est null
*
* @param string|string[] $code
* @return mixed|null
*/
public function getById($id)
{