Ejemplo n.º 1
0
 /**
  * Imports ical files.
  *
  * @param UploadedFile $file
  * @param Workspace    $workspace
  *
  * @return int number of events saved
  */
 public function importEvents(UploadedFile $file, $workspace = null)
 {
     $ical = new ICal($file->getPathname());
     $events = $ical->events();
     $tabs = [];
     foreach ($events as $event) {
         $e = new Event();
         $e->setTitle($event->summary);
         $e->setStart($ical->iCalDateToUnixTimestamp($event->dtstart));
         $e->setEnd($ical->iCalDateToUnixTimestamp($event->dtend));
         $e->setDescription($event->description);
         if ($workspace) {
             $e->setWorkspace($workspace);
         }
         $e->setUser($this->tokenStorage->getToken()->getUser());
         $e->setPriority('#01A9DB');
         $this->om->persist($e);
         //the flush is required to generate an id
         $this->om->flush();
         $tabs[] = $e->jsonSerialize();
     }
     return $tabs;
 }