Commit 776203fe authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

Ajout process fichier json

parent 65fc5642
Loading
Loading
Loading
Loading
+3 −54
Original line number Diff line number Diff line
@@ -23,19 +23,19 @@ class ImmobilierLocal
     * @var string
     * @ORM\Column(type="text", nullable="true")
     */
    private $nom;
    public $nom;

    /**
     * @var string
     * @ORM\Column(type="text", nullable="true")
     */
    private $libelle;
    public $libelle;

    /**
     * @var string
     * @ORM\Column(type="text", nullable="true")
     */
    private $idSourceDistante;
    public $idSourceDistante;

    /**
     * @return mixed
@@ -44,55 +44,4 @@ class ImmobilierLocal
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getNom(): string
    {
        return $this->nom;
    }

    /**
     * @param string $nom
     */
    public function setNom(string $nom): self
    {
        $this->nom = $nom;
        return $this;
    }

    /**
     * @return string
     */
    public function getLibelle(): string
    {
        return $this->libelle;
    }

    /**
     * @param string $libelle
     */
    public function setLibelle(string $libelle): self
    {
        $this->libelle = $libelle;
        return $this;
    }

    /**
     * @return string
     */
    public function getIdSourceDistante(): string
    {
        return $this->idSourceDistante;
    }

    /**
     * @param string $idSourceDistante
     */
    public function setIdSourceDistante(string $idSourceDistante): self
    {
        $this->idSourceDistante = $idSourceDistante;
        return $this;
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -19,7 +19,29 @@ class ImmobilierLocalService implements UseEntityManager, UseLoggerService, UseO
  {
    $logs = array();

    if (!array_key_exists('_embedded', $data)) {
      $logs[] = 'Clé _embedded non présente dans le JSON des données';
      return $logs;
    }
    $embedded = $data['_embedded'];
    if (!array_key_exists('immobilier-local', $embedded)) {
      $logs[] = "Clé ['_embedded']['immobilier-local'] non présente dans le JSON des données";
      return $logs;
    }
    $immobilierLocalArray = $embedded['immobilier-local'];
    if (!is_array($immobilierLocalArray)) {
      $logs[] = "La clé ['_embedded']['immobilier-local'] dans le JSON doit être un tableau de données";
      return $logs;
    }

    foreach ($immobilierLocalArray as $i) {
      $e = new \Oscar\Entity\ImmobilierLocal();
      $e->nom = $i['nom'];
      $e->libelle = $i['libelle'];
      $e->idSourceDistante = $i['id'];
      $this->getEntityManager()->persist($e);
      $this->getEntityManager()->flush();
    }
    
    return $logs;
  }