|
|
@@ -7,14 +7,14 @@ class Teryt {
|
|
|
const ULIC_TABLE = "TERYT_ULIC";
|
|
|
const PNA_TABLE = "PNA";
|
|
|
|
|
|
- private static function checkArgs($args, $argsAvailable) {
|
|
|
+ private static function checkArgs($args) {
|
|
|
+ $argsAvailable = ["kodPocztowy", "wojewodztwo", "powiat", "gmina", "miejscowosc", "ulica"];
|
|
|
if ($args == null) throw new Exception("Missing argument");
|
|
|
if (!is_array($args)) throw new Exception("Armument must be an array");
|
|
|
if (!count($args)) throw new Exception("Argument list cannot be empty");
|
|
|
- if(isset($args))
|
|
|
- foreach ($args as $arg => $value) {
|
|
|
- if (!in_array($arg, $argsAvailable)) throw new Exception("Unknown argument {$arg}");
|
|
|
- }
|
|
|
+ foreach ($args as $arg => $value) {
|
|
|
+ if (!in_array($arg, $argsAvailable)) throw new Exception("Unknown argument {$arg}");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static function throwException($msg, $sql) {
|
|
|
@@ -22,9 +22,8 @@ class Teryt {
|
|
|
}
|
|
|
|
|
|
public static function search($args = null) {
|
|
|
- $argsAvailable = ["kodPocztowy", "wojewodztwo", "powiat", "gmina", "miejscowosc", "ulica"];
|
|
|
- self::checkArgs($args, $argsAvailable);
|
|
|
- foreach ($args as &$arg) $arg = trim($arg);
|
|
|
+ self::checkArgs($args);
|
|
|
+ $args = array_map('trim', $args);
|
|
|
|
|
|
$where = "";
|
|
|
$return = null;
|
|
|
@@ -252,7 +251,7 @@ class Teryt {
|
|
|
$query = "select count(*) from `" . self::ULIC_TABLE . "` where 1 = 1 {$where}";
|
|
|
if ($liczbaUlic = DB::getPDO()->fetchValue($query)) throw new Exception(json_encode(['msg' => "ulica not found", 'sql' => $query]));
|
|
|
} else {
|
|
|
- if (count($result) > 1) throw new Exception(json_encode(['msg' => "Found too many ulicas", 'sql' => $query]));
|
|
|
+ if (count($result) > 1) self::throwException("Found too many ulicas", $query);
|
|
|
$return['WOJ'] = $result[0]['WOJ'];
|
|
|
$return['POW'] = $result[0]['POW'];
|
|
|
$return['GMI'] = $result[0]['GMI'];
|