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');
9 $decoder = new gisconverter\WKT();
12 $geom = $decoder->geomFromText($formData["geom_data"]);
13 } catch (gisconverter\CustomException $e) {
14 throw new Syj_Exception_Request();
17 if ($geom::name != "LineString") {
18 throw new Syj_Exception_Request();
21 $path = new Syj_Model_Path();
22 $pathMapper = new Syj_Model_PathMapper();
23 if (isset ($formData["geom_id"]) and $formData["geom_id"]) {
24 if (!$pathMapper->find($formData["geom_id"], $path)) {
25 throw new Syj_Exception_Request("unreferenced");
30 $user = $this->_helper->SyjSession->user();
31 if (!$user and !$formData["geom_accept"]) {
32 throw new Syj_Exception_Request();
36 if (!$path->isCreator($user)) {
37 throw new Syj_Exception_Request();
40 $path->creator = $user;
43 if (isset($formData["geom_title"])) {
44 $path->title = $formData["geom_title"];
46 $path->creatorIp = $this->getRequest()->getClientIp(true);
48 $pathMapper->save ($path);
49 } catch(Zend_Db_Statement_Exception $e) {
50 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
51 $message = $e->getMessage();
52 if (strpos($message, 'paths_geom_key') !== false) {
53 throw new Syj_Exception_Request("uniquepath");
62 $this->_helper->SyjApi->setBody($path->id);