| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library 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 GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | namespace SiWeather\Webservice;
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * @brief Describes a city in a region and a country.
|
|---|
| 25 | *
|
|---|
| 26 | * The codes (region and country) are Alpha 2 codes from ISO 3166-1 (country) and ISO 3166-2 (subdivision).
|
|---|
| 27 | *
|
|---|
| 28 | */
|
|---|
| 29 | class Location
|
|---|
| 30 | {
|
|---|
| 31 | public function __construct($city, $zipCode = "",
|
|---|
| 32 | $regionName = "", $regionCode = "",
|
|---|
| 33 | $countryName = "", $countryCode = "",
|
|---|
| 34 | $latitude = "", $longitude = "",
|
|---|
| 35 | $timeZone = ""){
|
|---|
| 36 |
|
|---|
| 37 | $this->_city = "";
|
|---|
| 38 | $this->_zipCode = "";
|
|---|
| 39 | $this->_regionName = "";
|
|---|
| 40 | $this->_regionCode = "";
|
|---|
| 41 | $this->_countryName = "";
|
|---|
| 42 | $this->_countryCode = "";
|
|---|
| 43 | $this->_longitude = 0;
|
|---|
| 44 | $this->_latitude = 0;
|
|---|
| 45 | $this->_timeZone = "";
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | $this->setCity($city);
|
|---|
| 49 | $this->setZipCode($zipCode);
|
|---|
| 50 | $this->setRegion($regionName, $regionCode);
|
|---|
| 51 | $this->setCountry($countryName, $countryCode);
|
|---|
| 52 | $this->setLocation($longitude, $latitude);
|
|---|
| 53 | $this->setTimezone($timeZone);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | public function setCity($name){
|
|---|
| 57 | $this->_city = $name;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | public function city(){
|
|---|
| 61 | return $this->_city;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | public function setZipCode($code){
|
|---|
| 65 | $this->_zipCode = $code;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | public function zipCode(){
|
|---|
| 69 | return $this->_zipCode;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | public function setRegion($name, $code){
|
|---|
| 73 | $this->_regionName = $name;
|
|---|
| 74 | if(strlen($code) == 2)
|
|---|
| 75 | $this->_regionCode = $code;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | public function regionName(){
|
|---|
| 79 | return $this->_regionName;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | public function regionCode(){
|
|---|
| 83 | return $this->_regionCode;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | public function setCountry($name, $code){
|
|---|
| 87 | $this->_countryName = $name;
|
|---|
| 88 | if(strlen($code) == 2)
|
|---|
| 89 | $this->_countryCode = $code;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | public function countryName(){
|
|---|
| 93 | return $this->_countryName;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | public function countryCode(){
|
|---|
| 97 | return $this->_countryCode;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * @brief Sets the location to @p $latitude and @p $longitude
|
|---|
| 102 | *
|
|---|
| 103 | * @note Please note that this functions arguments are in the typical order of
|
|---|
| 104 | * city coordinates, whereas the WKT format turned around those values
|
|---|
| 105 | * (WKT(Longitude Latitude)).
|
|---|
| 106 | *
|
|---|
| 107 | * @see latitude()
|
|---|
| 108 | * @see longitude()
|
|---|
| 109 | * @see locationWkt()
|
|---|
| 110 | */
|
|---|
| 111 | public function setLocation($latitude, $longitude){
|
|---|
| 112 | if(is_numeric($latitude) && ($latitude > -90.0 && $latitude < 90.0))
|
|---|
| 113 | $this->_latitude = $latitude;
|
|---|
| 114 | if(is_numeric($longitude) && ($longitude > -180.0 && $longitude < 180.0))
|
|---|
| 115 | $this->_longitude = $longitude;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | public function latitude(){
|
|---|
| 119 | return $this->_latitude;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | public function longitude(){
|
|---|
| 123 | return $this->_longitude;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | public function locationWkt(){
|
|---|
| 127 | return $this->longitude() ." ". $this->latitude();
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | public function setTimeZone($zone){
|
|---|
| 131 | if(preg_match("/^[\D]+\/[\D]+$/", $zone) > 0)
|
|---|
| 132 | $this->_timeZone = $zone;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | public function timeZone(){
|
|---|
| 136 | return $this->_timeZone;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | private $_countryCode;
|
|---|
| 140 | private $_countryName;
|
|---|
| 141 | private $_regionCode;
|
|---|
| 142 | private $_regionName;
|
|---|
| 143 | private $_city;
|
|---|
| 144 | private $_zipCode;
|
|---|
| 145 | private $_timeZone;
|
|---|
| 146 | private $_latitude;
|
|---|
| 147 | private $_longitude;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | ?>
|
|---|