/** * returns a GPX, KML or GeoJSON version of the document geometry with some useful additional informations in best possible lang */ protected function Export($module, $id, $lang, $format, $version = null) { if (!$id) { $this->setErrorAndRedirect('Could not understand your request', "@default_index?module={$module}"); } if (!empty($version)) { $document = $this->getDocument($id, $lang, $version); } if (empty($document)) { $document = Document::find('Document', $id, array('module', 'geom_wkt')); } if (!$document || $document->get('module') != $module) { $this->setErrorAndRedirect('Document does not exist', "@default_index?module={$module}"); } if ($document->get('geom_wkt')) { sfLoader::loadHelpers(array('General')); $doc = DocumentI18n::findNameDescription($id, $lang); // document can exist (id) but not in required lang (id, lang) if ($doc) { $this->name = $doc->get('name'); $this->description = $doc->get('description'); $this->slug = get_slug($doc); } else { $this->name = 'C2C::' . ucfirst(substr($module, 0, strlen($module) - 1)) . " {$id}"; $this->description = ""; $this->slug = ""; } $response = $this->getResponse(); switch ($format) { case 'gpx': $this->points = gisQuery::getEWKT($id, true, $module, $version); $this->setTemplate('../../documents/templates/exportgpx'); $response->setContentType('application/gpx+xml'); break; case 'kml': $this->points = gisQuery::getEWKT($id, true, $module, $version); $this->setTemplate('../../documents/templates/exportkml'); $response->setContentType('application/vnd.google-earth.kml+xml'); break; case 'json': $this->geojson = gisQuery::getGeoJSON($id, $module, $version, 6); $this->setTemplate('../../documents/templates/exportjson'); $response->setContentType('application/json'); break; } $this->setLayout(false); } else { sfLoader::loadHelpers('General'); $this->setErrorAndRedirect('This document has no geometry', "@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug=" . get_slug($document)); } }