get-events.php 1.9 KB

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