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
Loading
Loading
Loading
Loading
+7 −0
Changes for module/Application/src/ORM/Event/Listeners/ParametreEntityListener.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;
+14 −1
Changes for module/Application/src/ORM/RouteEntitiesInjector.php: 14 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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;