Loading src/UnicaenEtat/Form/EtatType/EtatTypeForm.php +4 −1 Original line number Diff line number Diff line Loading @@ -14,10 +14,12 @@ use Laminas\Form\Element\Text; use Laminas\Form\Form; use Laminas\InputFilter\Factory; use Laminas\Validator\Callback; use UnicaenEtat\Service\EtatType\EtatTypeServiceAwareTrait; class EtatTypeForm extends Form { use EtatCategorieServiceAwareTrait; use EtatTypeServiceAwareTrait; use EntityManagerAwareTrait; private ?string $oldCode = null; Loading Loading @@ -138,7 +140,8 @@ class EtatTypeForm extends Form ], 'callback' => function ($value, $context = []) { if($value == $context['old-code']) return true; return ($this->getEntityManager()->getRepository(EtatType::class)->findOneBy(['code'=>$value],[]) == null); // return ($this->getEntityManager()->getRepository(EtatType::class)->findOneBy(['code'=>$value],[]) == null);; return ($this->getEtatTypeService()->getEtatTypeByCode($value, $context['categorie']) == null); }, //'break_chain_on_failure' => true, ], Loading src/UnicaenEtat/Form/EtatType/EtatTypeFormFactory.php +8 −2 Original line number Diff line number Diff line Loading @@ -4,24 +4,29 @@ namespace UnicaenEtat\Form\EtatType; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenEtat\Service\EtatCategorie\EtatCategorieService; use UnicaenEtat\Service\EtatType\EtatTypeService; class EtatTypeFormFactory { /** * @param ContainerInterface $container * @return EtatTypeForm * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container) : EtatTypeForm { /** * @var EntityManager $entityManager * @var EtatCategorieService $etatCategorieService * @var EtatTypeService $etatTypeService */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $etatCategorieService = $container->get(EtatCategorieService::class); $etatTypeService = $container->get(EtatTypeService::class); /** @var EtatTypeHydrator $hydrator */ $hydrator = $container->get('HydratorManager')->get(EtatTypeHydrator::class); Loading @@ -29,6 +34,7 @@ class EtatTypeFormFactory { $form = new EtatTypeForm(); $form->setEntityManager($entityManager); $form->setEtatCategorieService($etatCategorieService); $form->setEtatTypeService($etatTypeService); $form->setHydrator($hydrator); return $form; Loading src/UnicaenEtat/Form/EtatType/EtatTypeHydrator.php +2 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ class EtatTypeHydrator implements HydratorInterface { $data = [ 'code' => ($object)?$object->getCode():null, 'libelle' => ($object)?$object->getLibelle():null, 'categorie' => ($object AND $object->getCategorie())?$object->getCategorie()->getId():null, 'categorie' => ($object AND $object->getCategorie())?$object->getCategorie()->getCode():null, 'icone' => ($object)?$object->getIcone():null, 'couleur' => ($object)?$object->getCouleur():null, 'ordre' => ($object)?$object->getOrdre():9999, Loading @@ -37,7 +37,7 @@ class EtatTypeHydrator implements HydratorInterface { $libelle = (isset($data['libelle']) AND trim($data['libelle']) !== "")?trim($data['libelle']):null; $icone = (isset($data['icone']) AND trim($data['icone']) !== "")?trim($data['icone']):null; $couleur = (isset($data['couleur']) AND trim($data['couleur']) !== "")?trim($data['couleur']):null; $categorie = isset($data['categorie'])?$this->getEtatCategorieService()->getEtatCategorie((int) $data['categorie']):null; $categorie = isset($data['categorie'])?$this->getEtatCategorieService()->getEtatCategorieByCode($data['categorie']):null; $ordre = (isset($data['ordre']) AND trim($data['ordre']) !== "")?trim($data['ordre']):9999; $object->setCode($code); Loading src/UnicaenEtat/Form/SelectionEtat/SelectionEtatHydrator.php +7 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,12 @@ class SelectionEtatHydrator implements HydratorInterface { use EtatTypeServiceAwareTrait; use EtatInstanceServiceAwareTrait; private ?string $categorie; public function setCategorie(?string $categorie): void { $this->categorie = $categorie; } /** * @param HasEtatInterface|HasEtatsInterface $object * @return array Loading @@ -36,7 +42,7 @@ class SelectionEtatHydrator implements HydratorInterface { public function hydrate(array $data, object $object): object { $etat = (isset($data['etat']))?$this->getEtatTypeService()->getEtatType($data['etat']):null; if ($etat) $this->getEtatInstanceService()->setEtatActif($object, $etat->getCode()); if ($etat) $this->getEtatInstanceService()->setEtatActif($object, $etat->getCode(), $this->categorie); return $object; } Loading src/UnicaenEtat/Service/EtatCategorie/EtatCategorieService.php +1 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ class EtatCategorieService { $result = $this->getEtatsCategories($champ,$ordre); $array = []; foreach ($result as $item) { $array[$item->getId()] = $item->getLibelle(); $array[$item->getCode()] = $item->getLibelle(); } return $array; } Loading Loading
src/UnicaenEtat/Form/EtatType/EtatTypeForm.php +4 −1 Original line number Diff line number Diff line Loading @@ -14,10 +14,12 @@ use Laminas\Form\Element\Text; use Laminas\Form\Form; use Laminas\InputFilter\Factory; use Laminas\Validator\Callback; use UnicaenEtat\Service\EtatType\EtatTypeServiceAwareTrait; class EtatTypeForm extends Form { use EtatCategorieServiceAwareTrait; use EtatTypeServiceAwareTrait; use EntityManagerAwareTrait; private ?string $oldCode = null; Loading Loading @@ -138,7 +140,8 @@ class EtatTypeForm extends Form ], 'callback' => function ($value, $context = []) { if($value == $context['old-code']) return true; return ($this->getEntityManager()->getRepository(EtatType::class)->findOneBy(['code'=>$value],[]) == null); // return ($this->getEntityManager()->getRepository(EtatType::class)->findOneBy(['code'=>$value],[]) == null);; return ($this->getEtatTypeService()->getEtatTypeByCode($value, $context['categorie']) == null); }, //'break_chain_on_failure' => true, ], Loading
src/UnicaenEtat/Form/EtatType/EtatTypeFormFactory.php +8 −2 Original line number Diff line number Diff line Loading @@ -4,24 +4,29 @@ namespace UnicaenEtat\Form\EtatType; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenEtat\Service\EtatCategorie\EtatCategorieService; use UnicaenEtat\Service\EtatType\EtatTypeService; class EtatTypeFormFactory { /** * @param ContainerInterface $container * @return EtatTypeForm * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container) : EtatTypeForm { /** * @var EntityManager $entityManager * @var EtatCategorieService $etatCategorieService * @var EtatTypeService $etatTypeService */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $etatCategorieService = $container->get(EtatCategorieService::class); $etatTypeService = $container->get(EtatTypeService::class); /** @var EtatTypeHydrator $hydrator */ $hydrator = $container->get('HydratorManager')->get(EtatTypeHydrator::class); Loading @@ -29,6 +34,7 @@ class EtatTypeFormFactory { $form = new EtatTypeForm(); $form->setEntityManager($entityManager); $form->setEtatCategorieService($etatCategorieService); $form->setEtatTypeService($etatTypeService); $form->setHydrator($hydrator); return $form; Loading
src/UnicaenEtat/Form/EtatType/EtatTypeHydrator.php +2 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ class EtatTypeHydrator implements HydratorInterface { $data = [ 'code' => ($object)?$object->getCode():null, 'libelle' => ($object)?$object->getLibelle():null, 'categorie' => ($object AND $object->getCategorie())?$object->getCategorie()->getId():null, 'categorie' => ($object AND $object->getCategorie())?$object->getCategorie()->getCode():null, 'icone' => ($object)?$object->getIcone():null, 'couleur' => ($object)?$object->getCouleur():null, 'ordre' => ($object)?$object->getOrdre():9999, Loading @@ -37,7 +37,7 @@ class EtatTypeHydrator implements HydratorInterface { $libelle = (isset($data['libelle']) AND trim($data['libelle']) !== "")?trim($data['libelle']):null; $icone = (isset($data['icone']) AND trim($data['icone']) !== "")?trim($data['icone']):null; $couleur = (isset($data['couleur']) AND trim($data['couleur']) !== "")?trim($data['couleur']):null; $categorie = isset($data['categorie'])?$this->getEtatCategorieService()->getEtatCategorie((int) $data['categorie']):null; $categorie = isset($data['categorie'])?$this->getEtatCategorieService()->getEtatCategorieByCode($data['categorie']):null; $ordre = (isset($data['ordre']) AND trim($data['ordre']) !== "")?trim($data['ordre']):9999; $object->setCode($code); Loading
src/UnicaenEtat/Form/SelectionEtat/SelectionEtatHydrator.php +7 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,12 @@ class SelectionEtatHydrator implements HydratorInterface { use EtatTypeServiceAwareTrait; use EtatInstanceServiceAwareTrait; private ?string $categorie; public function setCategorie(?string $categorie): void { $this->categorie = $categorie; } /** * @param HasEtatInterface|HasEtatsInterface $object * @return array Loading @@ -36,7 +42,7 @@ class SelectionEtatHydrator implements HydratorInterface { public function hydrate(array $data, object $object): object { $etat = (isset($data['etat']))?$this->getEtatTypeService()->getEtatType($data['etat']):null; if ($etat) $this->getEtatInstanceService()->setEtatActif($object, $etat->getCode()); if ($etat) $this->getEtatInstanceService()->setEtatActif($object, $etat->getCode(), $this->categorie); return $object; } Loading
src/UnicaenEtat/Service/EtatCategorie/EtatCategorieService.php +1 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ class EtatCategorieService { $result = $this->getEtatsCategories($champ,$ordre); $array = []; foreach ($result as $item) { $array[$item->getId()] = $item->getLibelle(); $array[$item->getCode()] = $item->getLibelle(); } return $array; } Loading