Browse Source

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

pull/5/head
Aaron Parecki 8 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')) {
$tz = $request->input('tz');
} else {
$tz = 'America/Los_Angeles';
$tz = 'UTC';
}
if($date=$request->input('date')) {
@ -55,29 +55,30 @@ class Api extends BaseController
$properties = [];
$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') {
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(
'type' => 'LineString',
'coordinates' => array(),
'coordinates' => [],
'properties' => $properties
);
foreach($locations as $loc) {
@ -93,6 +94,10 @@ class Api extends BaseController
);
} else {
foreach($results as $id=>$record) {
$locations[] = $record->data;
}
$response = [
'locations' => $locations
];

Loading…
Cancel
Save