| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | namespace GnuBoat;
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * @brief One item in a track
|
|---|
| 23 | */
|
|---|
| 24 | class TrackItem
|
|---|
| 25 | {
|
|---|
| 26 | function __construct($timestamp = null, $latitude = null, $longitude = null)
|
|---|
| 27 | {
|
|---|
| 28 | $this->setTimestamp($timestamp);
|
|---|
| 29 | $this->setLatitude($latitude);
|
|---|
| 30 | $this->setLongitude($longitude);
|
|---|
| 31 | $this->_speedThroughWater = null;
|
|---|
| 32 | $this->_speedOverGround = null;
|
|---|
| 33 | $this->_courseOverGround = null;
|
|---|
| 34 | $this->_waterDepth = null;
|
|---|
| 35 | $this->_waterTemperature = null;
|
|---|
| 36 | $this->_gpsfix = null;
|
|---|
| 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 |
|
|---|
| 72 | public function setTimestamp($time)
|
|---|
| 73 | {
|
|---|
| 74 | if(!is_numeric($time) || is_nan($time)){
|
|---|
| 75 | $this->_time = null;
|
|---|
| 76 | return false;
|
|---|
| 77 | }
|
|---|
| 78 | $this->_time = $time;
|
|---|
| 79 | return true;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | public function setDateTime($dateTime)
|
|---|
| 83 | {
|
|---|
| 84 | $timezone = new \DateTimeZone("UTC");
|
|---|
| 85 | if($dateTime == null){
|
|---|
| 86 | $this->_time = null;
|
|---|
| 87 | return true;
|
|---|
| 88 | }
|
|---|
| 89 | $dateTime->setTimezone($timezone);
|
|---|
| 90 | $this->_time = $dateTime->getTimestamp();
|
|---|
| 91 | return true;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | public function timestamp()
|
|---|
| 95 | {
|
|---|
| 96 | return $this->_time;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | public function setLatitude($latitude)
|
|---|
| 100 | {
|
|---|
| 101 | if(!is_numeric($latitude) || is_nan($latitude)){
|
|---|
| 102 | $this->_latitude = null;
|
|---|
| 103 | return false;
|
|---|
| 104 | }
|
|---|
| 105 | $this->_latitude = $latitude;
|
|---|
| 106 | return true;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | public function latitude()
|
|---|
| 110 | {
|
|---|
| 111 | return $this->_latitude;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | public function setLongitude($longitude)
|
|---|
| 115 | {
|
|---|
| 116 | if(!is_numeric($longitude) || is_nan($longitude)){
|
|---|
| 117 | $this->_longitude = null;
|
|---|
| 118 | return false;
|
|---|
| 119 | }
|
|---|
| 120 | $this->_longitude = $longitude;
|
|---|
| 121 | return true;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | public function longitude()
|
|---|
| 125 | {
|
|---|
| 126 | return $this->_longitude;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | public function setSpeedThroughWater($speedThroughWater)
|
|---|
| 130 | {
|
|---|
| 131 | if(!is_numeric($speedThroughWater) || is_nan($speedThroughWater)){
|
|---|
| 132 | $this->_speedThroughWater = null;
|
|---|
| 133 | return false;
|
|---|
| 134 | }
|
|---|
| 135 | $this->_speedThroughWater = $speedThroughWater;
|
|---|
| 136 | return true;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | public function speedThroughWater()
|
|---|
| 140 | {
|
|---|
| 141 | return $this->_speedThroughWater;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | public function setSpeedOverGround($speedOverGround)
|
|---|
| 145 | {
|
|---|
| 146 | if(!is_numeric($speedOverGround) || is_nan($speedOverGround)){
|
|---|
| 147 | $this->_speedOverGround = null;
|
|---|
| 148 | return false;
|
|---|
| 149 | }
|
|---|
| 150 | $this->_speedOverGround = $speedOverGround;
|
|---|
| 151 | return true;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | public function speedOverGround()
|
|---|
| 155 | {
|
|---|
| 156 | return $this->_speedOverGround;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | public function setCourseOverGround($courseOverGround)
|
|---|
| 160 | {
|
|---|
| 161 | if(!is_numeric($courseOverGround) || is_nan($courseOverGround)){
|
|---|
| 162 | $this->_courseOverGround = null;
|
|---|
| 163 | return false;
|
|---|
| 164 | }
|
|---|
| 165 | $this->_courseOverGround = $courseOverGround;
|
|---|
| 166 | return true;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | public function courseOverGround()
|
|---|
| 170 | {
|
|---|
| 171 | return $this->_courseOverGround;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | public function setWaterDepth($waterDepth)
|
|---|
| 175 | {
|
|---|
| 176 | if(!is_numeric($waterDepth) || is_nan($waterDepth)){
|
|---|
| 177 | $this->_waterDepth = null;
|
|---|
| 178 | return false;
|
|---|
| 179 | }
|
|---|
| 180 | $this->_waterDepth = $waterDepth;
|
|---|
| 181 | return true;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | public function waterDepth()
|
|---|
| 185 | {
|
|---|
| 186 | return $this->_waterDepth;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | public function setWaterTemperature($waterTemperature)
|
|---|
| 190 | {
|
|---|
| 191 | if(!is_numeric($waterTemperature) || is_nan($waterTemperature)){
|
|---|
| 192 | $this->_waterTemperature = null;
|
|---|
| 193 | return false;
|
|---|
| 194 | }
|
|---|
| 195 | $this->_waterTemperature = $waterTemperature;
|
|---|
| 196 | return true;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | public function waterTemperature()
|
|---|
| 200 | {
|
|---|
| 201 | return $this->_waterTemperature;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | public function setGpsFix($gpsFix)
|
|---|
| 205 | {
|
|---|
| 206 | if(!is_numeric($gpsFix) || is_nan($gpsFix)){
|
|---|
| 207 | $this->_gpsFix = null;
|
|---|
| 208 | return false;
|
|---|
| 209 | }
|
|---|
| 210 | $this->_gpsFix = $gpsFix;
|
|---|
| 211 | return true;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | public function gpsFix()
|
|---|
| 215 | {
|
|---|
| 216 | return $this->_gpsFix;
|
|---|
| 217 | }
|
|---|
| 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 |
|
|---|
| 238 | public function isValid()
|
|---|
| 239 | {
|
|---|
| 240 | if($this->timestamp() == null)
|
|---|
| 241 | return false;
|
|---|
| 242 | if($this->latitude() == null)
|
|---|
| 243 | return false;
|
|---|
| 244 | if($this->longitude() == null)
|
|---|
| 245 | return false;
|
|---|
| 246 | return true;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | public function toArray()
|
|---|
| 250 | {
|
|---|
| 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();
|
|---|
| 257 |
|
|---|
| 258 | return [
|
|---|
| 259 | "latitude" => $this->latitude(),
|
|---|
| 260 | "longitude" => $this->longitude(),
|
|---|
| 261 | "speedthroughwater" => $speedThroughWater,
|
|---|
| 262 | "speedoverground" => $speedOverGround,
|
|---|
| 263 | "courseoverground" => $courseOverGround,
|
|---|
| 264 | "waterdepth" => $waterDepth,
|
|---|
| 265 | "watertemperature" => $waterTemperature,
|
|---|
| 266 | "gpsfix" => $gpsFix,
|
|---|
| 267 | ];
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | private $_time;
|
|---|
| 271 | private $_latitude, $_longitude;
|
|---|
| 272 | private $_speedThroughWater, $_speedOverGround, $_courseOverGround;
|
|---|
| 273 | private $_waterDepth, $_waterTemperature;
|
|---|
| 274 | private $_gpsFix;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | ?>
|
|---|