Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4113 efrain 1
<?php
2
 
3
//--------------------------------------------------------------------------------------------------
4
// This script reads event data from a JSON file and outputs those events which are within the range
5
// supplied by the "start" and "end" GET parameters.
6
//
7
// An optional "timezone" GET parameter will force all ISO8601 date stings to a given timezone.
8
//
9
// Requires PHP 5.2.0 or higher.
10
//--------------------------------------------------------------------------------------------------
11
 
12
// Require our Event class and datetime utilities
13
require dirname(__FILE__) . '/utils.php';
14
 
15
// Short-circuit if the client did not give us a date range.
16
if (!isset($_GET['start']) || !isset($_GET['end'])) {
17
  die("Please provide a date range.");
18
}
19
 
20
// Parse the start/end parameters.
21
// These are assumed to be ISO8601 strings with no time nor timezone, like "2013-12-29".
22
// Since no timezone will be present, they will parsed as UTC.
23
$range_start = parseDateTime($_GET['start']);
24
$range_end = parseDateTime($_GET['end']);
25
 
26
// Parse the timezone parameter if it is present.
27
$timezone = null;
28
if (isset($_GET['timezone'])) {
29
  $timezone = new DateTimeZone($_GET['timezone']);
30
}
31
 
32
// Read and parse our events JSON file into an array of event data arrays.
33
$json = file_get_contents(dirname(__FILE__) . '/../json/events.json');
34
$input_arrays = json_decode($json, true);
35
 
36
// Accumulate an output array of event data arrays.
37
$output_arrays = array();
38
foreach ($input_arrays as $array) {
39
 
40
  // Convert the input array into a useful Event object
41
  $event = new Event($array, $timezone);
42
 
43
  // If the event is in-bounds, add it to the output
44
  if ($event->isWithinDayRange($range_start, $range_end)) {
45
    $output_arrays[] = $event->toArray();
46
  }
47
}
48
 
49
// Send JSON to the client.
50
echo json_encode($output_arrays);