Esempio n. 1
0
 public function postPersist($category)
 {
     if ($category->getDestination()->getId() != 10) {
         return;
     }
     $manager = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
     $fechaInicio = strtotime(Date('d') . "-" . Date('m') . "-" . $category->getYear());
     $fechaFin = strtotime("31-12-" . $category->getYear());
     for ($i = $fechaInicio; $i <= $fechaFin; $i += 86400) {
         $tourDate = new TourDate();
         $tourDate->setDate(new \DateTime(date("d-m-Y", $i)));
         $tourDate->setAvailability(null);
         $tourDate->setCategory($category);
         $manager->persist($tourDate);
     }
     $manager->flush();
 }
Esempio n. 2
0
 public function import(Destination $dest, $month, $year)
 {
     $url = 'http://www.machupicchu.gob.pe/rpt//DisponibilidadPorMes.cfm?idLugar=' . $dest->getId() . '&mes=' . $month . '&ano=' . $year;
     $fn = __DIR__ . '/d.pdf';
     $return = true;
     file_put_contents($fn, file_get_contents($url));
     $pdf = new Pdf($fn);
     $paragraphs = $pdf->html()->find('p.ft03');
     $ret = array();
     $curr = 0;
     foreach ($paragraphs as $i => $p) {
         if ($i == 0) {
             continue;
         }
         if ($i % 2 != 0) {
             $curr = $p->text();
         } else {
             $ret[$curr] = $p->text();
         }
     }
     if (empty($ret)) {
         $return = false;
         $date = Carbon::createFromDate($year, $month, 1);
         $lastDayofMonth = $date->format('t') + 1;
         $ret = array();
         for ($i = 1; $i < $lastDayofMonth; $i++) {
             $ret[$i] = 0;
         }
     }
     echo '<pre>';
     var_dump($ret);
     foreach ($ret as $day => $availability) {
         $date = Carbon::createFromDate($year, $month, $day);
         $e = $this->getContainer()->get('doctrine')->getRepository('AppBundle:TourDate')->findOneBy(array('date' => $date, 'destination' => $dest));
         if (empty($e)) {
             $e = new TourDate();
             $e->setDestination($dest);
             $e->setDate($date);
         }
         $e->setAvailability($availability);
         $this->getContainer()->get('doctrine')->getEntityManager()->persist($e);
         $this->getContainer()->get('doctrine')->getEntityManager()->flush();
     }
     return $return;
 }