Esempio n. 1
0
 /**
  * @todo Пока что только по одному событию
  * Метод возвращает Файл с событиями на месяц для outlook
  * @Route("/outlooklist/{year}/{month}", name = "outlook_list", defaults = { "year" = null, "month" = null}, requirements = {"year" = "\d+", "month" = "\d+", })
  */
 public function outlookListAction($year, $month)
 {
     $calendar = new Calendar();
     $calendar->setMonth($month);
     $calendar->setYear($year);
     $events = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:UserCalendar')->findForPeriod($calendar->getBeginningTimestamp(), $calendar->getEndTimestamp(), $this->getUser());
     $msg = '';
     $msg .= "BEGIN:VCALENDAR\n";
     $msg .= "VERSION:2.0\n";
     $msg .= "PRODID:www.evrika.ru\n";
     $msg .= "METHOD:REQUEST\n";
     // requied by Outlook
     foreach ($events as $key => $event) {
         $msg .= "BEGIN:VEVENT\n";
         $msg .= "DTSTART:" . $event->getStarts()->format('Ymd') . "T" . $event->getStarts()->format('his') . "\n";
         $msg .= "DTEND:" . $event->getEnds()->format('Ymd') . "T" . $event->getStarts()->format('his') . "\n";
         $msg .= "SUMMARY:" . $event->getTitle() . "\n";
         $tmp = $event->getEvent();
         if ($tmp != null) {
             $msg .= "LOCATION:" . $tmp->getAddress() . "\n";
         } else {
             $msg .= "LOCATION:\n";
         }
         $msg .= "DESCRIPTION:" . $event->getBody() . "\n";
         $msg .= "UID:EVR" . $event->getId() . "\n";
         $msg .= "SEQUENCE:0\n";
         $msg .= "END:VEVENT\n";
     }
     $msg .= "END:VCALENDAR\n";
     $olheader = array('Content-Type' => 'text/Calendar', 'Content-Disposition' => 'inline; filename=calendar.ics');
     return new Response($msg, 200, $olheader);
 }
Esempio n. 2
0
 /**
  * @Secure(roles="IS_AUTHENTICATED_REMEMBERED")
  * @Route("/mycalendar/{id}/{year}/{month}", name = "user_calendar", options={"expose"=true} , defaults = {"year" = null, "month" = null, "id" = null}, requirements = {"year" = "\d+", "month" = "\d+"})
  */
 public function showMyCalendarAction($id, $year, $month)
 {
     if ($id == null || $id == 0) {
         $userCalendar = new UserCalendar();
         $userCalendar->setUser($this->getUser());
         $userCalendar->setEvent(null);
     } else {
         $userCalendar = $this->getDoctrine()->getManager()->find("EvrikaMainBundle:UserCalendar", $id);
     }
     $form = $this->createFormBuilder($userCalendar)->add('Starts', 'datetime', array('label' => 'Дата начала', 'years' => range(date('Y') - 90, date('Y')), 'empty_value' => ''))->add('Ends', 'datetime', array('label' => 'Дата окончания', 'years' => range(date('Y') - 90, date('Y')), 'empty_value' => ''))->add('Title', 'text', array('label' => 'Заголовок', 'required' => false))->add('Body', 'textarea', array('label' => 'Описание', 'required' => false))->add('Id', 'hidden', array('required' => false))->getForm();
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         $form->bind($request);
         /**
          * Нужно сделать проверку формы
          */
         #if ($form->isValid()) {
         $userCalendar = $form->getData();
         $em = $this->getDoctrine()->getManager();
         if ($id == null || $id == 0) {
             $em->persist($userCalendar);
         }
         $em->flush();
         $referer = $request->headers->get('referer');
         return new RedirectResponse($referer);
         #}
     } else {
         if ($id != null && $id != 0) {
             $em = $this->getDoctrine()->getManager();
             $em->remove($userCalendar);
             $em->flush();
             $referer = $request->headers->get('referer');
             return new RedirectResponse($referer);
         }
     }
     $calendar = new Calendar();
     $calendar->setMonth($month);
     $calendar->setYear($year);
     $subEvents = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:UserCalendar')->findForPeriodForeign($calendar->getBeginningTimestamp(), $calendar->getEndTimestamp(), $this->getUser());
     $events = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:UserCalendar')->findForPeriod($calendar->getBeginningTimestamp(), $calendar->getEndTimestamp(), $this->getUser());
     $events = array_merge($subEvents, $events);
     $eventsArray = array();
     foreach ($events as $key => $event) {
         $eventsArray[$key]['i'] = $this->getUser()->getId();
         $eventsArray[$key]['user'] = $event->getUser()->getId();
         $eventsArray[$key]['userName'] = $event->getUser()->getLastName() . " " . $event->getUser()->getFirstName();
         $eventsArray[$key]['title'] = $event->getTitle();
         $eventsArray[$key]['body'] = $event->getBody();
         $eventsArray[$key]['id'] = $event->getId();
         $eventsArray[$key]['starts'] = $event->getStarts();
         $eventsArray[$key]['ends'] = $event->getEnds();
         $tmp = $event->getEvent();
         if ($tmp != null) {
             $eventsArray[$key]['myevent'] = $tmp->getId();
         } else {
             $eventsArray[$key]['myevent'] = 0;
         }
     }
     $monthTable = $calendar->getMonthTable();
     $numberOfEvents = count($events);
     foreach ($monthTable as $rowKey => $row) {
         foreach ($monthTable[$rowKey] as $colKey => $element) {
             if ($element) {
                 $monthTable[$rowKey][$colKey]['events'] = array();
             }
             if ($element['number'] < 10) {
                 $tmp_element = '0' . $element['number'];
             } else {
                 $tmp_element = $element['number'];
             }
             for ($i = 0; $i < $numberOfEvents; $i++) {
                 if ($events[$i]->getStarts()->format('Ymd') <= $calendar->getYear() . $calendar->getMonthD() . $tmp_element and $events[$i]->getEnds()->format('Ymd') >= $calendar->getYear() . $calendar->getMonthD() . $tmp_element) {
                     $monthTable[$rowKey][$colKey]['events'][] = $events[$i]->getTitle();
                 }
             }
         }
     }
     $nowYear = date('Y', time()) + 1;
     //Добавляем год что бы посмотреть события и на следующий год
     return $this->render('EvrikaMainBundle:Index:my_calendar.html.twig', array('calendar' => $monthTable, 'monthName' => $calendar->getMonthName(), 'year' => $calendar->getYear(), 'month' => $calendar->getMonth(), 'nextMonth' => $calendar->getNextMonth(), 'prevMonth' => $calendar->getPrevMonth(), 'nextMonthYear' => $calendar->getNextMonthYear(), 'prevMonthYear' => $calendar->getPrevMonthYear(), 'events' => $events, 'feedType' => 'events', 'nowYear' => $nowYear, 'addEvent' => $form->createView(), 'eventsArray' => $eventsArray, 'typeCalendar' => 'my'));
 }