parent
827007437b
commit
a5b2f118a2
1 changed files with 47 additions and 0 deletions
|
@ -15,6 +15,10 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||||
use Hackspace\Bundle\CalciferBundle\Entity\Event;
|
use Hackspace\Bundle\CalciferBundle\Entity\Event;
|
||||||
use Hackspace\Bundle\CalciferBundle\Form\EventType;
|
use Hackspace\Bundle\CalciferBundle\Form\EventType;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Jsvrcek\ICS\Model\Calendar;
|
||||||
|
use Jsvrcek\ICS\Utility\Formatter;
|
||||||
|
use Jsvrcek\ICS\CalendarStream;
|
||||||
|
use Jsvrcek\ICS\CalendarExport;
|
||||||
use
|
use
|
||||||
Sabre\VObject,
|
Sabre\VObject,
|
||||||
Sabre\CalDAV,
|
Sabre\CalDAV,
|
||||||
|
@ -70,6 +74,49 @@ class EventController extends Controller
|
||||||
return new Response();
|
return new Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all Event entities as ICS.
|
||||||
|
*
|
||||||
|
* @Route("/all.ics", name="events_ics")
|
||||||
|
* @Method("GET")
|
||||||
|
* @Template()
|
||||||
|
*/
|
||||||
|
public function allEventsAsICSAction()
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$now = new \DateTime();
|
||||||
|
$now->setTime(0, 0, 0);
|
||||||
|
/** @var QueryBuilder $qb */
|
||||||
|
$qb = $em->createQueryBuilder();
|
||||||
|
$qb->select(array('e'))
|
||||||
|
->from('CalciferBundle:Event', 'e')
|
||||||
|
->where('e.startdate >= :startdate')
|
||||||
|
->orderBy('e.startdate')
|
||||||
|
->setParameter('startdate', $now);
|
||||||
|
$entities = $qb->getQuery()->execute();
|
||||||
|
|
||||||
|
$calendar = new Calendar();
|
||||||
|
$calendar->setProdId('-//My Company//Cool Calendar App//EN');
|
||||||
|
|
||||||
|
foreach ($entities as $entity) {
|
||||||
|
/** @var Event $entity */
|
||||||
|
$event = $entity->ConvertToCalendarEvent();
|
||||||
|
$calendar->addEvent($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
|
||||||
|
$calendarExport->addCalendar($calendar);
|
||||||
|
|
||||||
|
//output .ics formatted text
|
||||||
|
$result = $calendarExport->getStream();
|
||||||
|
|
||||||
|
$response = new Response($result);
|
||||||
|
$response->headers->set('Content-Type', 'text/calendar');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all Event entities.
|
* Lists all Event entities.
|
||||||
|
|
Reference in a new issue