public function validate($value, Constraint $constraint) { if ($value !== null) { $ical = new ICal($value->getPathName()); $events = $ical->events(); if ($events === null || count($events) === 0) { $this->context->addViolation($constraint->message); } } }
/** * 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; }
<?php require_once '../vendor/autoload.php'; use ICal\ICal; $ical = new ICal('MyCal.ics'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <title>PHP ICS Parser example</title> <style>.caption { overflow-x: auto }</style> </head> <body style="background-color: #eee"> <div class="container"> <h3>PHP ICS Parser example</h3> <ul class="list-group"> <li class="list-group-item"> <span class="badge"><?php echo $ical->eventCount; ?> </span> The number of events </li> <li class="list-group-item"> <span class="badge"><?php echo $ical->todoCount; ?> </span>