X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=application%2Fcontrollers%2FPathController.php;h=375b83e8e32c798dbcdbe956a3be3000f74f3a4e;hb=0fb09adccd5c3b305d56f1b267dbd3bf836fd17f;hp=aa41866679103703bb66909032302ecd59fd645d;hpb=ec061a75fe57a25eb7ef0894f5e723397ba35472;p=syj.git diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index aa41866..375b83e 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -1,5 +1,5 @@ creator = $user; $path->creatorIp = $this->getRequest()->getClientIp(true); - return $this->save($path, $formData); + $this->save($path, $formData); + + $redirecturl = "idx/" . (string)$path->id; + if ($this->getRequest()->isXmlHttpRequest()) { + $data = array('redirect' => $redirecturl); + $this->_helper->SyjApi->setCode(201)->setBodyJson($data); + } else { + $this->_helper->SyjApi->setRedirect($redirecturl, 303); + } } public function updateAction() { $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); - return $this->save($this->getPath(), $formData); + $path = $this->getPath(); + $this->save($path, $formData); + $this->_helper->SyjApi->setCode(200); // we should use 204, but ie mangles 204 to 1223 } public function deleteAction() { $path = $this->getPath(); $pathMapper = new Syj_Model_PathMapper(); $pathMapper->delete ($path); - $this->_helper->SyjApi->setCode(204); + $this->_helper->SyjApi->setCode(200); // we should use 204, but ie mangles 204 to 1223 } public function getPath() { @@ -51,12 +61,22 @@ class PathController extends Zend_Controller_Action public function save(Syj_Model_Path $path, $formData) { /* setting geom property */ - $decoder = new gisconverter\WKT(); - try { - $geom = $decoder->geomFromText($formData["geom_data"]); - } catch (gisconverter\CustomException $e) { - throw new Syj_Exception_Request(); + $geom = null; + foreach (array("WKT", "KML", "GPX", "geoJSON") as $dectype) { + $classname = 'gisconverter\\' . $dectype; + $decoder = new $classname(); + try { + $geom = $decoder->geomFromText($formData["geom_data"]); + } catch (Exception $e) { + } + if ($geom) { + break; + } + } + if (!$geom) { + throw new Syj_Exception_InvalidGeomUpload(); } + if ($geom::name != "LineString") { throw new Syj_Exception_Request(); } @@ -84,8 +104,6 @@ class PathController extends Zend_Controller_Action throw $e; } } - - $this->_helper->SyjApi->setBody($path->id); } }