Commit 78078406 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Merge branch 'main' of https://git.unicaen.fr/lib/unicaen/etat into HEAD

parents 854bf105 9977ffca
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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,
                    ],
+8 −2
Original line number Diff line number Diff line
@@ -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);
@@ -29,6 +34,7 @@ class EtatTypeFormFactory {
        $form = new EtatTypeForm();
        $form->setEntityManager($entityManager);
        $form->setEtatCategorieService($etatCategorieService);
        $form->setEtatTypeService($etatTypeService);
        $form->setHydrator($hydrator);

        return $form;
+2 −2
Original line number Diff line number Diff line
@@ -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,
@@ -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);
+7 −1
Original line number Diff line number Diff line
@@ -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
@@ -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;
    }

+1 −1
Original line number Diff line number Diff line
@@ -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