|
|
@@ -43,14 +43,14 @@ class Teryt {
|
|
|
|
|
|
try {
|
|
|
if (isset($args['wojewodztwo'])) {
|
|
|
- $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($args['wojewodztwo']) . " and POW = 0";
|
|
|
+ $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($args['wojewodztwo']) . " and POW is null";
|
|
|
if (!($return['WOJ'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
|
|
|
$where = "and WOJ = '{$return['WOJ']}'";
|
|
|
}
|
|
|
|
|
|
if (isset($args['powiat'])) {
|
|
|
$args['powiat'] = preg_replace('/^M. /i', '', $args['powiat']);
|
|
|
- $query = "select WOJ, POW from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($args['powiat']) . " and POW > 0 and GMI = 0 {$where}";
|
|
|
+ $query = "select WOJ, POW from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($args['powiat']) . " and POW is not null and GMI is null {$where}";
|
|
|
if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
|
|
|
if (count($result) > 1) throw new Exception("Found too many powiats");
|
|
|
$return['WOJ'] = $result[0]['WOJ'];
|
|
|
@@ -60,7 +60,7 @@ class Teryt {
|
|
|
|
|
|
if (isset($args['gmina'])) {
|
|
|
$args['gmina'] = preg_replace('/^M. /i', '', $args['gmina']);
|
|
|
- $query = "select WOJ, POW, GMI from `" . self::TERC_TABLE. "` where NAZWA = " . DB::getPDO()->quote($args['gmina']) . " and GMI > 0 {$where} group by WOJ, POW, GMI";
|
|
|
+ $query = "select WOJ, POW, GMI from `" . self::TERC_TABLE. "` where NAZWA = " . DB::getPDO()->quote($args['gmina']) . " and GMI is not null {$where} group by WOJ, POW, GMI";
|
|
|
if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("gmina not found");
|
|
|
if (count($result) == 1) {// throw new Exception("Found too many gminas ({$query})");
|
|
|
$return['WOJ'] = $result[0]['WOJ'];
|
|
|
@@ -92,18 +92,19 @@ class Teryt {
|
|
|
} catch (Exception $e) {
|
|
|
if (!isset($kodPocztowy)) throw new Exception($e->getMessage());
|
|
|
|
|
|
- $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['wojewodztwo']) . " and POW = 0";
|
|
|
+ $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['wojewodztwo']) . " and POW is null";
|
|
|
if (!($return['WOJ'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
|
|
|
$where = "and WOJ = '{$return['WOJ']}'";
|
|
|
|
|
|
- $query = "select WOJ, POW from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['powiat']) . " and POW > 0 and GMI = 0 {$where}";
|
|
|
+ $query = "select WOJ, POW from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['powiat']) . " and POW is not null and GMI is null {$where}";
|
|
|
if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
|
|
|
if (count($result) > 1) throw new Exception("Found too many powiats");
|
|
|
$return['WOJ'] = $result[0]['WOJ'];
|
|
|
$return['POW'] = $result[0]['POW'];
|
|
|
$where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}'";
|
|
|
|
|
|
- $query = "select WOJ, POW, GMI from `" . self::TERC_TABLE. "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['gmina']) . " and GMI > 0 {$where} group by WOJ, POW, GMI";
|
|
|
+ $query = "select WOJ, POW, GMI from `" . self::TERC_TABLE. "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['gmina']) . " and GMI is not null {$where} group by WOJ, POW, GMI";
|
|
|
+echo $query . "\n";
|
|
|
if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("gmina not found");
|
|
|
if (count($result) == 1) {
|
|
|
$return['WOJ'] = $result[0]['WOJ'];
|
|
|
@@ -316,10 +317,10 @@ class Teryt {
|
|
|
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 is null";
|
|
|
if (!($return['wojewodztwo'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
|
|
|
|
|
|
- $query = "select NAZWA, NAZWA_DOD from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = '{$args['POW']}' and GMI = 0";
|
|
|
+ $query = "select NAZWA, NAZWA_DOD from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = '{$args['POW']}' and GMI is null";
|
|
|
if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
|
|
|
if (count($result) > 1) throw new Exception("Found too many powiats");
|
|
|
$return['powiat'] = $result[0]['NAZWA'];
|