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 $sessionStorage = Zend_Auth::getInstance()->getStorage();
11 if ($sessionStorage->isEmpty()) {
12 throw new Syj_Exception_Forbidden();
14 $sessionData = $sessionStorage->read();
16 $user = new Syj_Model_User();
17 $userMapper = new Syj_Model_UserMapper();
18 if (!$userMapper->find($sessionData['user'], $user)) {
19 // we could also throw a forbidden exception, but client session
20 // should not contain reference to a non existent user. So, it's considered a bug.
21 throw new Syj_Exception_Forbidden();
24 $decoder = new gisconverter\WKT();
27 $geom = $decoder->geomFromText($formData["geom_data"]);
28 } catch (gisconverter\CustomException $e) {
29 throw new Syj_Exception_Request();
32 if ($geom::name != "LineString") {
33 throw new Syj_Exception_Request();
36 $path = new Syj_Model_Path();
37 $pathMapper = new Syj_Model_PathMapper();
38 if (isset ($formData["geom_id"]) and $formData["geom_id"]) {
39 if (!$pathMapper->find($formData["geom_id"], $path)) {
40 throw new Syj_Exception_Request("unreferenced");
45 if ($path->owner->id != $user->id) {
46 throw new Syj_Exception_Forbidden();
51 if (isset($formData["geom_title"])) {
52 $path->title = $formData["geom_title"];
55 $pathMapper->save ($path);
56 } catch(Zend_Db_Statement_Exception $e) {
57 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
58 $message = $e->getMessage();
59 if (strpos($message, 'paths_geom_key') !== false) {
60 throw new Syj_Exception_Request("uniquepath");
69 $this->_helper->SyjApi->setBody($path->id);