You are here

public function Generic::generateStructure in Add to Cal 8

Generates an ICS file for download

Overrides AddToCalTypeInterface::generateStructure

1 call to Generic::generateStructure()
Generic::downloadSubmit in src/Plugin/AddToCal/Type/Generic.php

File

src/Plugin/AddToCal/Type/Generic.php, line 106

Class

Generic
Provides generic calendar type (ics).

Namespace

Drupal\addtocal\Plugin\AddToCal\Type

Code

public function generateStructure(array $info) {
  $uri = $this->fileSystem
    ->tempnam('temporary://', 'ics_');
  $title = Html::escape($info['title']);
  $ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:{<span class="php-variable">$info</span>[<span class="php-string">'entity_type'</span>]}-{<span class="php-variable">$info</span>[<span class="php-string">'entity_id'</span>]}@{<span class="php-variable">$_SERVER</span>[<span class="php-string">'HTTP_HOST'</span>]}
DTSTAMP:{<span class="php-variable">$info</span>[<span class="php-string">'rfc3339'</span>][<span class="php-string">'start'</span>]}
DTSTART:{<span class="php-variable">$info</span>[<span class="php-string">'rfc3339'</span>][<span class="php-string">'start'</span>]}
DTEND:{<span class="php-variable">$info</span>[<span class="php-string">'rfc3339'</span>][<span class="php-string">'end'</span>]}
SUMMARY:{<span class="php-variable">$title</span>}
DESCRIPTION:{<span class="php-variable">$info</span>[<span class="php-string">'description'</span>]}
LOCATION:{<span class="php-variable">$info</span>[<span class="php-string">'location'</span>]}
END:VEVENT
END:VCALENDAR
ICS;
  $this
    ->open($uri);
  $this
    ->write($ics);
  $this
    ->close();
  return $uri;
}