X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=application%2Fcontrollers%2FPathController.php;h=bb969e82c8ed6b15888a6cf9de01adc0510c7a4e;hp=6ef95292baf813d54c7a3a41a0dff0f032148d29;hb=a3870411b5c5217e7b2f063d2929fc2e14daa962;hpb=a64d41557a62ec6051d7fa08d1ba941e089aa5c2 diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index 6ef9529..bb969e8 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -6,44 +6,74 @@ class PathController extends Zend_Controller_Action { public function indexAction() { $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); - $decoder = new gisconverter\WKT(); + $path = new Syj_Model_Path(); - try { - $geom = $decoder->geomFromText($formData["geom_data"]); - } catch (gisconverter\CustomException $e) { + $user = $this->_helper->SyjSession->user(); + if (!$user and !$formData["geom_accept"]) { throw new Syj_Exception_Request(); } + $path->creator = $user; + $path->creatorIp = $this->getRequest()->getClientIp(true); - if ($geom::name != "LineString") { - throw new Syj_Exception_Request(); - } + $this->save($path, $formData); + $data = array('redirect' => "idx/" . (string)$path->id); + $this->_helper->SyjApi->setCode(201)->setBodyJson($data); + } + + 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(); - if (isset ($formData["geom_id"]) and $formData["geom_id"]) { - if (!$pathMapper->find($formData["geom_id"], $path)) { - throw new Syj_Exception_Request("unreferenced"); + if (!$pathMapper->find($idx, $path)) { + if ($pathMapper->hasexisted($idx)) { + throw new Syj_Exception_NotFound('Gone', 410); + } else { + throw new Syj_Exception_NotFound('Not Found', 404); } } - $path->geom = $geom; $user = $this->_helper->SyjSession->user(); - if (!$user and !$formData["geom_accept"]) { - throw new Syj_Exception_Request(); + if (!$path->isCreator($user)) { + throw new Syj_Exception_Forbidden(); } + return $path; + } - if ($path->getId()) { - if (!$path->isCreator($user)) { - throw new Syj_Exception_Request(); - } - } else { - $path->creator = $user; + 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(); } + if ($geom::name != "LineString") { + throw new Syj_Exception_Request(); + } + $path->geom = $geom; + /* setting title property */ if (isset($formData["geom_title"])) { $path->title = $formData["geom_title"]; } - $path->creatorIp = $this->getRequest()->getClientIp(true); + + + /* now, saving !*/ + $pathMapper = new Syj_Model_PathMapper(); try { $pathMapper->save ($path); } catch(Zend_Db_Statement_Exception $e) { @@ -58,7 +88,6 @@ class PathController extends Zend_Controller_Action throw $e; } } - - $this->_helper->SyjApi->setBody($path->id); } + }