You are here

class ICalendar in Opigno calendar event 3.x

Same name and namespace in other branches
  1. 8 src/iCal/ICalendar.php \Drupal\opigno_calendar_event\iCal\ICalendar

Class ICalendar.

Hierarchy

  • class \Drupal\opigno_calendar_event\iCal\ICalendar

Expanded class hierarchy of ICalendar

File

src/iCal/ICalendar.php, line 8

Namespace

Drupal\opigno_calendar_event\iCal
View source
class ICalendar {
  protected $events;
  protected $title;
  protected $author;

  /**
   * ICalendar constructor.
   */
  public function __construct($parameters) {
    $parameters += [
      'events' => [],
      'title' => 'Calendar',
      'author' => 'Calender Generator',
    ];
    $this->events = $parameters['events'];
    $this->title = $parameters['title'];
    $this->author = $parameters['author'];
  }

  /**
   * Call this function to download the invite.
   */
  public function generateDownload() {
    $generated = $this
      ->generateString();

    // Date in the past.
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

    // Tell it we just updated.
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

    // Force revaidation.
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');
    header('Content-type: text/calendar; charset=utf-8');
    header('Content-Disposition: inline; filename="calendar.ics"');
    header("Content-Description: File Transfer");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . strlen($generated));
    print $generated;
  }

  /**
   * The function generates the actual content of the ICS file and returns it.
   */
  public function generateString() {
    $content = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . $this->author . "//NONSGML//EN\r\n" . "X-WR-CALNAME:" . $this->title . "\r\nCALSCALE:GREGORIAN\r\n";
    foreach ($this->events as $event) {
      $content .= $event
        ->generateString();
    }
    $content .= "END:VCALENDAR";
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ICalendar::$author protected property
ICalendar::$events protected property
ICalendar::$title protected property
ICalendar::generateDownload public function Call this function to download the invite.
ICalendar::generateString public function The function generates the actual content of the ICS file and returns it.
ICalendar::__construct public function ICalendar constructor.