X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=application%2Fcontrollers%2FPathController.php;h=f0ef477e0969fdd32a6911aced09276a453ed689;hb=efd74d3cddbac3cb5d317a5e14ba9d70281531c4;hp=c3c085a8695ff1eddbed1874edea580e8b9644ed;hpb=3ff82e2d9fa289beba4e965b82772cf83f905b2f;p=syj.git diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index c3c085a..f0ef477 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -1,14 +1,46 @@ save(new Syj_Model_Path()); + $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); + $path = new Syj_Model_Path(); + + $user = $this->_helper->SyjUserManager->current(); + if (!$user and !$formData["geom_accept"]) { + throw new Syj_Exception_Request(); + } + $path->creator = $user; + $path->creatorIp = $this->getRequest()->getClientIp(true); + + $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'); + $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(200); // we should use 204, but ie mangles 204 to 1223 + } + + public function getPath() { $idx = $this->getRequest()->getUserParam('idx'); $path = new Syj_Model_Path(); $pathMapper = new Syj_Model_PathMapper(); @@ -19,37 +51,34 @@ class PathController extends Zend_Controller_Action throw new Syj_Exception_NotFound('Not Found', 404); } } - return $this->save($path); - } - - public function save(Syj_Model_Path $path) { - $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); - /* authorization check */ - $user = $this->_helper->SyjSession->user(); - if (!$user and !$formData["geom_accept"]) { - throw new Syj_Exception_Request(); + $user = $this->_helper->SyjUserManager->current(); + if (!$path->isCreator($user)) { + throw new Syj_Exception_Forbidden(); } + return $path; + } - /* setting creator property */ - if ($path->getId()) { - if (!$path->isCreator($user)) { - throw new Syj_Exception_Request(); + public function save(Syj_Model_Path $path, $formData) { + /* setting geom property */ + $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; } - } else { - $path->creator = $user; } - $path->creatorIp = $this->getRequest()->getClientIp(true); - - /* setting geom property */ - $decoder = new gisconverter\WKT(); - try { - $geom = $decoder->geomFromText($formData["geom_data"]); - } catch (gisconverter\CustomException $e) { - throw new Syj_Exception_Request(); + if (!$geom) { + throw new Syj_Exception_InvalidGeomUpload(); } + if ($geom::name != "LineString") { - throw new Syj_Exception_Request(); + throw new Syj_Exception_InvalidGeomUpload(); } $path->geom = $geom; @@ -67,7 +96,7 @@ class PathController extends Zend_Controller_Action 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"); + throw new Syj_Exception_InvalidGeomUpload("uniquepath"); } else { throw $e; } @@ -75,8 +104,6 @@ class PathController extends Zend_Controller_Action throw $e; } } - - $this->_helper->SyjApi->setBody($path->id); } }