X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=application%2Fmodels%2FPath.php;h=6512f76d64bc21cd9a8b357558b1efe527fc4b41;hp=41706e4f58d3bc736c6efc663bc5071a9d8743af;hb=00c2579ade64a20ba2d82e98d3eea5f864864cdb;hpb=190fd621df4920c56a422c03663874cddaa67d64 diff --git a/application/models/Path.php b/application/models/Path.php index 41706e4..6512f76 100644 --- a/application/models/Path.php +++ b/application/models/Path.php @@ -1,14 +1,15 @@ _id = (int) $id; @@ -28,13 +29,20 @@ class Syj_Model_Path extends Syj_Model_Generic return $this->_geom; } - public function setOwner(Syj_Model_User $owner) { - $this->_owner = $owner; + public function setCreator(Syj_Model_User $creator = null) { + $this->_creator = $creator; return $this; } - public function getOwner() { - return $this->_owner; + public function getCreator() { + return $this->_creator; + } + + public function isCreator(Syj_Model_User $creator = null) { + if (!$creator or !$this->creator) { + return false; + } + return ($creator->id == $this->creator->id); } public function setTitle($title) { @@ -50,7 +58,8 @@ class Syj_Model_Path extends Syj_Model_Generic if ($this->_title) { return $this->_title; } else if ($this->_id) { - return "journey number " . (string)$this->_id; + $title = $this->getTranslator()->translate("route number %d"); + return str_replace('%d', (string)$this->id, $title); } else { return ""; } @@ -65,4 +74,79 @@ class Syj_Model_Path extends Syj_Model_Generic return $this->_urlcomp; } + public function setCreatorIp($_creator_ip) { + $this->_creator_ip = (string) $_creator_ip; + return $this; + } + + public function getCreatorIp() { + return $this->_creator_ip; + } + + /* + * returns an array containing two arrays. First one is list of distance + * from start. Second on is altitude at that point. + * @error: ratio of void we accept + */ + public function getAltiProfile($altiService, $error = 0) { + $points = $altiService->interpolate($this->_geom); + $points = array_map(function($point) { + if ($point instanceof \gisconverter\Geometry) { + return array($point->lon, $point->lat); + } + return $point; + }, $points); + $altitudes = $altiService->altitude($points); + + if (is_null($altitudes)) { + throw new Syj_Exception_NotImplemented("could not compute altitude profile"); + } + + $res = array(array(0, $altitudes[0])); + $prevpoint = $points[0]; + $prevdist = 0; + + $alticount = count($altitudes); + $altinull = 0; + foreach (range(1, count($altitudes) - 1) as $idx) { + $point = $points[$idx]; + $delta = $altiService->vincentyDistance($prevpoint[0], $prevpoint[1], $point[0], $point[1]); + $dist = $prevdist + $delta; + if ($delta == 0) { // we have two similar points side to side + continue; + } + if (is_null($altitudes[$idx])) { + $altinull++; + continue; + } + $prevpoint = $point; + $prevdist = $dist; + $res[] = array($dist, $altitudes[$idx]); + } + + if ($altinull / $alticount > $error) { + throw new Syj_Exception_NotImplemented("too many void in altitude profile"); + } + return $res; + } + + public function getProfileCache($size) { + $cacheDir = Zend_Controller_Front::getInstance()->getParam('profileCache'); + if (is_file($cacheDir) and !is_dir($cacheDir)) { + throw new Zend_Exception(); + } + if (!is_dir($cacheDir)) { + if (@mkdir($cacheDir, 0755, true) === false) { + throw new Zend_Exception(); + } + } + + return sprintf("%s/%s-%s.png", $cacheDir, (string)$this->_id, $size); + } + + public function invalidateCache() { + @unlink($this->getProfileCache('small')); + @unlink($this->getProfileCache('big')); + } + }