foot_step_data.php 2.7 KB

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