private function addToItinerary($eguide, $spotDetail, $egts)
 {
     $itinerary = $this->_em->getRepository('BugglMainBundle:Itinerary')->findOneBy(array('e_guide' => $eguide, 'day_num' => $egts->getDayNum()));
     if (!$itinerary) {
         $itinerary = new Itinerary();
         $itinerary->setEGuide($eguide);
         $itinerary->setDayNum($egts->getDayNum());
         $this->_em->persist($itinerary);
         $this->_em->flush();
     }
     $obj = $this->_em->getRepository('BugglMainBundle:ItineraryToSpotDetail')->findOneBy(array('itinerary' => $itinerary, 'spotDetail' => $spotDetail));
     if (!$obj) {
         $lastOrder = $this->_em->getRepository('BugglMainBundle:ItineraryToSpotDetail')->getLastOrderByItineraryAndPeriodOfDay($itinerary, $egts->getPeriodOfDay());
         $order = $lastOrder ? (int) $lastOrder[0]->getOrder() + 1 : 1;
         $obj = new ItineraryToSpotDetail();
         $obj->setItinerary($itinerary);
         $obj->setSpotDetail($spotDetail);
         $obj->setPeriodOfDay($egts->getPeriodOfDay());
         $obj->setOrder($order);
         $obj->setDateAdded($spotDetail->getDateAdded());
         $this->_em->persist($obj);
         $this->_em->flush();
     }
 }
Ejemplo n.º 2
0
 private function saveAsItinerary(\Buggl\MainBundle\Entity\EGuide $eguide, \Buggl\MainBundle\Entity\SpotDetail $detail, $day, $time_of_day)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $itinerary = $this->getDoctrine()->getRepository('BugglMainBundle:Itinerary')->findOneBy(array('e_guide' => $eguide, 'day_num' => $day));
     if (!$itinerary) {
         $itinerary = new Itinerary();
         $itinerary->setEGuide($eguide);
         $itinerary->setDayNum($day);
         $em->persist($itinerary);
         $em->flush();
     }
     $itsd = $em->getRepository('BugglMainBundle:ItineraryToSpotDetail')->findOneBy(array('itinerary' => $itinerary, 'spotDetail' => $detail, 'periodOfDay' => $time_of_day));
     if (!$itsd) {
         $lastOrder = $em->getRepository('BugglMainBundle:ItineraryToSpotDetail')->getLastOrderByItineraryAndPeriodOfDay($itinerary, $time_of_day);
         $order = $lastOrder ? (int) $lastOrder[0]->getOrder() + 1 : 1;
         $itsd = new ItineraryToSpotDetail();
         $itsd->setItinerary($itinerary);
         $itsd->setSpotDetail($detail);
         $itsd->setPeriodOfDay($time_of_day);
         $itsd->setOrder($order);
         $dateAdded = new \DateTime(date('Y-m-d H:i:s'));
         $itsd->setDateAdded($dateAdded);
         $em->persist($itsd);
         $em->flush();
     }
 }