Browse Source

refactor query route, include all data when format is not linestring

pull/5/head
Aaron Parecki 9 years ago
parent
commit
9624abc4fe
1 changed files with 25 additions and 20 deletions
  1. +25
    -20
      compass/app/Http/Controllers/Api.php

+ 25
- 20
compass/app/Http/Controllers/Api.php View File

@ -39,7 +39,7 @@ class Api extends BaseController
if($request->input('tz')) { if($request->input('tz')) {
$tz = $request->input('tz'); $tz = $request->input('tz');
} else { } else {
$tz = 'America/Los_Angeles';
$tz = 'UTC';
} }
if($date=$request->input('date')) { if($date=$request->input('date')) {
@ -55,29 +55,30 @@ class Api extends BaseController
$properties = []; $properties = [];
$events = []; $events = [];
foreach($results as $id=>$record) {
if(property_exists($record->data->properties, 'action')) {
$rec = $record->data;
$date = $record->date;
$rec->properties->unixtime = (int)$date->format('U');
$events[] = $rec;
} else {
#$record->date->format('U.u');
$locations[] = $record->data;
$props = $record->data->properties;
$date = $record->date;
$date->setTimeZone(new DateTimeZone($tz));
$props->timestamp = $date->format('c');
$props->unixtime = (int)$date->format('U');
$properties[] = $props;
}
}
if($request->input('format') == 'linestring') { if($request->input('format') == 'linestring') {
foreach($results as $id=>$record) {
// When returning a linestring, separate out the "event" records from the "location" records
if(property_exists($record->data->properties, 'action')) {
$rec = $record->data;
# add a unixtime property
$rec->properties->unixtime = (int)$record->date->format('U');
$events[] = $rec;
} else {
#$record->date->format('U.u');
$locations[] = $record->data;
$props = $record->data->properties;
$date = $record->date;
$date->setTimeZone(new DateTimeZone($tz));
$props->timestamp = $date->format('c');
$props->unixtime = (int)$date->format('U');
$properties[] = $props;
}
}
$linestring = array( $linestring = array(
'type' => 'LineString', 'type' => 'LineString',
'coordinates' => array(),
'coordinates' => [],
'properties' => $properties 'properties' => $properties
); );
foreach($locations as $loc) { foreach($locations as $loc) {
@ -93,6 +94,10 @@ class Api extends BaseController
); );
} else { } else {
foreach($results as $id=>$record) {
$locations[] = $record->data;
}
$response = [ $response = [
'locations' => $locations 'locations' => $locations
]; ];

Loading…
Cancel
Save