2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class PathController extends Zend_Controller_Action
7 public function indexAction() {
8 $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
10 $user = $this->_helper->SyjSession->user();
12 throw new Syj_Exception_Forbidden();
15 $decoder = new gisconverter\WKT();
18 $geom = $decoder->geomFromText($formData["geom_data"]);
19 } catch (gisconverter\CustomException $e) {
20 throw new Syj_Exception_Request();
23 if ($geom::name != "LineString") {
24 throw new Syj_Exception_Request();
27 $path = new Syj_Model_Path();
28 $pathMapper = new Syj_Model_PathMapper();
29 if (isset ($formData["geom_id"]) and $formData["geom_id"]) {
30 if (!$pathMapper->find($formData["geom_id"], $path)) {
31 throw new Syj_Exception_Request("unreferenced");
36 if ($path->owner->id != $user->id) {
37 throw new Syj_Exception_Forbidden();
42 if (isset($formData["geom_title"])) {
43 $path->title = $formData["geom_title"];
46 $pathMapper->save ($path);
47 } catch(Zend_Db_Statement_Exception $e) {
48 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
49 $message = $e->getMessage();
50 if (strpos($message, 'paths_geom_key') !== false) {
51 throw new Syj_Exception_Request("uniquepath");
60 $this->_helper->SyjApi->setBody($path->id);