public function createFromImport($ligne, $output) { $prenomNom = trim($ligne[self::CSV_IDENTITE]); $nom = substr(strrchr($prenomNom, " "), 1); $prenom = trim(str_replace($nom, '', $prenomNom)); $societeAurouze = $this->dm->getRepository('AppBundle:Societe')->findOneByRaisonSociale("AUROUZE"); if (!$societeAurouze) { $output->writeln(sprintf("<error>La société Aurouze n'a pas été trouvée</error>")); return false; } $compte = $this->dm->getRepository('AppBundle:Compte')->findOneByIdentifiantReprise($ligne[self::CSV_IDENTIFIANT]); if (isset($ligne[self::CSV_TYPE])) { if (!$compte) { $tag = new CompteTag(); $tag->setIdentifiant($ligne[self::CSV_TYPE]); $tag->setNom(CompteManager::$tagsCompteLibelles[$ligne[self::CSV_TYPE]]); $this->dm->persist($tag); $compte = new Compte($societeAurouze); $compte->setIdentifiantReprise($ligne[self::CSV_IDENTIFIANT]); $compte->setNom($nom); $compte->setPrenom($prenom); $compte->setCouleur($this->random_color()); $compte->addTag($tag); return $compte; } else { $tag = new CompteTag(); $tag->setIdentifiant($ligne[self::CSV_TYPE]); $tag->setNom(CompteManager::$tagsCompteLibelles[$ligne[self::CSV_TYPE]]); $this->dm->persist($tag); $compte->addTag($tag); return $compte; } } return false; }
public function createContactFromImport($ligne, $output) { $identifiantRepriseEtablissement = $ligne[self::CSV_IDENTIFIANT_REPRISE_ETABLISSEMENT]; $identifiantRepriseSociete = $ligne[self::CSV_IDENTIFIANT_REPRISE_SOCIETE]; $etablissement = $this->dm->getRepository('AppBundle:Etablissement')->findOneByIdentifiantReprise($identifiantRepriseEtablissement); $societe = null; if ($etablissement) { $societe = $etablissement->getSociete(); } if (!$societe) { $societe = $this->dm->getRepository('AppBundle:Societe')->findOneByIdentifiantReprise($identifiantRepriseSociete); } if (!$societe) { $output->writeln(sprintf("\n<error>La société d'identifiant de reprise %s n'a pas été trouvée (etb? = %s)</error>", $identifiantRepriseSociete, $identifiantRepriseEtablissement)); return false; } $compte = new Compte($societe); $compte->setSociete($societe); $compte->setIdentifiantReprise($ligne[self::CSV_IDENTIFIANT_REPRISE_CONTACT]); $compte->setCivilite($this->getCivilite($ligne[self::CSV_CIVILITE])); $compte->setPrenom($ligne[self::CSV_PRENOM]); $compte->setNom($ligne[self::CSV_NOM]); $compte->setIdentite($compte->getIdentite()); $compte->setTitre($this->getTitre($ligne[self::CSV_TITRE])); $contactCoordonnee = new ContactCoordonnee(); $contactCoordonnee->setTelephoneFixe($ligne[self::CSV_TELEPHONE_FIXE]); $contactCoordonnee->setTelephoneMobile($ligne[self::CSV_TELEPHONE_PORTABLE]); $contactCoordonnee->setFax($ligne[self::CSV_FAX]); $contactCoordonnee->setEmail($ligne[self::CSV_EMAIL]); $compte->setContactCoordonnee($contactCoordonnee); $compte->setActif(boolval($ligne[self::CSV_ACTIF])); $adresse = new Adresse(); $compte->setAdresse($adresse); $this->dm->persist($compte); return $compte; }