public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $cpt = 0;
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     if (!$configuration) {
         $configuration = new Configuration();
         $configuration->setId(Configuration::PREFIX);
         $this->dm->persist($configuration);
         $this->dm->flush();
     }
     foreach ($csv as $data) {
         $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
         $founded = false;
         foreach ($configuration->getPrestationsArray() as $prestaConf) {
             if ($prestaConf->getNom() == $data[self::CSV_NOM]) {
                 $founded = true;
             }
         }
         if ($founded) {
             continue;
         }
         if ($data[self::CSV_ID]) {
             $prestation = new Prestation();
             $prestation->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_ID])))));
             $prestation->setNom($data[self::CSV_NOM]);
             $prestation->setNomCourt($data[self::CSV_NOM_COURT]);
             $configuration->addPrestation($prestation);
             $this->dm->flush();
         }
     }
 }
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $cpt = 0;
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     if (!$configuration) {
         $configuration = new Configuration();
         $configuration->setId(Configuration::PREFIX);
     }
     foreach ($csv as $data) {
         $produit = new Produit();
         $produit->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_NOM])))));
         $produit->setNom(ucfirst(strtolower($data[self::CSV_NOM])));
         $produit->setConditionnement($data[self::CSV_CONDITIONNEMENT]);
         $produit->setPrixHt($data[self::CSV_PRIX_HT]);
         $produit->setPrixPrestation($data[self::CSV_PRIX_PRESTATION]);
         $produit->setPrixVente($data[self::CSV_PRIX_VENTE]);
         if ($data[self::CSV_STATUT]) {
             $produit->setStatut(Produit::PRODUIT_ACTIF);
         } else {
             $produit->setStatut(Produit::PRODUIT_INACTIF);
         }
         $configuration->addProduit($produit);
         $this->dm->persist($configuration);
     }
     $this->dm->flush();
 }
Пример #3
0
 /**
  * @Route("/configuration-modification-provenances", name="configuration_modification_provenances")
  */
 public function modificationProvenancesAction(Request $request)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $configuration = $dm->getRepository('AppBundle:Configuration')->findConfiguration();
     if (!$configuration) {
         $configuration = new Configuration();
         $configuration->setId(Configuration::PREFIX);
         $dm->persist($configuration);
         $dm->flush();
     }
     $form = $this->createForm(new ConfigurationProvenancesType($this->container, $dm), $configuration, array('action' => $this->generateUrl('configuration_modification_provenances'), 'method' => 'POST'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $configuration = $form->getData();
         $dm->persist($configuration);
         $dm->flush();
         return $this->redirectToRoute('configuration');
     }
     return $this->render('configuration/modificationProvenances.html.twig', array('configuration' => $configuration, 'form' => $form->createView()));
 }