if ($x && $y) {
$query = new NearbyQuery($x, $y);
$stations = $app['api']->findNearbyLocations($query);
}
$query = $request->get('query');
if ($query) {
$query = new LocationQuery($query, $request->get('type'));
$stations = $app['api']->findLocations($query);
}
$result = array('stations' => $stations);
$json = $app['serializer']->serialize((object) $result, 'json');
return new Response($json, 200, array('Content-Type' => 'application/json'));
});
// connections
$app->get('/v1/connections', function (Request $request) use($app) {
$query = LocationQueryParser::create($request);
// get stations
$stations = $app['api']->findLocations($query);
// get connections
$connections = array();
$from = reset($stations['from']) ?: null;
$to = reset($stations['to']) ?: null;
$via = array();
foreach ($stations as $k => $v) {
if (preg_match("/^via[0-9]+\$/", $k) && $v) {
$via[] = reset($v);
}
}
if ($from && $to) {
$app['stats']->station($from);
$app['stats']->station($to);