<?php
-/* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
and is published under the AGPL license. */
class PathController extends Zend_Controller_Action
$formData = $this->_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();
}
$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() {
$formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
$path = $this->getPath();
$this->save($path, $formData);
- $this->_helper->SyjApi->setCode(204);
+ $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() {
}
}
- $user = $this->_helper->SyjSession->user();
+ $user = $this->_helper->SyjUserManager->current();
if (!$path->isCreator($user)) {
throw new Syj_Exception_Forbidden();
}
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;
/* 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);
}
}