public function indexAction() { $user = $this->_helper->SyjUserManager->current(); $pathMapper = new Syj_Model_PathMapper(); $list = $pathMapper->fetchByCreator($user); $paginator = Zend_Paginator::factory($list); $paginator->setDefaultItemCountPerPage(20); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); $this->view->paginator = $paginator; $this->_jsLocaleStrings(); }
public function loginAction() { $form = new Syj_Form_Login(array('name' => 'loginform')); $request = $this->getRequest(); $formData = $request->getPost(); $this->view->form = $form; $httprequest = $request->isXmlHttpRequest(); if (!$httprequest) { $this->_jsLocaleStrings(); } if (empty($formData) or !$form->isValid($formData)) { if ($httprequest) { throw new Syj_Exception_Request(); } else { return; } } /* form has been filled */ if (!$this->_helper->SyjUserManager->validate($formData['login_user'], sha1($formData['login_password']), $formData['login_rememberme'])) { if ($httprequest) { throw new Syj_Exception_Forbidden(); } else { $form->addError('Wrong login/password'); return; } } $user = $this->_helper->SyjUserManager->current(); if ($httprequest) { $api = $this->_helper->SyjApi->setCode(200); $data = array('pseudo' => $user->pseudo); $login_geom_id = $formData['login_geom_id']; if ($login_geom_id) { $path = new Syj_Model_Path(); $pathMapper = new Syj_Model_PathMapper(); if (!$pathMapper->find((int) $login_geom_id, $path)) { throw new Syj_Exception_Request(); } $data['iscreator'] = $path->creator->id === $user->id; } else { $data['iscreator'] = true; } $api->setBodyJson($data); } else { $this->redirect(); } }
public function indexAction() { $request = $this->getRequest(); $response = $this->getResponse(); $idx = $request->idx; $pathMapper = new Syj_Model_PathMapper(); $path = new Syj_Model_Path(); $api = $this->_helper->SyjApi; $ext = ""; $parts = explode('.', $idx); if (count($parts) >= 2) { $ext = end($parts); if (in_array($ext, array('kml', 'gpx', 'json'))) { $idx = implode('.', explode('.', $idx, -1)); } else { $ext = ""; } } if (!$pathMapper->find($idx, $path)) { if (!$pathMapper->findByTitle($idx, $path)) { if ($pathMapper->hasexisted($idx)) { $api->setCode(410); } else { $api->setCode(404); } return; } } switch ($ext) { case 'kml': $this->kml($path); break; case 'gpx': $this->gpx($path); break; case 'json': default: $this->json($path); return; break; } }
public function indexAction() { $this->_initForms(); $url = $this->getRequest()->getUserParam('url'); if (isset($url)) { $this->view->geomform->setAction(""); $pathMapper = new Syj_Model_PathMapper(); $path = new Syj_Model_Path(); if (!$pathMapper->findByUrl($url, $path)) { if (is_numeric($url) and $pathMapper->hasexisted($url)) { $this->view->message = $this->view->translate("route has been deleted"); throw new Syj_Exception_NotFound('Gone', 410); } else { $this->view->message = $this->view->translate("route does not exist"); throw new Syj_Exception_NotFound('Not Found', 404); } } if ($this->getRequest()->getQuery('format') == 'raw') { $this->rawmode($path); return; } $title = $path->displayTitle; $this->view->path = $path; $jsgeom = new phptojs\JsObject('gInitialGeom', array('data' => (string) $path->geom)); $this->view->headScript()->prependScript((string) $jsgeom); $this->view->loginform->login_geom_id->setValue((string) $path->id); $this->view->geomform->geom_title->setValue($path->title); $this->view->profileActive = $this->_hasAltiProfile($path); } else { $this->_setInitialPos(); $title = "Show your journey"; } $this->_jsLoggedInfo(isset($url) ? $path : null); $this->_jsLocaleStrings(); if (isset($url) and $path->creator) { $this->view->jslocales['geomAttribution'] = $this->view->translate('route by <strong>%s</strong>', (string) $path->creator->pseudo); } $this->view->headTitle($title); $this->view->headMeta()->appendName('description', $this->view->translate('website to share routes')); $this->view->loggedUser = $this->_helper->SyjUserManager->current(); }
public function indexAction() { $url = $this->getRequest()->getUserParam('url'); if (!isset($url)) { throw new Syj_Exception_NotFound('Not Found', 404); } $pathMapper = new Syj_Model_PathMapper(); $path = new Syj_Model_Path(); if (!$pathMapper->findByUrl($url, $path)) { if (is_numeric($url) and $pathMapper->hasexisted($url)) { throw new Syj_Exception_NotFound('Gone', 410); } else { throw new Syj_Exception_NotFound('Not Found', 404); } } $size = $this->getRequest()->getQuery('size', 'big'); if ($size == 'small') { $width = 300; $height = 225; } else { $width = 800; $height = 600; $size = 'big'; } $file = $path->getProfileCache($size); if (file_exists($file)) { if (filesize($file) == 0) { throw new Syj_Exception_NotImplemented("could not compute altitude profile"); } $this->sendFile($file); return; } try { $service = $this->_helper->SyjAltiService->service(); /* we accept 2% of invalid values in the profile */ $profile = $path->getAltiProfile($service, 2 / 100); } catch (Syj_Exception_NotImplemented $e) { @touch($file); throw $e; } $canvas = $this->drawProfile($profile, $width, $height); $canvas->draw($file); $this->sendFile($file); }
public function save(Syj_Model_Path $path, $formData) { /* setting geom property */ $geom = null; foreach (array("WKT", "KML", "GPX", "geoJSON") as $dectype) { $classname = 'gisconverter\\' . $dectype; $decoder = new $classname(); try { $geom = $decoder->geomFromText($formData["geom_data"]); } catch (Exception $e) { } if ($geom) { break; } } if (!$geom) { throw new Syj_Exception_InvalidGeomUpload(); } // merge linestrings for gpx containting multiple trkseg elements. if ($classname == 'gisconverter\\GPX' && $geom::name == 'GeometryCollection') { $geomstring = ""; foreach (array_filter($geom->components, function ($geom) { return $geom::name == "LineString"; }) as $linestring) { $geomstring .= str_replace("<trkseg>", "", str_replace("</trkseg>", "", $linestring->toGPX())); } $geom = $decoder->geomFromText("<trkseg>" . $geomstring . "</trkseg>"); } if ($geom::name != "LineString") { throw new Syj_Exception_InvalidGeomUpload(); } $path->geom = $geom; /* setting title property */ if (isset($formData["geom_title"])) { $path->title = $formData["geom_title"]; } /* now, saving !*/ $pathMapper = new Syj_Model_PathMapper(); $pathMapper->save($path); }