foot_step_data.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. //$json = file_get_contents(dirname(__FILE__) . '/../json/events.json');
  43. //$input_arrays = json_decode($json, true);
  44. //使用cookie传递老师id
  45. $dns = "sqlite:"._FILE_DB_USER_ACTIVE_;
  46. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  47. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  48. $query = "SELECT id , start, end,duration, hit FROM edit WHERE user_id = ?";
  49. $stmt = $dbh->prepare($query);
  50. $stmt->execute(array($_GET["userid"]));
  51. $allData = $stmt->fetchAll(PDO::FETCH_ASSOC);
  52. $input_arrays=array();
  53. foreach ($allData as $key => $value) {
  54. # code...
  55. $strDuration = covertTimeToString($value["duration"]/1000)."-".$value["hit"]."次操作";
  56. $start = date("Y-m-d\TH:i:s+00:00",$value["start"]/1000);
  57. $end = date("Y-m-d\TH:i:s+00:00",$value["end"]/1000);
  58. $input_arrays[] = array("id"=>$value["id"],
  59. "title"=>$strDuration,
  60. "start"=>$start,
  61. "end"=>$end);
  62. }
  63. // Accumulate an output array of event data arrays.
  64. $output_arrays = array();
  65. foreach ($input_arrays as $array) {
  66. // Convert the input array into a useful Event object
  67. $event = new Event($array, $time_zone);
  68. // If the event is in-bounds, add it to the output
  69. if ($event->isWithinDayRange($range_start, $range_end)) {
  70. $output_arrays[] = $event->toArray();
  71. }
  72. }
  73. // Send JSON to the client.
  74. echo json_encode($output_arrays);