ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
VEvent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class VEvent
24 {
25  protected string $uid;
26  protected string $description;
27  protected string $summary;
28  protected int $sequence;
29  protected EventStatus $status;
30  protected string $organiser_name;
31  protected string $organiser_email;
32  protected string $attendee_name;
33  protected string $attendee_email;
34  protected int $start_time;
35  protected int $end_time;
36  protected bool $all_day;
37  protected string $url;
38  protected string $location;
39 
40  public function __construct(
41  string $uid,
42  string $description,
43  string $summary,
44  int $sequence,
45  EventStatus $status,
46  string $organiserName,
47  string $organiserEmail,
48  string $attendeeName,
49  string $attendeeEmail,
50  int $startTime,
51  int $endTime,
52  bool $allDay,
53  string $url,
54  string $location
55  ) {
56  $this->uid = $uid;
57  $this->description = $description;
58  $this->summary = $summary;
59  $this->sequence = $sequence;
60  $this->status = $status;
61  $this->organiser_name = $organiserName;
62  $this->organiser_email = $organiserEmail;
63  $this->attendee_name = $attendeeName;
64  $this->attendee_email = $attendeeEmail;
65  $this->start_time = $startTime;
66  $this->end_time = $endTime;
67  $this->all_day = $allDay;
68  $this->url = $url;
69  $this->location = $location;
70  }
71 
72  protected function renderStartAndEndDates(): string
73  {
74  // creating DateTimes from Unix timestamps automatically sets the initial timezone to UTC
75  $start = new \DateTimeImmutable('@' . $this->start_time);
76  $start = $start->setTimezone(new \DateTimeZone('Europe/Paris'));
77  $end = new \DateTimeImmutable('@' . $this->end_time);
78  $end = $end->setTimezone(new \DateTimeZone('Europe/Paris'));
79 
80  if ($this->all_day) {
81  return 'DTSTART;TZID=Europe/Paris;VALUE=DATE:' . $start->format('Ymd') . "\r\n" .
82  'DTEND;TZID=Europe/Paris;VALUE=DATE:' . $end->format('Ymd') . "\r\n" .
83  "X-MICROSOFT-CDO-ALLDAYEVENT: TRUE\r\n";
84  } else {
85  return 'DTSTART;TZID=Europe/Paris:' . $start->format('Ymd\THis') . "\r\n" .
86  'DTEND;TZID=Europe/Paris:' . $end->format('Ymd\THis') . "\r\n";
87  }
88  }
89 
90  public function render(): string
91  {
92  return 'BEGIN:VEVENT' . "\r\n" .
93  'UID: ' . $this->uid . "\r\n" .
94  'DESCRIPTION:' . $this->description . "\r\n" .
95  $this->renderStartAndEndDates() .
96  'DTSTAMP:' . date("Ymd\THis") . "\r\n" .
97  'LAST-MODIFIED:' . date("Ymd\THis") . "\r\n" .
98  'ORGANIZER;CN="' . $this->organiser_name . '":MAILTO:' . $this->organiser_email . "\r\n" .
99  'ATTENDEE;CN="' . $this->attendee_name . '";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' . $this->attendee_email . "\r\n" .
100  'SUMMARY:' . $this->summary . "\r\n" .
101  'LOCATION:' . $this->location . "\r\n" .
102  'SEQUENCE:' . $this->sequence . "\r\n" .
103  "PRIORITY:5\r\n" .
104  'STATUS:' . $this->status->value . "\r\n" .
105  "TRANSP:OPAQUE\r\n" .
106  "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\n" .
107  'CLASS:PUBLIC' . "\r\n" .
108  "X-MICROSOFT-DISALLOW-COUNTER:TRUE\r\n" .
109  //'URL:'. $this->url . "\r\n" .
110 
111  'BEGIN:VALARM' . "\r\n" .
112  'DESCRIPTION:' . $this->summary . "\r\n" .
113  'TRIGGER:-PT15M' . "\r\n" .
114  'ACTION:DISPLAY' . "\r\n" .
115  'END:VALARM' . "\r\n" .
116 
117  'END:VEVENT' . "\r\n";
118  }
119 }
__construct(string $uid, string $description, string $summary, int $sequence, EventStatus $status, string $organiserName, string $organiserEmail, string $attendeeName, string $attendeeEmail, int $startTime, int $endTime, bool $allDay, string $url, string $location)
Definition: VEvent.php:40