/**
  * @Route("/schedule/export", name="user_schedule_export")
  * @Template()
  */
 public function exportAction()
 {
     if (!$this->getUserLayer()->isStudent()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     /** @var $courses Course[] */
     $courses = $em->getRepository('EtuUserBundle:Course')->findByUser($this->getUser());
     $vcalendar = new VCalendar();
     $semesterEnd = SemesterManager::current()->getEnd()->format('Ymd\\THis');
     foreach ($courses as $course) {
         if ($course->getUv() == 'SPJE') {
             continue;
         }
         if ($course->getDay() == Course::DAY_SATHURDAY) {
             $day = 'saturday';
         } else {
             $day = $course->getDay();
         }
         $day = new \DateTime('last ' . $day);
         $start = clone $day;
         $time = explode(':', $course->getStart());
         $start->setTime($time[0], $time[1]);
         $end = clone $day;
         $time = explode(':', $course->getEnd());
         $end->setTime($time[0], $time[1]);
         $summary = $course->getWeek() != 'T' ? $course->getUv() . ' (' . $course->getWeek() . ')' : $course->getUv();
         $vcalendar->add('VEVENT', ['SUMMARY' => $summary . ' - ' . $course->getType(), 'DTSTART' => $start, 'DTEND' => $end, 'RRULE' => 'FREQ=WEEKLY;INTERVAL=1;UNTIL=' . $semesterEnd, 'LOCATION' => $course->getRoom(), 'CATEGORIES' => $course->getType()]);
     }
     $response = new Response($vcalendar->serialize());
     $response->headers->set('Content-Type', 'text/calendar; charset=utf-8');
     $response->headers->set('Content-Disposition', 'attachment; filename="etuutt_schedule.ics"');
     return $response;
 }
Beispiel #2
0
 /**
  * @return string
  */
 public static function currentSemester()
 {
     return SemesterManager::current()->getCode();
 }