function importRouteStops()
{
    include_once "../public_html/apps/routecoorddistances.php";
    $url = "http://shuttles.rpi.edu/displays/netlink.js";
    $data = json_decode(getUrl($url));
    //print_ar($data);exit;
    foreach ($data as $type => $datum) {
        switch ($type) {
            case 'stops':
                foreach ($datum as $stop) {
                    /* update 'stops' table */
                    if ($stop->short_name) {
                        if (Stop::get($stop->short_name)) {
                            Stop::update($stop->short_name, $stop);
                        } else {
                            Stop::insert($stop);
                        }
                    }
                    foreach ($stop->routes as $stop_route) {
                        /* update 'stop_routes' table */
                        if (!StopRoute::get($stop->short_name, $stop_route->id)) {
                            StopRoute::insert($stop->short_name, $stop_route->id);
                        }
                    }
                }
                break;
            case 'routes':
                foreach ($datum as $route) {
                    /* update 'route' table */
                    if (Route::get($route->id)) {
                        Route::update($route->id, $route);
                    } else {
                        Route::insert($route->id, $route);
                    }
                    if ($route->coords) {
                        RouteCoords::delete($route->id);
                        /* delete all coords for route */
                        $seq = 0;
                        foreach ($route->coords as $route_coord) {
                            /* update 'route_coords' table */
                            RouteCoords::insert($route->id, $seq, $route_coord);
                            $seq++;
                        }
                    }
                }
                break;
        }
    }
    RouteCoordDistances::loadDistanceTable();
}
Example #2
0
        Flight::ok($array);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('GET /v1/main/route/@id', function ($id) {
    try {
        $object = Route::select($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('POST /v1/main/route', function () {
    try {
        $object = Route::insert();
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('PUT /v1/main/route/@id', function ($id) {
    try {
        $object = Route::update($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('DELETE /v1/main/route/@id', function ($id) {
    try {