|
@@ -7,8 +7,7 @@ class Teryt {
|
|
|
const ULIC_TABLE = "TERYT_ULIC";
|
|
const ULIC_TABLE = "TERYT_ULIC";
|
|
|
const PNA_TABLE = "PNA";
|
|
const PNA_TABLE = "PNA";
|
|
|
|
|
|
|
|
- private static function checkArgs($args) {
|
|
|
|
|
- $argsAvailable = ["kodPocztowy", "wojewodztwo", "powiat", "gmina", "miejscowosc", "ulica"];
|
|
|
|
|
|
|
+ private static function checkArgs($args, $argsAvailable) {
|
|
|
if ($args == null) throw new Exception("Missing argument");
|
|
if ($args == null) throw new Exception("Missing argument");
|
|
|
if (!is_array($args)) throw new Exception("Armument must be an array");
|
|
if (!is_array($args)) throw new Exception("Armument must be an array");
|
|
|
if (!count($args)) throw new Exception("Argument list cannot be empty");
|
|
if (!count($args)) throw new Exception("Argument list cannot be empty");
|
|
@@ -22,7 +21,8 @@ class Teryt {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static function search($args = null) {
|
|
public static function search($args = null) {
|
|
|
- self::checkArgs($args);
|
|
|
|
|
|
|
+ $argsAvailable = ["kodPocztowy", "wojewodztwo", "powiat", "gmina", "miejscowosc", "ulica"];
|
|
|
|
|
+ self::checkArgs($args, $argsAvailable);
|
|
|
$args = array_map('trim', $args);
|
|
$args = array_map('trim', $args);
|
|
|
|
|
|
|
|
$where = "";
|
|
$where = "";
|
|
@@ -263,35 +263,54 @@ class Teryt {
|
|
|
if (isset($SYMarr)) $return['SYM'] = $SYMarr[0];
|
|
if (isset($SYMarr)) $return['SYM'] = $SYMarr[0];
|
|
|
else throw new Exception("miejscowosc not found");
|
|
else throw new Exception("miejscowosc not found");
|
|
|
}
|
|
}
|
|
|
|
|
+ } elseif (isset($return['SYM'])) {
|
|
|
|
|
+ $query = "select count(*) from `" . self::ULIC_TABLE . "` where `SYM` = '{$return['SYM']}'";
|
|
|
|
|
+ if (DB::getPDO()->fetchValue($query)) throw new Exception(json_encode(['msg' => "missing required parameter - ulica", 'sql' => $query]));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
return $return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static function getNames($args) {
|
|
|
|
|
|
|
+ public static function verify($args) {
|
|
|
$argsAvailable = ["WOJ", "POW", "GMI", "SYM", "SYM_UL"];
|
|
$argsAvailable = ["WOJ", "POW", "GMI", "SYM", "SYM_UL"];
|
|
|
self::checkArgs($args, $argsAvailable);
|
|
self::checkArgs($args, $argsAvailable);
|
|
|
|
|
|
|
|
if (!(isset($args['SYM']) && isset($args['SYM_UL']))) throw new Exception("Missing SYM or/and SYM_UL");
|
|
if (!(isset($args['SYM']) && isset($args['SYM_UL']))) throw new Exception("Missing SYM or/and SYM_UL");
|
|
|
- $query = "select WOJ, POW, GMI, CECHA, NAZWA_1, NAZWA_2 from `" . self::ULIC_TABLE . "` where SYM = " . DB::getPDO()->quote($args['SYM']) . " and SYM_UL = " . DB::getPDO()->quote($args['SYM_UL']);
|
|
|
|
|
- if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("ulica not found");
|
|
|
|
|
- if (count($result) > 1) throw new Exception("Found too many ulicas");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if ($args['SYM_UL']) {
|
|
|
|
|
+ $query = "select WOJ, POW, GMI, CECHA, NAZWA_1, NAZWA_2 from `" . self::ULIC_TABLE . "` where SYM = " . DB::getPDO()->quote($args['SYM']) . " and SYM_UL = " . DB::getPDO()->quote($args['SYM_UL']);
|
|
|
|
|
+ if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("ulica not found");
|
|
|
|
|
+ if (count($result) > 1) throw new Exception("Found too many ulicas");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $query = "select count(*) from `" . self::ULIC_TABLE . "` where `SYM` = '{$args['SYM']}'";
|
|
|
|
|
+ if (DB::getPDO()->fetchValue($query)) throw new Exception("Invalid SYM_UL");
|
|
|
|
|
+ $query = "select `WOJ`, `POW`, `GMI` from `" . self::SIMC_TABLE . "` where SYM = " . DB::getPDO()->quote($args['SYM']);
|
|
|
|
|
+ if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("miejscowosc not found");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $result[0];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getNames($args) {
|
|
|
|
|
+ $result = self::verify($args);
|
|
|
|
|
+
|
|
|
|
|
+ if ($args['SYM_UL']) {
|
|
|
|
|
+ $return['ulica_cecha'] = $result['CECHA'];
|
|
|
|
|
+ $return['ulica_nazwa_1'] = $result['NAZWA_1'];
|
|
|
|
|
+ $return['ulica_nazwa_2'] = $result['NAZWA_2'];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (isset($args['WOJ'])) {
|
|
if (isset($args['WOJ'])) {
|
|
|
- if ($args['WOJ'] != $result[0]['WOJ']) throw new Exception("Invalid WOJ");
|
|
|
|
|
- } else $args['WOJ'] = $result[0]['WOJ'];
|
|
|
|
|
|
|
+ if ($args['WOJ'] != $result['WOJ']) throw new Exception("Invalid WOJ");
|
|
|
|
|
+ } else $args['WOJ'] = $result['WOJ'];
|
|
|
|
|
|
|
|
if (isset($args['POW'])) {
|
|
if (isset($args['POW'])) {
|
|
|
- if ($args['POW'] != $result[0]['POW']) throw new Exception("Invalid POW");
|
|
|
|
|
- } else $args['POW'] = $result[0]['POW'];
|
|
|
|
|
|
|
+ if ($args['POW'] != $result['POW']) throw new Exception("Invalid POW");
|
|
|
|
|
+ } else $args['POW'] = $result['POW'];
|
|
|
|
|
|
|
|
if (isset($args['GMI'])) {
|
|
if (isset($args['GMI'])) {
|
|
|
- if ($args['GMI'] != $result[0]['GMI']) throw new Exception("Invalid POW");
|
|
|
|
|
- } else $args['GMI'] = $result[0]['GMI'];
|
|
|
|
|
-
|
|
|
|
|
- $return['ulica_cecha'] = $result[0]['CECHA'];
|
|
|
|
|
- $return['ulica_nazwa_1'] = $result[0]['NAZWA_1'];
|
|
|
|
|
- $return['ulica_nazwa_2'] = $result[0]['NAZWA_2'];
|
|
|
|
|
|
|
+ if ($args['GMI'] != $result['GMI']) throw new Exception("Invalid POW");
|
|
|
|
|
+ } else $args['GMI'] = $result['GMI'];
|
|
|
|
|
|
|
|
$query = "select NAZWA from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = 0";
|
|
$query = "select NAZWA from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = 0";
|
|
|
if (!($return['wojewodztwo'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
|
|
if (!($return['wojewodztwo'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
|