foot_step_data.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_once '../path.php';
  12. require_once '../lib/fullcalendar/php/utils.php';
  13. function covertTimeToString($time)
  14. {
  15. $time = (int) $time;
  16. if ($time < 60) {
  17. return $time . "秒";
  18. } else if ($time < 3600) {
  19. return (floor($time / 60)) . "分钟";
  20. } else {
  21. $hour = floor($time / 3600);
  22. $min = floor(($time - ($hour * 3600)) / 60);
  23. return "{$hour}小时{$min}分钟";
  24. }
  25. }
  26. // Short-circuit if the client did not give us a date range.
  27. if (!isset($_GET['start']) || !isset($_GET['end'])) {
  28. die("Please provide a date range.");
  29. }
  30. // Parse the start/end parameters.
  31. // These are assumed to be ISO8601 strings with no time nor timeZone, like "2013-12-29".
  32. // Since no timeZone will be present, they will parsed as UTC.
  33. $range_start = parseDateTime($_GET['start']);
  34. $range_end = parseDateTime($_GET['end']);
  35. // Parse the timeZone parameter if it is present.
  36. $time_zone = null;
  37. if (isset($_GET['timeZone'])) {
  38. $time_zone = new DateTimeZone($_GET['timeZone']);
  39. }
  40. // Read and parse our events JSON file into an array of event data arrays.
  41. $dns = "" . _FILE_DB_USER_ACTIVE_;
  42. $dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  43. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  44. $query = "SELECT id , start, end,duration, hit FROM edit WHERE user_id = ?";
  45. $stmt = $dbh->prepare($query);
  46. $stmt->execute(array($_GET["userid"]));
  47. $allData = $stmt->fetchAll(PDO::FETCH_ASSOC);
  48. $input_arrays = array();
  49. foreach ($allData as $key => $value) {
  50. # code...
  51. $strDuration = covertTimeToString($value["duration"] / 1000) . "-" . $value["hit"] . "次操作";
  52. $start = date("Y-m-d\TH:i:s+00:00", $value["start"] / 1000);
  53. $end = date("Y-m-d\TH:i:s+00:00", $value["end"] / 1000);
  54. $input_arrays[] = array("id" => $value["id"],
  55. "title" => $strDuration,
  56. "start" => $start,
  57. "end" => $end);
  58. }
  59. // Accumulate an output array of event data arrays.
  60. $output_arrays = array();
  61. foreach ($input_arrays as $array) {
  62. // Convert the input array into a useful Event object
  63. $event = new Event($array, $time_zone);
  64. // If the event is in-bounds, add it to the output
  65. if ($event->isWithinDayRange($range_start, $range_end)) {
  66. $output_arrays[] = $event->toArray();
  67. }
  68. }
  69. // Send JSON to the client.
  70. echo json_encode($output_arrays);