X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=application%2Fcontrollers%2FPathController.php;h=394da6921cac13042844cc78e0a5e4d99a839041;hb=e534c17db2f3986751f4a96900e4aaae56d34873;hp=bb969e82c8ed6b15888a6cf9de01adc0510c7a4e;hpb=a3870411b5c5217e7b2f063d2929fc2e14daa962;p=syj.git diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index bb969e8..394da69 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -1,5 +1,5 @@ _helper->SyjPostData->getPostData('Syj_Form_Geom'); $path = new Syj_Model_Path(); - $user = $this->_helper->SyjSession->user(); + $user = $this->_helper->SyjUserManager->current(); if (!$user and !$formData["geom_accept"]) { throw new Syj_Exception_Request(); } @@ -16,8 +16,14 @@ class PathController extends Zend_Controller_Action $path->creatorIp = $this->getRequest()->getClientIp(true); $this->save($path, $formData); - $data = array('redirect' => "idx/" . (string)$path->id); - $this->_helper->SyjApi->setCode(201)->setBodyJson($data); + + $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() { @@ -46,7 +52,7 @@ class PathController extends Zend_Controller_Action } } - $user = $this->_helper->SyjSession->user(); + $user = $this->_helper->SyjUserManager->current(); if (!$path->isCreator($user)) { throw new Syj_Exception_Forbidden(); } @@ -55,14 +61,24 @@ 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(); + throw new Syj_Exception_InvalidGeomUpload(); } $path->geom = $geom; @@ -74,20 +90,7 @@ class PathController extends Zend_Controller_Action /* now, saving !*/ $pathMapper = new Syj_Model_PathMapper(); - try { - $pathMapper->save ($path); - } catch(Zend_Db_Statement_Exception $e) { - if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request(); - $message = $e->getMessage(); - if (strpos($message, 'paths_geom_key') !== false) { - throw new Syj_Exception_Request("uniquepath"); - } else { - throw $e; - } - } else { - throw $e; - } - } + $pathMapper->save ($path); } }