Пример #1
0
 /**
  * @param DataWindPrev $dataWindPrevAllPrev
  * Delete all data of this dataWindPrev
  */
 static function deleteOldData(DataWindPrev $dataWindPrevAllPrev, EntityManager $em)
 {
     foreach ($dataWindPrevAllPrev->getListPrevisionDate() as $previsionDate) {
         $em->remove($previsionDate);
     }
     $em->flush();
 }
Пример #2
0
 /**
  * @Template()
  *
  * http://localhost/Wind/web/app_dev.php/admin/BO/ajax/spot/1/addSite
  */
 public function spotAddSiteAction($id = null, Request $request)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     if (isset($id) && $id != -1) {
         $spot = $em->find('LaPoizWindBundle:Spot', $id);
         if (!$spot) {
             return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice:errorPage.html.twig', array('errMessage' => "No spot find !"));
         }
         $dataWindPrev = new DataWindPrev();
         $dataWindPrev->setSpot($spot);
         $form = $this->createForm('dataWindPrevForm', $dataWindPrev)->add('add to spot', 'submit');
         if ('POST' == $request->getMethod()) {
             //$form->submit($request);
             $form->handleRequest($request);
             //$form->submit($request->request->get($form->getName()));
             if ($form->isValid()) {
                 // form submit
                 $dataWindPrev = $form->getData();
                 // Uniquement url et spot.
                 // Récupération du webSite grace à l'url
                 $website = WebsiteManage::getWebSiteEntityFromURL($dataWindPrev->getUrl(), $em);
                 if ($website != null) {
                     // Check si le couple spot+website n'existe pas déjà ...
                     $dataWindPrevInDB = $em->getRepository('LaPoizWindBundle:DataWindPrev')->getWithWebsiteAndSpot($website, $spot);
                     if ($dataWindPrevInDB === null) {
                         // OK il n'existe pas dans la BD -> on peut l'ajouter
                         $dataWindPrev->setWebsite($website);
                         if ($dataWindPrev->getWebsite()->getNom() == WebsiteGetData::windguruName) {
                             $dataWindPrevWindGuruPro = clone $dataWindPrev;
                             $dataWindPrevWindGuruPro->getWebsite()->removeDataWindPrev($dataWindPrevWindGuruPro);
                             $windGuruProWebsite = $em->getRepository('LaPoizWindBundle:WebSite')->findByNom(WebsiteGetData::windguruProName)[0];
                             $dataWindPrevWindGuruPro->setWebsite($windGuruProWebsite);
                             $this->saveDataWindPrev($spot, $dataWindPrevWindGuruPro, $em);
                         }
                         $this->saveDataWindPrev($spot, $dataWindPrev, $em);
                         return $this->render('LaPoizWindBundle:BackOffice/Spot/Ajax:addSite.html.twig', array('spot' => $spot, 'form' => $form->createView(), 'create' => false));
                     } else {
                         // Le couple spot et website existe dans la BD
                         $form->get('url')->addError(new FormError('Ce site de prévision est déjà existant pour ce spot.'));
                     }
                 } else {
                     // pas trouvé dfe website correspondant
                     $form->get('url')->addError(new FormError('Site internet non géré par laPoiz.com'));
                 }
             }
         }
         return $this->render('LaPoizWindBundle:BackOffice/Spot/Ajax:addSite.html.twig', array('spot' => $spot, 'form' => $form->createView(), 'create' => false));
     } else {
         return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice:errorPage.html.twig', array('errMessage' => "Miss id of spot... !"));
     }
 }
Пример #3
0
 /**
  * Efface les anciennes PrevisionDate (antérieur à aujourd'hui)
  */
 private static function deleteOldPrevisionDate(DataWindPrev $dataWindPrev, OutputInterface $output, EntityManager $entityManager)
 {
     $output->writeln('<info>****** function deleteOldPrevisionDate ****</info>');
     $today = new \DateTime('now');
     $today->setTime(0, 0, 0);
     foreach ($dataWindPrev->getlistPrevisionDate() as $previsionDate) {
         if ($previsionDate->getDatePrev() < $today) {
             // avant today -> on efface
             try {
                 $entityManager->remove($previsionDate);
                 $output->writeln('<info>delete $previsionDate->getDatePrev : ' . $previsionDate->getDatePrev()->format('Y-m-d H:i:s') . '</info>');
             } catch (\Exception $ex) {
                 $output->writeln("Exception Found - " . $ex->getMessage());
             }
         }
     }
     $entityManager->flush();
     $output->writeln('<info>******</info>');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     // récupere tous les spots
     $listSpot = $em->getRepository('LaPoizWindBundle:Spot')->findAll();
     //$allPrevWebSite = $em->getRepository('LaPoizWindBundle:WebSite')->findWithName(WebsiteGetData::allPrevName);
     $allPrevWebSite = new WebSite();
     $allPrevWebSite->setNom(WebsiteGetData::allPrevName);
     $allPrevWebSite->setUrl("www.lapoiz.com");
     $allPrevWebSite->setLogo("Lapoiz.png");
     $em->persist($allPrevWebSite);
     foreach ($listSpot as $spot) {
         $output->writeln('<info>Note du Spot ' . $spot->getNom() . ' - </info>');
         $dataWindPrevAllPrev = new DataWindPrev();
         $dataWindPrevAllPrev->setUrl('http://www.lapoiz.com');
         $dataWindPrevAllPrev->setWebsite($allPrevWebSite);
         $dataWindPrevAllPrev->setCreated(new \DateTime("now"));
         $dataWindPrevAllPrev->setSpot($spot);
         $spot->addDataWindPrev($dataWindPrevAllPrev);
         $em->persist($dataWindPrevAllPrev);
         $em->persist($spot);
     }
     $output->writeln('<info>**** END ****</info>');
     $em->flush();
 }
Пример #5
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $webSiteWG = new WebSite();
     //$webSiteWG->setNom("Windguru");
     $webSiteWG->setNom(WebsiteGetData::windguruName);
     $webSiteWG->setUrl("www.windguru.cz");
     $webSiteWG->setLogo("Windguru.png");
     $manager->persist($webSiteWG);
     $webSiteWGPro = new WebSite();
     $webSiteWGPro->setNom(WebsiteGetData::windguruProName);
     $webSiteWGPro->setUrl("www.windguru.cz");
     $webSiteWGPro->setLogo("WindguruPro.png");
     $manager->persist($webSiteWGPro);
     $webSiteWF = new WebSite();
     $webSiteWF->setNom(WebsiteGetData::windFinderName);
     $webSiteWF->setUrl("www.windfinder.com");
     $webSiteWF->setLogo("Windfinder.png");
     $manager->persist($webSiteWF);
     $webSiteMF = new WebSite();
     $webSiteMF->setNom(WebsiteGetData::meteoFranceName);
     $webSiteMF->setUrl("http://france.meteofrance.com/");
     $webSiteMF->setLogo("MeteoFrance.png");
     $manager->persist($webSiteMF);
     /*$balise=new Balise();
       $balise->setNom('Balise FFVL de St Aubin');
       $balise->setUrl('http://balisemeteo.com/balise.php?idBalise=56');
       $balise->setDescription('Balise de la Federation Francais de Vol Libre');
       */
     $regionSM = new Region();
     $regionSM->setNom("Seine-Maritime");
     $regionSM->setDescription("Du Havre jusqu'après Dieppe.");
     $regionSM->setNumDisplay(4);
     $manager->persist($regionSM);
     // ************************
     // **** Saint-Aubin *******
     // ************************
     $dataWindPrevWG = new DataWindPrev();
     $dataWindPrevWG->setUrl('http://www.windguru.cz/fr/index.php?sc=3627');
     $dataWindPrevWG->setWebsite($webSiteWG);
     $dataWindPrevWG->setCreated(new \DateTime("now"));
     $dataWindPrevWF = new DataWindPrev();
     $dataWindPrevWF->setUrl('http://www.windfinder.com/forecast/saint_aubin_sur_mer');
     $dataWindPrevWF->setWebsite($webSiteWF);
     $dataWindPrevWF->setCreated(new \DateTime("now"));
     $dataWindPrevMF = new DataWindPrev();
     $dataWindPrevMF->setUrl('http://www.meteofrance.com/previsions-meteo-france/saint-aubin-sur-mer/76740');
     $dataWindPrevMF->setWebsite($webSiteMF);
     $dataWindPrevMF->setCreated(new \DateTime("now"));
     $spot = new Spot();
     $spot->setNom("Saint Aubin");
     $spot->setDescription("Spot avec grande plage, sans risque.");
     $spot->setLocalisationDescription('Proche de Saint-Aubin-sur-mer prendre a gauche dans le début du village: route de Saussemare');
     $spot->setGpsLong('0.862329');
     $spot->setGpsLat('49.892945');
     //$spot->setBalise($balise);
     //$balise->setSpot($spot);
     $dataWindPrevWG->setSpot($spot);
     $dataWindPrevWF->setSpot($spot);
     $dataWindPrevMF->setSpot($spot);
     $spot->addDataWindPrev($dataWindPrevMF);
     $spot->addDataWindPrev($dataWindPrevWG);
     $spot->addDataWindPrev($dataWindPrevWF);
     $spot->setMareeURL("http://maree.info/16");
     $regionSM->addSpot($spot);
     $spot->setRegion($regionSM);
     $manager->persist($dataWindPrevWG);
     $manager->persist($dataWindPrevWF);
     $manager->persist($dataWindPrevMF);
     $manager->persist($spot);
     $manager->persist($regionSM);
     //$manager->persist($balise);
     // ************************
     // **** Alamanarre  *******
     // ************************
     $spot = new Spot();
     $spot->setNom("Almanarre");
     $spot->setDescription("Spot mythique proche de Hyeres.");
     $spot->setLocalisationDescription('A Hyères suivre Giens (D559), puis prendre Route du sel. Le spot est balisé.');
     $spot->setGpsLong('43.056244');
     $spot->setGpsLat('6.133105');
     $dataWindPrevWG = new DataWindPrev();
     $dataWindPrevWG->setUrl('http://www.windguru.cz/fr/index.php?sc=14&sty=m_spot');
     $dataWindPrevWG->setWebsite($webSiteWG);
     $dataWindPrevWG->setCreated(new \DateTime("now"));
     $dataWindPrevWF = new DataWindPrev();
     $dataWindPrevWF->setUrl('http://fr.windfinder.com/forecast/l_almanarre');
     $dataWindPrevWF->setWebsite($webSiteWF);
     $dataWindPrevWF->setCreated(new \DateTime("now"));
     $dataWindPrevMF = new DataWindPrev();
     $dataWindPrevMF->setUrl('http://www.meteofrance.com/previsions-meteo-france/hyeres/83400');
     $dataWindPrevMF->setWebsite($webSiteMF);
     $dataWindPrevMF->setCreated(new \DateTime("now"));
     $dataWindPrevWG->setSpot($spot);
     $dataWindPrevWF->setSpot($spot);
     $dataWindPrevMF->setSpot($spot);
     $spot->addDataWindPrev($dataWindPrevMF);
     $spot->addDataWindPrev($dataWindPrevWG);
     $spot->addDataWindPrev($dataWindPrevWF);
     $manager->persist($dataWindPrevWG);
     $manager->persist($dataWindPrevWF);
     $manager->persist($dataWindPrevMF);
     $manager->persist($spot);
     $manager->flush();
     // ************************
     // **** Sainte-Adresse ****
     // ************************
     $spot = new Spot();
     $spot->setNom("Sainte-Adresse");
     $spot->setDescription("Plage de gros galet.La plage la plus polyvalente quant aux orientations de vent en Haute Normandi.A marée descendante, vent et courant pousse vers le Havre.");
     $spot->setLocalisationDescription('Prendre l’A13 puis la bifurcation jusqu’au Havre. Ensuite suivre les indications pour aller vers la plage. La longer en allant vers le nord jusqu’à Saint-Adresse. On entre dans une petite cité avec voie à sens unique.');
     $spot->setGpsLong('49.505');
     $spot->setGpsLat('0.074');
     $dataWindPrevWG = new DataWindPrev();
     $dataWindPrevWG->setUrl('http://www.windguru.cz/fr/index.php?sc=151625&sty=m_spot');
     $dataWindPrevWG->setWebsite($webSiteWG);
     $dataWindPrevWG->setCreated(new \DateTime("now"));
     $dataWindPrevWF = new DataWindPrev();
     $dataWindPrevWF->setUrl('http://fr.windfinder.com/weatherforecast/port-du-havre-plaisance');
     $dataWindPrevWF->setWebsite($webSiteWF);
     $dataWindPrevWF->setCreated(new \DateTime("now"));
     $dataWindPrevMF = new DataWindPrev();
     $dataWindPrevMF->setUrl('http://www.meteofrance.com/previsions-meteo-france/sainte-adresse/76310');
     $dataWindPrevMF->setWebsite($webSiteMF);
     $dataWindPrevMF->setCreated(new \DateTime("now"));
     $dataWindPrevWG->setSpot($spot);
     $dataWindPrevWF->setSpot($spot);
     $dataWindPrevMF->setSpot($spot);
     $spot->addDataWindPrev($dataWindPrevMF);
     $spot->addDataWindPrev($dataWindPrevWG);
     $spot->addDataWindPrev($dataWindPrevWF);
     $regionSM->addSpot($spot);
     $spot->setRegion($regionSM);
     $manager->persist($dataWindPrevWG);
     $manager->persist($dataWindPrevWF);
     $manager->persist($dataWindPrevMF);
     $manager->persist($spot);
     $manager->persist($regionSM);
     $manager->flush();
 }
 /**
  * @Template()
  *
  * http://localhost/Wind/web/app_dev.php/fo/ajax/spot/ask/create/step3/2/1
  *
  * Etape 3: ajout des website
  */
 public function step3Action($id = null, $idContact = null, Request $request)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     if (isset($id) && $id != -1) {
         $spot = $em->find('LaPoizWindBundle:Spot', $id);
         if (!$spot) {
             return $this->container->get('templating')->renderResponse('LaPoizWindBundle:FrontOffice:errorPage.html.twig', array('errMessage' => "No spot find !"));
         }
         $dataWindPrev = new DataWindPrev();
         $dataWindPrev->setSpot($spot);
         $form = $this->createForm('dataWindPrevForm', $dataWindPrev)->add('Ajoute et test le site', 'submit');
         if ($request->request->get("spot") == null) {
             if ('POST' == $request->getMethod()) {
                 $form->handleRequest($request);
                 if ($form->isValid()) {
                     // form submit
                     $dataWindPrev = $form->getData();
                     // Récupération du webSite grace à l'url
                     $website = WebsiteManage::getWebSiteEntityFromURL($dataWindPrev->getUrl(), $em);
                     if ($website != null) {
                         $dataWindPrevInDB = $em->getRepository('LaPoizWindBundle:DataWindPrev')->getWithWebsiteAndSpot($website, $spot);
                         if ($dataWindPrevInDB === null) {
                             $dataWindPrev->setWebsite($website);
                             // test si l'url est OK
                             $webSite = WebsiteGetData::getWebSiteObject($dataWindPrev);
                             if ($webSite->isDataWindPrevOK($dataWindPrev)) {
                                 // Il est possible de parser le site de cet URL
                                 if ($dataWindPrev->getWebsite()->getNom() == WebsiteGetData::windguruName) {
                                     $dataWindPrevWindGuruPro = clone $dataWindPrev;
                                     $dataWindPrevWindGuruPro->getWebsite()->removeDataWindPrev($dataWindPrevWindGuruPro);
                                     $windGuruProWebsite = $em->getRepository('LaPoizWindBundle:WebSite')->findByNom(WebsiteGetData::windguruProName)[0];
                                     $dataWindPrevWindGuruPro->setWebsite($windGuruProWebsite);
                                     $this->saveDataWindPrev($spot, $dataWindPrevWindGuruPro, $em);
                                 }
                                 $this->saveDataWindPrev($spot, $dataWindPrev, $em);
                                 // clean the form and display it
                                 $dataWindPrev = new DataWindPrev();
                                 $dataWindPrev->setSpot($spot);
                                 $form = $this->createForm('dataWindPrevForm', $dataWindPrev)->add('Ajoute et test le site', 'submit');
                                 return $this->render('LaPoizWindBundle:FrontOffice:AskNewSpot/blockAddSite.html.twig', array('form' => $form->createView(), 'spot' => $spot, 'idContact' => $idContact));
                             } else {
                                 // URL n'est pas bonne
                                 return new JsonResponse(array('message' => $website->getNom() . ' est déjà spécifié pour ce spot'), 419);
                             }
                         } else {
                             // URL n'est pas bonne
                             return new JsonResponse(array('message' => 'Impossible de parser l URL'), 419);
                         }
                     } else {
                         // URL n'est pas bonne
                         return new JsonResponse(array('message' => 'Cette URL ne correspond à aucun site parser par LaPoizWind.'), 419);
                     }
                 }
                 /*else {
                       return new Response($request);
                   }*/
             }
         }
         return $this->render('LaPoizWindBundle:FrontOffice:AskNewSpot/step3.html.twig', array('spot' => $spot, 'form' => $form->createView(), 'idContact' => $idContact));
     } else {
         return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice:errorPage.html.twig', array('errMessage' => "Miss id of spot... !"));
     }
 }
Пример #7
0
 /**
  * Add dataWindPrev
  *
  * @param LaPoiz\WindBundle\Entity\DataWindPrev $dataWindPrev
  */
 public function addDataWindPrev(\LaPoiz\WindBundle\Entity\DataWindPrev $dataWindPrev)
 {
     $this->dataWindPrev[] = $dataWindPrev;
     $dataWindPrev->setWebsite($this);
 }