Commit b216c145 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Les types de structures sont de nouveau correctement synchronisés avec le connecteur.

Le label reçu est correctement convertit en Objet
parent f615fc8e
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -67,8 +67,10 @@ class ConnectorOrganizationREST extends AbstractConnector
     */
    protected function factory(){
        static $factory;
        if( $factory === null )
            $factory = new JsonToOrganization();
        if( $factory === null ) {
            $types = $this->getRepository()->getTypesKeyLabel();
            $factory = new JsonToOrganization($types);
        }
        return $factory;
    }

+1 −0
Original line number Diff line number Diff line
@@ -412,6 +412,7 @@ class Organization implements ResourceInterface, IConnectedObject
    public function setTypeObj($typeObj)
    {
        $this->typeObj = $typeObj;
        return $this;
    }

    /**
+11 −0
Original line number Diff line number Diff line
@@ -232,5 +232,16 @@ class OrganizationRepository extends EntityRepository implements IConnectedRepos
        return $qb->getSingleResult();
    }

    public function getTypesKeyLabel() :array
    {
        $types = $this->getEntityManager()->getRepository(OrganizationType::class)->findAll();
        $out = [];
        /** @var OrganizationType $organizationType */
        foreach ($types as $organizationType){
            $out[$organizationType->getLabel()] = $organizationType;
        }
        return $out;
    }


}
 No newline at end of file
+14 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ namespace Oscar\Factory;


use Oscar\Entity\Organization;
use Oscar\Entity\OrganizationType;

/**
 * Class JsonToPersonFactory
@@ -17,9 +18,20 @@ use Oscar\Entity\Organization;
 */
class JsonToOrganization extends JsonToObject implements IJsonToOrganisation
{
    public function __construct()
    public function __construct($types)
    {
        parent::__construct(['uid', 'code', 'shortname']);
        $this->types = $types;
    }

    private ?array $types;

    protected function getTypeObj( string $typeLabel ) :?OrganizationType
    {
        if( is_array($this->types) && array_key_exists($typeLabel, $this->types) ){
            return $this->types[$typeLabel];
        }
        return null;
    }

    /**
@@ -50,7 +62,6 @@ class JsonToOrganization extends JsonToObject implements IJsonToOrganisation
                $this->getFieldValue($jsonData, 'uid')
            );
        }

        $object
            ->setDateUpdated(new \DateTime($this->getFieldValue($jsonData, 'dateupdate', null)))
            ->setLabintel($this->getFieldValue($jsonData, 'labintel', null))
@@ -63,6 +74,7 @@ class JsonToOrganization extends JsonToObject implements IJsonToOrganisation
            ->setUrl($this->getFieldValue($jsonData, 'url'))
            ->setSiret($this->getFieldValue($jsonData, 'siret'))
            ->setType($this->getFieldValue($jsonData, 'type'))
            ->setTypeObj($this->getTypeObj($this->getFieldValue($jsonData, 'type')))

            // Ajout de champs
            ->setDuns($this->getFieldValue($jsonData, 'duns'))
@@ -82,7 +94,6 @@ class JsonToOrganization extends JsonToObject implements IJsonToOrganisation
            }
        }


        return $object;
    }
}
 No newline at end of file