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

Recherche de l'entité de paramètre ayant la bonne année automatiquement si...

Recherche de l'entité de paramètre ayant la bonne année automatiquement si l'année donnée n'est pas la bonne
parent f703df2b
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,13 @@ class ParametreEntityListener implements EventSubscriber
public function setEntityManager(EntityManager $entityManager)
{
$this->em = $entityManager;
}
protected function save(LifecycleEventArgs $args)
{
if ($this->isSaving) return;
......
......@@ -5,7 +5,10 @@ namespace Application\ORM;
use Application\Cache\Traits\CacheContainerTrait;
use Application\Entity\Db\TypeAgrement;
use Application\Interfaces\ParametreEntityInterface;
use Application\ORM\Event\Listeners\ParametreEntityListener;
use Application\Service\IntervenantService;
use Application\Service\Traits\ContextServiceAwareTrait;
use Laminas\Mvc\MvcEvent;
use UnicaenApp\Service\EntityManagerAwareTrait;
......@@ -18,6 +21,7 @@ class RouteEntitiesInjector
{
use CacheContainerTrait;
use EntityManagerAwareTrait;
use ContextServiceAwareTrait;
public function __invoke(MvcEvent $e)
......@@ -50,7 +54,16 @@ class RouteEntitiesInjector
if (array_key_exists($name, $entityParams)) {
if (0 !== (int)$value) {
$repo = $this->getEntityManager()->getRepository($entityParams[$name]);
$e->setParam($name, $repo->find($value));
$entity = $repo->find($value);
if ($entity instanceof ParametreEntityInterface) {
$annee = $this->getServiceContext()->getAnnee();
if ($entity->getAnnee() != $annee) {
$pel = new ParametreEntityListener();
$pel->setEntityManager($this->getEntityManager());
$entity = $pel->entityAutreAnnee($entity, $annee);
}
}
$e->setParam($name, $entity);
}
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment