Changeset 0662b2d for src/webapp/webservice/inc/GnuBoat/TrackItem.php
- Timestamp:
- Aug 30, 2017, 2:45:37 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- a50c18f
- Parents:
- 89c510f
- File:
-
- 1 edited
-
src/webapp/webservice/inc/GnuBoat/TrackItem.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/inc/GnuBoat/TrackItem.php
r89c510f r0662b2d 24 24 class TrackItem 25 25 { 26 function __construct( )27 { 28 $this-> _time = null;29 $this-> _latitude = null;30 $this-> _longitude = null;26 function __construct($timestamp = null, $latitude = null, $longitude = null) 27 { 28 $this->setTimestamp($timestamp); 29 $this->setLatitude($latitude); 30 $this->setLongitude($longitude); 31 31 $this->_speedThroughWater = null; 32 32 $this->_speedOverGround = null; … … 35 35 $this->_waterTemperature = null; 36 36 $this->_gpsfix = null; 37 } 38 37 38 $this->_properties = [ 39 "time" => ["timestamp", "setTimestamp"], 40 "latitude" => ["latitude", "setLatitude"], 41 "longitude" => ["longitude", "setLongitude"], 42 "speedthroughwater" => ["speedThroughWater", "setSpeedThroughWater"], 43 "speedoverground" => ["speedOverGround", "setSpeedOverGround"], 44 "courseoverground" => ["courseOverGround", "setCourseOverGround"], 45 "waterdepth" => ["waterDepth", "setWaterDepth"], 46 "watertemperature" => ["waterTemperature", "setWaterTemperature"], 47 "gpsfix" => ["gpsFix", "setGpsFix"], 48 ]; 49 } 50 51 public function hasProperty($property) 52 { 53 return array_key_exists(strtolower($property), $this->_properties); 54 } 55 56 public function getProperty($property) 57 { 58 $property = strtolower($property); 59 if(!$this->hasProperty($property)) 60 return null; 61 return call_user_func(array($this, $this->_properties[$property][0])); 62 } 63 64 public function setProperty($property, $value) 65 { 66 $property = strtolower($property); 67 if(!$this->hasProperty($property)) 68 return false; 69 return call_user_func(array($this, $this->_properties[$property][1]), $value); 70 } 71 39 72 public function setTimestamp($time) 40 73 { 74 if(!is_numeric($time) || is_nan($time)){ 75 $this->_time = null; 76 return false; 77 } 41 78 $this->_time = $time; 79 return true; 42 80 } 43 81 … … 45 83 { 46 84 $timezone = new \DateTimeZone("UTC"); 47 if($dateTime == null) 85 if($dateTime == null){ 48 86 $this->_time = null; 87 return true; 88 } 49 89 $dateTime->setTimezone($timezone); 50 90 $this->_time = $dateTime->getTimestamp(); 91 return true; 51 92 } 52 93 … … 56 97 } 57 98 58 public function setLatitude($latitude) 59 { 99 public function setLatitude($latitude) 100 { 101 if(!is_numeric($latitude) || is_nan($latitude)){ 102 $this->_latitude = null; 103 return false; 104 } 60 105 $this->_latitude = $latitude; 106 return true; 61 107 } 62 108 … … 66 112 } 67 113 68 public function setLongitude($longitude) 69 { 114 public function setLongitude($longitude) 115 { 116 if(!is_numeric($longitude) || is_nan($longitude)){ 117 $this->_longitude = null; 118 return false; 119 } 70 120 $this->_longitude = $longitude; 121 return true; 71 122 } 72 123 … … 76 127 } 77 128 78 public function setSpeedThroughWater($speedThroughWater) 79 { 129 public function setSpeedThroughWater($speedThroughWater) 130 { 131 if(!is_numeric($speedThroughWater) || is_nan($speedThroughWater)){ 132 $this->_speedThroughWater = null; 133 return false; 134 } 80 135 $this->_speedThroughWater = $speedThroughWater; 136 return true; 81 137 } 82 138 … … 86 142 } 87 143 88 public function setSpeedOverGround($speedOverGround) 89 { 144 public function setSpeedOverGround($speedOverGround) 145 { 146 if(!is_numeric($speedOverGround) || is_nan($speedOverGround)){ 147 $this->_speedOverGround = null; 148 return false; 149 } 90 150 $this->_speedOverGround = $speedOverGround; 151 return true; 91 152 } 92 153 … … 96 157 } 97 158 98 public function setCourseOverGround($courseOverGround) 99 { 159 public function setCourseOverGround($courseOverGround) 160 { 161 if(!is_numeric($courseOverGround) || is_nan($courseOverGround)){ 162 $this->_courseOverGround = null; 163 return false; 164 } 100 165 $this->_courseOverGround = $courseOverGround; 166 return true; 101 167 } 102 168 … … 106 172 } 107 173 108 public function setWaterDepth($waterDepth) 109 { 174 public function setWaterDepth($waterDepth) 175 { 176 if(!is_numeric($waterDepth) || is_nan($waterDepth)){ 177 $this->_waterDepth = null; 178 return false; 179 } 110 180 $this->_waterDepth = $waterDepth; 181 return true; 111 182 } 112 183 … … 116 187 } 117 188 118 public function setWaterTemperature($waterTemperature) 119 { 189 public function setWaterTemperature($waterTemperature) 190 { 191 if(!is_numeric($waterTemperature) || is_nan($waterTemperature)){ 192 $this->_waterTemperature = null; 193 return false; 194 } 120 195 $this->_waterTemperature = $waterTemperature; 196 return true; 121 197 } 122 198 … … 126 202 } 127 203 128 public function setGpsFix($gpsFix) 129 { 204 public function setGpsFix($gpsFix) 205 { 206 if(!is_numeric($gpsFix) || is_nan($gpsFix)){ 207 $this->_gpsFix = null; 208 return false; 209 } 130 210 $this->_gpsFix = $gpsFix; 211 return true; 131 212 } 132 213 … … 136 217 } 137 218 219 public function gpsFixString() 220 { 221 switch($this->gpsFix()){ 222 case 2: 223 return "2D"; 224 case 3: 225 return "3D"; 226 default: 227 return "-"; 228 } 229 } 230 231 public function gpsFixed() 232 { 233 if($this->gpsFix() != null && $this->gpsFix() > 1) 234 return true; 235 return false; 236 } 237 138 238 public function isValid() 139 239 { … … 149 249 public function toArray() 150 250 { 151 $speedThroughWater = ($this->speedThroughWater() != null) ? $this->speedThroughWater() : 0;152 $speedOverGround = ($this->speedOverGround() != null) ? $this->speedOverGround() : 0;153 $courseOverGround = ($this->courseOverGround() != null) ? $this->courseOverGround() : 0;154 $waterDepth = ($this->waterDepth() != null) ? $this->waterDepth() : 0;155 $waterTemperature = ($this->waterTemperature() != null) ? $this->waterTemperature() : 0;156 $gpsFix = ($this->gpsFix() != null) ? $this->gpsFix() : 0;251 $speedThroughWater = ($this->speedThroughWater() != null) ? $this->speedThroughWater() : "-"; 252 $speedOverGround = ($this->speedOverGround() != null) ? $this->speedOverGround() : "-"; 253 $courseOverGround = ($this->courseOverGround() != null) ? $this->courseOverGround() : "-"; 254 $waterDepth = ($this->waterDepth() != null) ? $this->waterDepth() : "-"; 255 $waterTemperature = ($this->waterTemperature() != null) ? $this->waterTemperature() : "-"; 256 $gpsFix = $this->gpsFixString(); 157 257 158 258 return [
Note:
See TracChangeset
for help on using the changeset viewer.
