]> dev.renevier.net Git - syj.git/blob - application/controllers/PathController.php
allow anonymous routes creation
[syj.git] / application / controllers / PathController.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class PathController extends Zend_Controller_Action
6 {
7     public function indexAction() {
8         $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom');
9         $decoder = new gisconverter\WKT();
10
11         try {
12             $geom = $decoder->geomFromText($formData["geom_data"]);
13         } catch (gisconverter\CustomException $e) {
14             throw new Syj_Exception_Request();
15         }
16
17         if ($geom::name != "LineString") {
18             throw new Syj_Exception_Request();
19         }
20
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");
26             }
27         }
28         $path->geom = $geom;
29
30         $user = $this->_helper->SyjSession->user();
31         if (!$user and !$formData["geom_accept"]) {
32             throw new Syj_Exception_Request();
33         }
34
35         if ($path->getId()) {
36             if (!$path->isCreator($user)) {
37                 throw new Syj_Exception_Request();
38             }
39         } else {
40             $path->creator = $user;
41         }
42
43         if (isset($formData["geom_title"])) {
44             $path->title = $formData["geom_title"];
45         }
46         $path->creatorIp = $this->getRequest()->getClientIp(true);
47         try {
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");
54                 } else {
55                     throw $e;
56                 }
57             } else {
58                 throw $e;
59             }
60         }
61
62         $this->_helper->SyjApi->setBody($path->id);
63     }
64 }