Overview

Namespaces

  • api
  • config
  • database
  • None
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • Api
  • PisApi
  • PssApi
  • SpsApi
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace api;
  4: 
  5: include_once "../../global.inc.php";
  6: include_once PATH_DATABASE . "/SpsSqlManager.php";
  7: require_once PATH_API . "/Api.php";
  8: 
  9: /**
 10:  * This class provides some spezial SpsAPI methods
 11:  * @author stubbfel
 12:  * @since 20.06.2013
 13:  */
 14: class SpsApi extends Api {
 15: 
 16:     /**
 17:      * Route string for the alias paramter
 18:      * @var string
 19:      */
 20:     public static $routeParameterAlias = "/alias/:alias";
 21: 
 22:     /**
 23:      * Route string for the domain paramter
 24:      * @var string
 25:      */
 26:     public static $routeParameterDomain = "(/domain/:domain)";
 27:         /**
 28:      * Route string for the range paramter
 29:      * @var string
 30:      */
 31:     public static $routeParameterRange = "(/range/:range)";
 32: 
 33:     /**
 34:      * Route string for the Longitude paramter
 35:      * @var string
 36:      */
 37:     public static $routeParameterLongitude = "/longitude/:longitude";
 38: 
 39:     /**
 40:      * Route string for the latitude paramter
 41:      * @var string
 42:      */
 43:     public static $routeParameterLatitude = "/latitude/:latitude";
 44: 
 45:     /**
 46:      * Keyword for alias arguments
 47:      * @var string
 48:      */
 49:     public static $keyAlias = "alias";
 50: 
 51:     /**
 52:      * Keyword for domain arguments
 53:      * @var string
 54:      */
 55:     public static $keyDomain = "domain";
 56: 
 57:     /**
 58:      * Keyword for polygon arguments
 59:      * @var string
 60:      */
 61:     public static $keyPoly = "poly";
 62: 
 63:     /**
 64:      * Keyword for longitude arguments
 65:      * @var string
 66:      */
 67:     public static $keyLong = "longitude";
 68: 
 69:     /**
 70:      * Keyword for latitude arguments
 71:      * @var string
 72:      */
 73:     public static $keyLat = "latitude";
 74: 
 75:     /**
 76:      * Keyword for range arguments
 77:      * @var string
 78:      */
 79:     public static $keyRange = "range";
 80: 
 81:     /*
 82:      * Varible for the range of the searchpolygon
 83:      * @var float
 84:      */
 85:     private static $range = 0.001;
 86: 
 87:     /*
 88:      * Varible for the fist chars of the string for a Polygon
 89:      * @var string
 90:      */
 91:     private static $polyStartStr = "GeomFromText('Polygon((";
 92: 
 93:     /*
 94:      * Varible for the last chars of the string for a Polygon
 95:      * @var string
 96:      */
 97:     private static $polyEndStr = "))'";
 98: 
 99:     /**
100:      * maximum value of latitude
101:      * @var float
102:      */
103:     private static $maxLat = 180;
104: 
105:     /**
106:      * minimum value of latitude
107:      * @var float
108:      */
109:     private static $minLat = -180;
110: 
111:     /**
112:      * maximum value of longitude
113:      * @var float
114:      */
115:     private static $maxLong = 180;
116: 
117:     /**
118:      * minimum value of longitude
119:      * @var float
120:      */
121:     private static $minLong = -180;
122: 
123:     /**
124:      * Constructor
125:      * @param array[assoc] $headers - RequestHeader
126:      */
127:     public function __construct($headers = array()) {
128:         $this->sqlManager = new \database\SpsSqlManager();
129:         parent::__construct($headers);
130:     }
131: 
132:     /**
133:      * Default-DeConstructor
134:      */
135:     public function __destruct() {
136:         parent::__destruct();
137:     }
138: 
139:     /**
140:      * Method start a sps-query(alias)
141:      * @param array $queryArgs
142:      * @return querry result as xml
143:      */
144:     public function sendSpsAliasQuery($queryArgs) {
145:         $result = $this->sqlManager->sendSpsAliasQuery($queryArgs);
146:         return $this->serialManager->arrayToSps($result);
147:     }
148: 
149:     /**
150:      * Method start a sps-query(Coordinates)
151:      * @param array $queryArgs
152:      * @return querry result as xml
153:      */
154:     public function sendSpsCoordinateQuery($queryArgs) {
155: 
156:         // check arguments of the query
157:         if (!array_key_exists(self::$keyLong, $queryArgs) || !array_key_exists(self::$keyLat, $queryArgs)) {
158:             return null;
159:         }
160:         $latitude = $queryArgs[self::$keyLat];
161:         $longitude = $queryArgs[self::$keyLong];
162: 
163:         if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
164:             return null;
165:         }
166: 
167:         // build a request polygon
168:         if (array_key_exists(self::$keyRange, $queryArgs)) {
169:             $newRange = $queryArgs[self::$keyRange];
170:             if ($this->validRange($newRange)) {
171:                 self::$range = $newRange;
172:             } else {
173:                 return;
174:             }
175:         }
176:         $queryArgs[self::$keyPoly] = $this->createPolygon($latitude, $longitude, self::$range);
177:         
178:         // send querry
179:         $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
180:         return $this->serialManager->arrayToSps($result);
181:     }
182: 
183:     /**
184:      * Method check if a string is a valid Longitude
185:      * @param string $string
186:      * @return bool
187:      */
188:     private function validRange($string) {
189:         $digit = str_replace(".", "", $string);
190:         if (ctype_digit($digit)) {
191:             return TRUE;
192:         };
193:         return FALSE;
194:     }
195: 
196:     /**
197:      * Method check if a string is a valid Longitude
198:      * @param string $string
199:      * @return bool
200:      */
201:     private function validLongitude($string) {
202:         $digitLessPoint = str_replace(".", "", $string);
203:         $digit = str_replace("-", "", $digitLessPoint);
204:         if (ctype_digit($digit)) {
205:             if ($string <= self::$maxLong && $string >= self::$minLong) {
206:                 return TRUE;
207:             }
208:         };
209:         return FALSE;
210:     }
211: 
212:     /**
213:      * Method check if a string is a valid Latitude
214:      * @param strinf $string
215:      * @return bool
216:      */
217:     private function validLatitude($string) {
218:         $digitLessPoint = str_replace(".", "", $string);
219:         $digit = str_replace("-", "", $digitLessPoint);
220:         if (ctype_digit($digit)) {
221:             if ($string <= self::$maxLat && $string >= self::$minLat) {
222:                 return TRUE;
223:             }
224:         };
225:         return FALSE;
226:     }
227: 
228:     /**
229:      * Method create a Polygon
230:      * @param float $latitude
231:      * @param float $longitude
232:      * @param float $range
233:      * @return string
234:      */
235:     private function createPolygon($latitude, $longitude, $range) {
236:         $minLat = $latitude - $range;
237:         $minLong = $longitude - $range;
238:         $maxLat = $latitude + $range;
239:         $maxLong = $longitude + $range;
240:          return self::$polyStartStr . "$minLong $minLat,$minLong $maxLat,$maxLong $maxLat,$maxLong $minLat,$minLong $minLat" . self::$polyEndStr;
241:     }
242: 
243: }
244: 
245: ?>
246: 
GeoApi API documentation generated by ApiGen 2.8.0