Skip to content
Snippets Groups Projects
Commit 01bf24b9 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Correction bug saisie référentiel

parent d3eb116d
No related branches found
No related tags found
No related merge requests found
......@@ -229,6 +229,9 @@ class ServiceReferentielService extends AbstractEntityService
$entity->setIntervenant($intervenant);
}
$entity->setSource($this->getServiceSource()->getOse());
$entity->setSourceCode(uniqid('ose-'));
return $entity;
}
......@@ -244,8 +247,7 @@ class ServiceReferentielService extends AbstractEntityService
public function save($entity)
{
$role = $this->getServiceContext()->getSelectedIdentityRole();
$this->getEntityManager()->beginTransaction();
try {
if (!$entity->getIntervenant() && $intervenant = $role->getIntervenant()) {
$entity->setIntervenant($intervenant);
}
......@@ -254,7 +256,7 @@ class ServiceReferentielService extends AbstractEntityService
}
$serviceAllreadyExists = null;
if (!$entity->getId()) { // uniquement pour les nouveaux services!!
$serviceAllreadyExists = $this->getBy(
$entity->getIntervenant(),
$entity->getFonctionReferentiel(),
......@@ -263,57 +265,36 @@ class ServiceReferentielService extends AbstractEntityService
$entity->getMotifNonPaiement(),
$entity->getCommentaires()
);
}
//@TODO probleme de supression
//On regarde dans le cas d'un modification d'un service reférentiel
// Enregistrement en BDD
$this->getEntityManager()->beginTransaction();
try {
if ($serviceAllreadyExists) {
$result = $serviceAllreadyExists;
if ($result->getId() != $entity->getId()) {
//on remove l'ancien service puisque les volumes horaires vont être accrochés sur un service déjà existant
parent::delete($entity);
} else {
$result = parent::save($entity);
}
} else {
$sourceOse = $this->getServiceSource()->getOse();
if (!$entity->getSource()) {
$entity->setSource($sourceOse);
}
if (!$entity->getSourceCode()) {
$entity->setSourceCode(uniqid('ose-'));
}
// on déplace les nouveaux volumes horaires sur l'ancien
foreach ($entity->getVolumeHoraireReferentiel() as $vhr) {
if (!$vhr->getSource()) {
$vhr->setSource($sourceOse);
$vhr->setServiceReferentiel($serviceAllreadyExists);
$this->getEntityManager()->persist($vhr);
}
if (!$vhr->getSourceCode()) {
$vhr->setSourceCode(uniqid('ose-'));
// l'ancien remplace le nouveau
$entity = $serviceAllreadyExists;
}
}
$result = parent::save($entity);
}
/* Sauvegarde automatique des volumes horaires associés */
$serviceVolumeHoraire = $this->getServiceVolumeHoraireReferentiel();
$entity = parent::save($entity);
foreach ($entity->getVolumeHoraireReferentiel() as $volumeHoraire) {
if ($result !== $entity) $volumeHoraire->setServiceReferentiel($result);
if ($volumeHoraire->getRemove()) {
$serviceVolumeHoraire->delete($volumeHoraire);
$this->getServiceVolumeHoraireReferentiel()->delete($volumeHoraire);
} else {
$serviceVolumeHoraire->save($volumeHoraire);
$this->getServiceVolumeHoraireReferentiel()->save($volumeHoraire);
}
}
$this->getEntityManager()->commit();
} catch (Exception $e) {
} catch (\Exception $e) {
$this->getEntityManager()->rollBack();
throw $e;
}
return $result;
return $entity;
}
......
......@@ -58,11 +58,24 @@ class VolumeHoraireReferentielService extends AbstractEntityService
$entity = parent::newEntity();
$entity->setTypeVolumeHoraire($this->getServiceTypeVolumeHoraire()->getPrevu());
$entity->setSource($this->getServiceSource()->getOse());
$entity->setSourceCode(uniqid('ose-'));
return $entity;
}
public function populateAutoValidation(VolumeHoraireReferentiel $entity)
{
$typeVolumeHoraire = $entity->getTypeVolumeHoraire();
$canAutoValidate = $this->getAuthorize()->isAllowed($entity, $typeVolumeHoraire->getPrivilegeReferentielAutoValidation());
if ($canAutoValidate) $entity->setAutoValidation(true);
}
/**
* Sauvegarde une entité
*
......@@ -73,17 +86,7 @@ class VolumeHoraireReferentielService extends AbstractEntityService
*/
public function save($entity)
{
if (!$entity->getSource()) {
$entity->setSource($this->getServiceSource()->getOse());
}
if (!$entity->getSourceCode()) {
$entity->setSourceCode(uniqid('ose-'));
}
$typeVolumeHoraire = $entity->getTypeVolumeHoraire();
$canAutoValidate = $this->getAuthorize()->isAllowed($entity, $typeVolumeHoraire->getPrivilegeReferentielAutoValidation());
if ($canAutoValidate) $entity->setAutoValidation(true);
$this->populateAutoValidation($entity);
return parent::save($entity);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment