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 return $this->save(new Syj_Model_Path());
11 public function updateAction() {
12 $idx = $this->getRequest()->getUserParam('idx');
13 $path = new Syj_Model_Path();
14 $pathMapper = new Syj_Model_PathMapper();
15 if (!$pathMapper->find($idx, $path)) {
16 if ($pathMapper->hasexisted($idx)) {
17 throw new Syj_Exception_NotFound('Gone', 410);
19 throw new Syj_Exception_NotFound('Not Found', 404);
22 return $this->save($path);
25 public function save(Syj_Model_Path $path) {
26 $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
28 /* authorization check */
29 $user = $this->_helper->SyjSession->user();
30 if (!$user and !$formData["geom_accept"]) {
31 throw new Syj_Exception_Request();
34 /* setting creator property */
36 if (!$path->isCreator($user)) {
37 throw new Syj_Exception_Request();
40 $path->creator = $user;
42 $path->creatorIp = $this->getRequest()->getClientIp(true);
44 /* setting geom property */
45 $decoder = new gisconverter\WKT();
47 $geom = $decoder->geomFromText($formData["geom_data"]);
48 } catch (gisconverter\CustomException $e) {
49 throw new Syj_Exception_Request();
51 if ($geom::name != "LineString") {
52 throw new Syj_Exception_Request();
56 /* setting title property */
57 if (isset($formData["geom_title"])) {
58 $path->title = $formData["geom_title"];
63 $pathMapper = new Syj_Model_PathMapper();
65 $pathMapper->save ($path);
66 } catch(Zend_Db_Statement_Exception $e) {
67 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
68 $message = $e->getMessage();
69 if (strpos($message, 'paths_geom_key') !== false) {
70 throw new Syj_Exception_Request("uniquepath");
79 $this->_helper->SyjApi->setBody($path->id);