示例#1
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;
 }
 /**
  * @Route("/add_meta/{destination}", name="add_meta")
  */
 public function add_metaAction(Request $request, $destination)
 {
     $trip = new Destination();
     $trip->setDestination($destination);
     $trip->setName($this->get('security.token_storage')->getToken()->getUser());
     $trip->setCreationDate();
     $trip->setModifyDate();
     $form = $this->createFormBuilder($trip)->add('departure_date', 'date')->add('arrival_date', 'date')->add('insert', 'submit', array('label' => 'Invia'))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $em = $this->getDoctrine()->getManager();
         $em->persist($trip);
         $em->flush();
         return $this->redirectToRoute('profile');
     }
     // replace this example code with whatever you need
     return $this->render('AppBundle::add_meta.html.twig', array("destination" => $destination, 'form' => $form->createView()));
 }
示例#3
0
文件: LoadData.php 项目: jmiridis/atc
 protected function loadDestinations(ObjectManager $manager)
 {
     echo "\nDestinations ... ";
     // 'title','description','active','created_at','updated_at','seq_num','slug),
     $destinations = array(array('Cancun Hotel Zone', 'CANCUN Z. HOTELES', true, '1', 'cancun-hotel-zone'), array('Bahia Petempich', 'BAHIA PETENPICH', true, '2', 'bahia-petempich'), array('Puerto Morelos', 'PUERTO MORELOS', true, '5', 'puerto-morelos'), array('Playa del Carmen / Playacar', 'PLAYA DEL CARMEN / PLAYACAR', true, '6', 'playa-del-carmen-playacar'), array('Akumal - Kantenah', 'AKUMAL - KANTENAH', true, '8', 'akumal-kantenah'), array('Tulum & Hotel Zone Tulum', 'TULUM A Z.H TULUM', true, '9', 'tulum-hotel-zone-tulum'), array('Puerto Aventuras', 'PUERTO AVENTURAS', true, '7', 'puerto-aventuras'), array('Pto. Juarez (Isla Mujeres)', 'PTO. JUAREZ (ISLA MUJERES)', true, '3', 'pto-juarez-isla-mujeres'), array('Playa Mujeres', 'PLAYA MUJERES', true, '4', 'playa-mujeres'), array('Chiquila', 'CHIQUILA', false, '10', 'chiquila'));
     foreach ($destinations as $i => $destination) {
         list($title, $description, $isActive, $seqNum, $slug) = $destination;
         $destination = new Destination();
         $destination->setTitle($title);
         $destination->setDescription($description);
         $destination->setIsActive($isActive);
         $destination->setSeqNum($seqNum);
         $destination->setSlug($slug);
         $destination->setCreated(new \DateTime());
         $destination->setUpdated(new \DateTime());
         $manager->persist($destination);
         $i += 1;
         $this->addReference("destination-{$i}", $destination);
     }
 }
 /**
  * Creates a form to delete a Destination entity.
  *
  * @param Destination $destination The Destination entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Destination $destination)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('admin_destination_delete', array('id' => $destination->getId())))->setMethod('DELETE')->getForm();
 }