2016-09-15 02:16:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventExportController
|
|
|
|
extends PhabricatorCalendarController {
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
|
|
|
|
$event = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$event) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-09-15 15:27:20 +02:00
|
|
|
$file_name = $event->getICSFilename();
|
|
|
|
$event_node = $event->newIntermediateEventNode($viewer);
|
2016-09-15 02:16:54 +02:00
|
|
|
|
2016-09-15 15:27:20 +02:00
|
|
|
$document_node = id(new PhutilCalendarDocumentNode())
|
|
|
|
->appendChild($event_node);
|
2016-09-15 02:16:54 +02:00
|
|
|
|
2016-09-15 15:27:20 +02:00
|
|
|
$root_node = id(new PhutilCalendarRootNode())
|
|
|
|
->appendChild($document_node);
|
2016-09-15 02:16:54 +02:00
|
|
|
|
2016-09-15 15:27:20 +02:00
|
|
|
$ics_data = id(new PhutilICSWriter())
|
|
|
|
->writeICSDocument($root_node);
|
2016-09-15 02:16:54 +02:00
|
|
|
|
2016-09-15 15:27:20 +02:00
|
|
|
return id(new AphrontFileResponse())
|
|
|
|
->setDownload($file_name)
|
|
|
|
->setMimeType('text/calendar')
|
|
|
|
->setContent($ics_data);
|
2016-09-15 02:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|