getRequest();
$response = $this->getResponse();
$idx = $request->idx;
$pathMapper = new Syj_Model_PathMapper();
$path = new Syj_Model_Path();
$api = $this->_helper->SyjApi;
$ext = "";
$parts = explode('.', $idx);
if (count($parts) >= 2) {
$ext = end($parts);
if (in_array($ext, array('kml', 'gpx', 'json'))) {
$idx = implode('.', explode('.', $idx, -1));
} else {
$ext = "";
}
}
if (!$pathMapper->find($idx, $path)) {
if ($pathMapper->hasexisted($idx)) {
$api->setCode(410);
} else {
$api->setCode(404);
}
return;
}
switch ($ext) {
case 'kml':
$this->kml($path);
break;
case 'gpx':
$this->gpx($path);
break;
case 'json':
default:
$this->json($path);
return;
break;
}
}
protected function kml(Syj_Model_Path $path) {
$data = '' . PHP_EOL; // <-- vim syntax goes crazy
$data .= '';
$data .= '';
if ($path->creator) {
$data .= '' . htmlspecialchars($path->creator->pseudo) . '';
}
$data .= '' . htmlspecialchars($path->displayTitle) . '';
$data .= $path->geom->toKML();
$data .= '';
$data .= '';
$api = $this->_helper->SyjApi;
$api->setCheckIfNoneMatch(true)->setContentType('application/vnd.google-earth.kml+xml')->setBody($data);
}
protected function gpx(Syj_Model_Path $path) {
$data = '' . PHP_EOL; // <-- vim syntax goes crazy
$data .= '';
$data .= '';
if ($path->creator) {
$data .= '' . htmlspecialchars($path->creator->pseudo) . '';
}
$data .= '' . htmlspecialchars($path->displayTitle) . '';
$data .= $path->geom->toGPX();
$data .= '';
$data .= '';
$api = $this->_helper->SyjApi;
$api->setCheckIfNoneMatch(true)->setContentType('application/octet-stream')->setBody($data);
}
protected function json(Syj_Model_Path $path) {
$data = json_decode($path->geom->toGeoJSON());
$data->title = (string)$path->displayTitle;
if ($path->creator) {
$data->creator = (string)$path->creator->pseudo;
}
$api = $this->_helper->SyjApi;
$api->setCheckIfNoneMatch(true)->setBodyJson($data);
}
}