Example #1
0
 /**
  * Displays a form to create a new Event entity.
  *
  * @Route("/new", name="event_new")
  * @Template()
  */
 public function newAction()
 {
     $request = $this->getRequest();
     $session = $this->getRequest()->getSession();
     $session_id = $session->get('id');
     if (!$session_id) {
         return $this->redirect($this->generateUrl('user_welcome', array('back' => $_SERVER['REQUEST_URI'])));
     }
     $entity = new Event();
     $type = $request->query->get('type');
     if ($type) {
         $entity->setType($type);
     }
     // ical
     $ical = $request->query->get('ical');
     $date_start = $date_end = false;
     if ($ical) {
         $data = explode("\r\n", file_get_contents($ical));
         foreach ($data as $item) {
             if (strstr($item, 'SUMMARY')) {
                 $entity->setTitle(str_replace('SUMMARY;CHARSET=utf-8:', '', $item));
             } else {
                 if (strstr($item, 'LOCATION')) {
                     $entity->setLocation(current(explode(', ', str_replace('LOCATION;CHARSET=utf-8:', '', $item))));
                 } else {
                     if (strstr($item, 'DESCRIPTION')) {
                         $entity->setBody(str_replace('DESCRIPTION:', '', $item));
                     } else {
                         if (strstr($item, 'DTSTART')) {
                             $date = str_replace('DTSTART;VALUE=DATE:', '', $item);
                             $date_start = substr($date, 6, 2) . '-' . substr($date, 4, 2) . '-' . substr($date, 0, 4);
                         } else {
                             if (strstr($item, 'DTEND')) {
                                 $date = str_replace('DTEND;VALUE=DATE:', '', $item);
                                 $date_end = substr($date, 6, 2) . '-' . substr($date, 4, 2) . '-' . substr($date, 0, 4);
                             }
                         }
                     }
                 }
             }
         }
     }
     // new date
     $hashtag = $request->query->get('hashtag');
     if ($hashtag) {
         $em = $this->getDoctrine()->getEntityManager();
         $qb = $em->createQueryBuilder();
         $qb->add('select', 'e')->add('from', 'ApplicationEventBundle:Event e')->where('e.hashtag = :hashtag')->setParameter('hashtag', $hashtag)->add('orderBy', 'e.date_end DESC, e.id DESC')->setMaxResults(1);
         $event = current($qb->getQuery()->getResult());
         if ($event) {
             $entity->setTitle($event->getTitle());
             $entity->setAddress($event->getAddress());
             $entity->setLocation($event->getLocation());
             $entity->setHashtag($event->getHashtag());
             $entity->setCityId($event->getCityId());
             $entity->setCountryId($event->getCountryId());
         }
     }
     $form = $this->createForm(new EventType(), $entity);
     return array('entity' => $entity, 'form' => $form->createView(), 'hours' => array('07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '00', '01', '02', '03', '04', '05', '06'), 'minutes' => array('00', '10', '20', '30', '40', '50'), 'date_start' => $date_start, 'date_end' => $date_end);
 }