| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Simple Event Example |
| 5 |
* |
| 6 |
* Create a simple iCalendar event |
| 7 |
* No time zone specified, so this event will be in UTC time zone |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
require_once("../zapcallib.php"); |
| 12 |
|
| 13 |
$title = "Simple Event"; |
| 14 |
// date/time is in SQL datetime format |
| 15 |
$event_start = "2020-01-01 12:00:00"; |
| 16 |
$event_end = "2020-01-01 13:00:00"; |
| 17 |
|
| 18 |
// create the ical object |
| 19 |
$icalobj = new ZCiCal(); |
| 20 |
|
| 21 |
// create the event within the ical object |
| 22 |
$eventobj = new ZCiCalNode("VEVENT", $icalobj->curnode); |
| 23 |
|
| 24 |
// add title |
| 25 |
$eventobj->addNode(new ZCiCalDataNode("SUMMARY:" . $title)); |
| 26 |
|
| 27 |
// add start date |
| 28 |
$eventobj->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($event_start))); |
| 29 |
|
| 30 |
// add end date |
| 31 |
$eventobj->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($event_end))); |
| 32 |
|
| 33 |
// UID is a required item in VEVENT, create unique string for this event |
| 34 |
// Adding your domain to the end is a good way of creating uniqueness |
| 35 |
$uid = date('Y-m-d-H-i-s') . "@demo.icalendar.org"; |
| 36 |
$eventobj->addNode(new ZCiCalDataNode("UID:" . $uid)); |
| 37 |
|
| 38 |
// DTSTAMP is a required item in VEVENT |
| 39 |
$eventobj->addNode(new ZCiCalDataNode("DTSTAMP:" . ZCiCal::fromSqlDateTime())); |
| 40 |
|
| 41 |
// Add description |
| 42 |
$eventobj->addNode(new ZCiCalDataNode("Description:" . ZCiCal::formatContent( |
| 43 |
"This is a simple event, using the Zap Calendar PHP library. " . |
| 44 |
"Visit http://icalendar.org to validate icalendar files."))); |
| 45 |
|
| 46 |
// write iCalendar feed to stdout |
| 47 |
echo $icalobj->export(); |
| 48 |
|
| 49 |
|