aboutsummaryrefslogtreecommitdiffstats
path: root/library/fullcalendar/examples/php/get-events.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-11-05 08:46:42 +0000
committerMario <mario@mariovavti.com>2020-11-05 08:46:42 +0000
commitbafbf0416462c6f18c3fb6c8c06a063c8d6fdae6 (patch)
tree8929845be585b09d0f420621281c5531e1efad3e /library/fullcalendar/examples/php/get-events.php
parent6f93d9848c43019d43ea76c27d42d657ba031cd7 (diff)
parentfdefa101d84dc2a9424eaedbdb003a4c30ec5d01 (diff)
downloadvolse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.tar.gz
volse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.tar.bz2
volse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.zip
Merge branch '5.0RC'5.0
Diffstat (limited to 'library/fullcalendar/examples/php/get-events.php')
-rw-r--r--library/fullcalendar/examples/php/get-events.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/library/fullcalendar/examples/php/get-events.php b/library/fullcalendar/examples/php/get-events.php
new file mode 100644
index 000000000..e4d765433
--- /dev/null
+++ b/library/fullcalendar/examples/php/get-events.php
@@ -0,0 +1,50 @@
+<?php
+
+//--------------------------------------------------------------------------------------------------
+// This script reads event data from a JSON file and outputs those events which are within the range
+// supplied by the "start" and "end" GET parameters.
+//
+// An optional "timeZone" GET parameter will force all ISO8601 date stings to a given timeZone.
+//
+// Requires PHP 5.2.0 or higher.
+//--------------------------------------------------------------------------------------------------
+
+// Require our Event class and datetime utilities
+require dirname(__FILE__) . '/utils.php';
+
+// Short-circuit if the client did not give us a date range.
+if (!isset($_GET['start']) || !isset($_GET['end'])) {
+ die("Please provide a date range.");
+}
+
+// Parse the start/end parameters.
+// These are assumed to be ISO8601 strings with no time nor timeZone, like "2013-12-29".
+// Since no timeZone will be present, they will parsed as UTC.
+$range_start = parseDateTime($_GET['start']);
+$range_end = parseDateTime($_GET['end']);
+
+// Parse the timeZone parameter if it is present.
+$time_zone = null;
+if (isset($_GET['timeZone'])) {
+ $time_zone = new DateTimeZone($_GET['timeZone']);
+}
+
+// Read and parse our events JSON file into an array of event data arrays.
+$json = file_get_contents(dirname(__FILE__) . '/../json/events.json');
+$input_arrays = json_decode($json, true);
+
+// Accumulate an output array of event data arrays.
+$output_arrays = array();
+foreach ($input_arrays as $array) {
+
+ // Convert the input array into a useful Event object
+ $event = new Event($array, $time_zone);
+
+ // If the event is in-bounds, add it to the output
+ if ($event->isWithinDayRange($range_start, $range_end)) {
+ $output_arrays[] = $event->toArray();
+ }
+}
+
+// Send JSON to the client.
+echo json_encode($output_arrays);