| [db38696] | 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 | {
|
|---|
| [b5ebb8d] | 31 | public function __construct($city, $postalCode = "",
|
|---|
| [db38696] | 32 | $regionName = "", $regionCode = "",
|
|---|
| 33 | $countryName = "", $countryCode = "",
|
|---|
| 34 | $latitude = "", $longitude = "",
|
|---|
| 35 | $timeZone = ""){
|
|---|
| 36 |
|
|---|
| 37 | $this->_city = "";
|
|---|
| [b5ebb8d] | 38 | $this->_postalCode = "";
|
|---|
| [db38696] | 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);
|
|---|
| [b5ebb8d] | 49 | $this->setPostalCode($postalCode);
|
|---|
| [db38696] | 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 |
|
|---|
| [b5ebb8d] | 64 | public function setPostalCode($code){
|
|---|
| 65 | $this->_postalCode = $code;
|
|---|
| [db38696] | 66 | }
|
|---|
| 67 |
|
|---|
| [b5ebb8d] | 68 | public function postalCode(){
|
|---|
| 69 | return $this->_postalCode;
|
|---|
| [db38696] | 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){
|
|---|
| [b5ebb8d] | 112 | if(self::validLatitude($latitude))
|
|---|
| [db38696] | 113 | $this->_latitude = $latitude;
|
|---|
| [b5ebb8d] | 114 | if(self::validLongitude($longitude))
|
|---|
| [db38696] | 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 | }
|
|---|
| [b5ebb8d] | 129 |
|
|---|
| 130 | public static function validLatitude($latitude){
|
|---|
| 131 | if(is_numeric($latitude) && (-90.0 <= $latitude && $latitude <= 90.0))
|
|---|
| 132 | return true;
|
|---|
| 133 | return false;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | public static function validLongitude($longitude){
|
|---|
| 137 | if(is_numeric($longitude) && (-180.0 <= $longitude && $longitude <= 180.0))
|
|---|
| 138 | return true;
|
|---|
| 139 | return false;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| [db38696] | 142 | public function setTimeZone($zone){
|
|---|
| 143 | if(preg_match("/^[\D]+\/[\D]+$/", $zone) > 0)
|
|---|
| 144 | $this->_timeZone = $zone;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | public function timeZone(){
|
|---|
| 148 | return $this->_timeZone;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | private $_countryCode;
|
|---|
| 152 | private $_countryName;
|
|---|
| 153 | private $_regionCode;
|
|---|
| 154 | private $_regionName;
|
|---|
| 155 | private $_city;
|
|---|
| [b5ebb8d] | 156 | private $_postalCode;
|
|---|
| [db38696] | 157 | private $_timeZone;
|
|---|
| 158 | private $_latitude;
|
|---|
| 159 | private $_longitude;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | ?>
|
|---|