summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2017-05-11 19:19:07 -0700
committerAaron Parecki <aaron@parecki.com>2017-05-11 19:19:07 -0700
commitb1b4aaa4d02ba2cf4c0bb07a95afcb0035dac3cf (patch)
treec7bf18e62395def018326e61d97de2bf48ffbe5d /controllers
parent34afa1f5f220af14c055e5eb5e0844be0b5120aa (diff)
add interface for checking in to flights
let's give this a shot
Diffstat (limited to 'controllers')
-rw-r--r--controllers/controllers.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index fe4d89c..ecc3a9e 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -191,6 +191,105 @@ $app->get('/itinerary', function() use($app) {
}
});
+$app->get('/flight', function() use($app) {
+ if($user=require_login($app)) {
+ $params = $app->request()->params();
+
+ render('new-flight', array(
+ 'title' => 'Flight',
+ 'authorizing' => false
+ ));
+ }
+});
+
+$app->post('/flight', function() use($app) {
+ if($user=require_login($app)) {
+ $params = $app->request()->params();
+
+ $location = false;
+
+ if($params['action'] == 'find') {
+
+ } elseif($params['action'] == 'checkin') {
+
+ $payload = [
+ 'type' => ['h-entry'],
+ 'properties' => [
+ 'checkin' => [
+ [
+ 'type' => ['h-card'],
+ 'properties' => [
+ 'name' => [$params['flight']],
+ 'url' => ['http://flightaware.com/live/flight/'.$params['flight']],
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $r = micropub_post_for_user($user, $payload, null, true);
+
+ $location = $r['location'];
+
+ if($location) {
+ // Store the checkin in the database to enable the cron job tracking the flight
+ $flight = ORM::for_table('flights')->create();
+ $flight->user_id = $_SESSION['user_id'];
+ $flight->date_created = date('Y-m-d H:i:s');
+ $flight->active = 1;
+ $flight->url = $location;
+ $flight->flight = $params['flight'];
+ $flight->save();
+ }
+ }
+
+ $app->response()['Content-type'] = 'application/json';
+ $app->response()->body(json_encode(array(
+ 'result' => 'ok',
+ 'location' => $location
+ )));
+ }
+});
+
+$app->get('/flight/:id/:flightID/route.json', function($id, $flightID) use($app) {
+ $route = false;
+
+ $flight = ORM::for_table('flights')->where('id', $id)->find_one();
+ if($flight) {
+ $lastPosition = json_decode($flight->lastposition, true);
+ if($lastPosition['InFlightInfoResult']['faFlightID'] == $flightID) {
+
+ // {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-122.638351,45.52217]},"properties":{"date":"2016-01-02T23:13:49Z","altitude":42.666666666667}}
+
+ $route = [
+ 'type' => 'FeatureCollection',
+ 'features' => []
+ ];
+
+ $positions = json_decode($flight->positions, true);
+ foreach($positions as $p) {
+ $route['features'][] = [
+ 'type' => 'Feature',
+ 'geometry' => [
+ 'type' => 'Point',
+ 'coordinates' => [$p['lng'], $p['lat']]
+ ],
+ 'properties' => [
+ 'date' => $p['date'],
+ 'altitude' => $p['altitude'],
+ 'heading' => $p['heading'],
+ 'speed' => $p['speed']
+ ]
+ ];
+ }
+
+ }
+ }
+
+ $app->response()['Content-type'] = 'application/json';
+ $app->response()->body(json_encode($route));
+});
+
$app->get('/photo', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();