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 $path = new Syj_Model_Path();
11 $user = $this->_helper->SyjSession->user();
12 if (!$user and !$formData["geom_accept"]) {
13 throw new Syj_Exception_Request();
15 $path->creator = $user;
16 $path->creatorIp = $this->getRequest()->getClientIp(true);
18 return $this->save($path, $formData);
21 public function updateAction() {
22 $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
23 return $this->save($this->getPath(), $formData);
26 public function deleteAction() {
27 $path = $this->getPath();
28 $pathMapper = new Syj_Model_PathMapper();
29 $pathMapper->delete ($path);
30 $this->_helper->SyjApi->setCode(204);
33 public function getPath() {
34 $idx = $this->getRequest()->getUserParam('idx');
35 $path = new Syj_Model_Path();
36 $pathMapper = new Syj_Model_PathMapper();
37 if (!$pathMapper->find($idx, $path)) {
38 if ($pathMapper->hasexisted($idx)) {
39 throw new Syj_Exception_NotFound('Gone', 410);
41 throw new Syj_Exception_NotFound('Not Found', 404);
45 $user = $this->_helper->SyjSession->user();
46 if (!$path->isCreator($user)) {
47 throw new Syj_Exception_Forbidden();
52 public function save(Syj_Model_Path $path, $formData) {
53 /* setting geom property */
54 $decoder = new gisconverter\WKT();
56 $geom = $decoder->geomFromText($formData["geom_data"]);
57 } catch (gisconverter\CustomException $e) {
58 throw new Syj_Exception_Request();
60 if ($geom::name != "LineString") {
61 throw new Syj_Exception_Request();
65 /* setting title property */
66 if (isset($formData["geom_title"])) {
67 $path->title = $formData["geom_title"];
72 $pathMapper = new Syj_Model_PathMapper();
74 $pathMapper->save ($path);
75 } catch(Zend_Db_Statement_Exception $e) {
76 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
77 $message = $e->getMessage();
78 if (strpos($message, 'paths_geom_key') !== false) {
79 throw new Syj_Exception_Request("uniquepath");
88 $this->_helper->SyjApi->setBody($path->id);