]> dev.renevier.net Git - syj.git/blobdiff - application/controllers/PathController.php
revert a86eeac0ab678ea55307e1386c5f955f77d8ff73
[syj.git] / application / controllers / PathController.php
index c3c085a8695ff1eddbed1874edea580e8b9644ed..bb969e82c8ed6b15888a6cf9de01adc0510c7a4e 100644 (file)
@@ -5,10 +5,36 @@
 class PathController extends Zend_Controller_Action
 {
     public function indexAction() {
-        return $this->save(new Syj_Model_Path());
+        $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
+        $path = new Syj_Model_Path();
+
+        $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);
+
+        $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();
@@ -19,28 +45,15 @@ 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();
+        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();
-            }
-        } else {
-            $path->creator = $user;
-        }
-        $path->creatorIp = $this->getRequest()->getClientIp(true);
-
+    public function save(Syj_Model_Path $path, $formData) {
         /* setting geom property */
         $decoder = new gisconverter\WKT();
         try {
@@ -75,8 +88,6 @@ class PathController extends Zend_Controller_Action
                 throw $e;
             }
         }
-
-        $this->_helper->SyjApi->setBody($path->id);
     }
 
 }