예제 #1
0
 /**
  * @{inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     // Adhérent 1
     $adherent = new Adherent();
     $adherent->setNom("Nom 1");
     $adherent->setPrenom("Prenom 1");
     $adherent->setEmail("email@localhost");
     $adherent->setAdresse("1bis rue de la Fosse");
     $adherent->setCodePostal("44000");
     $adherent->setVille("Nantes");
     $adherent->setDateNaissance(\DateTime::createFromFormat("Y-m-d", "1980-07-15"));
     $adherent->setDateAdhesion(\DateTime::createFromFormat("Y-m-d", "2013-09-20"));
     $adherent->setAnnee($this->getReference("annee-2013"));
     $manager->persist($adherent);
     // Adhérent 2
     $adherent = new Adherent();
     $adherent->setNom("Nom 2");
     $adherent->setPrenom("Prenom 2");
     $adherent->setEmail("email2@localhost");
     $adherent->setAdresse("Appartement 12\n17 Paul Bellamy");
     $adherent->setCodePostal("44000");
     $adherent->setVille("Nantes");
     $adherent->setDateNaissance(\DateTime::createFromFormat("Y-m-d", "1970-01-13"));
     $adherent->setDateAdhesion(\DateTime::createFromFormat("Y-m-d", "2013-10-25"));
     $adherent->setAnnee($this->getReference("annee-2013"));
     $manager->persist($adherent);
     // Flush
     $manager->flush();
 }
예제 #2
0
 /**
  * @param Annee $annee
  * @param UploadedFile $fichier
  * @param array $erreurs
  * @return number
  */
 public function importAdherents($annee, $fichier, &$erreurs)
 {
     $this->em->beginTransaction();
     try {
         $nbLignes = 0;
         $handle = fopen($fichier->getRealPath(), "r");
         $headers = fgetcsv($handle);
         while ($data = fgetcsv($handle)) {
             if (count($data) != 10) {
                 array_push($erreurs, $this->translator->trans('patlenain_gas.adherent.import.erreur.nombreChampsIncorrect', array('%ligne%' => $nbLignes + 1)));
             } else {
                 $adherent = new Adherent();
                 $adherent->setNom($data[0]);
                 $adherent->setPrenom($data[1]);
                 $adherent->setEmail($data[2]);
                 $adherent->setAdresse($data[3]);
                 $adherent->setCodePostal($data[4]);
                 $adherent->setVille($data[5]);
                 $adherent->setNumeroFixe($data[6]);
                 $adherent->setNumeroPortable($data[7]);
                 $dateNaissance = DateTime::createFromFormat("d/m/Y", $data[8]);
                 $adherent->setDateNaissance($dateNaissance);
                 $dateAdhesion = null;
                 if ($data[9]) {
                     $dateAdhesion = DateTime::createFromFormat("d/m/Y", $data[9]);
                 }
                 $adherent->setDateNaissance($dateNaissance);
                 $adherent->setAnnee($annee);
                 $this->em->persist($adherent);
             }
             $nbLignes++;
         }
         if (count($erreurs) > 0) {
             $this->em->rollback();
         } else {
             $this->em->commit();
         }
         fclose($handle);
     } catch (\Exception $e) {
         $this->em->rollback();
         fclose($handle);
         throw $e;
     }
     return $nbLignes;
 }