Teryt.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. class Teryt {
  3. const SIMC_TABLE = "TERYT_SIMC";
  4. const TERC_TABLE = "TERYT_TERC";
  5. const ULIC_TABLE = "TERYT_ULIC";
  6. const PNA_TABLE = "PNA";
  7. private static function checkArgs($args, $argsAvailable) {
  8. if ($args == null) throw new Exception("Missing argument");
  9. if (!is_array($args)) throw new Exception("Armument must be an array");
  10. if (!count($args)) throw new Exception("Argument list cannot be empty");
  11. foreach ($args as $arg => $value) {
  12. if (!in_array($arg, $argsAvailable)) throw new Exception("Unknown argument {$arg}");
  13. }
  14. }
  15. private static function throwException($msg, $sql) {
  16. throw new Exception(json_encode(['msg' => $msg, 'sql' => $sql]));
  17. }
  18. public static function search($args = null) {
  19. $argsAvailable = ["kodPocztowy", "wojewodztwo", "powiat", "gmina", "miejscowosc", "ulica"];
  20. self::checkArgs($args, $argsAvailable);
  21. $args = array_map('trim', $args);
  22. $where = "";
  23. $return = null;
  24. if (isset($args['kodPocztowy'])) {
  25. $args['kodPocztowy'] = str_replace(' ', '', $args['kodPocztowy']);
  26. if (isset($args['miejscowosc'])) $whereKod = "and miejscowosc = " . DB::getPDO()->quote($args['miejscowosc']);
  27. else $whereKod = "";
  28. $query = "select wojewodztwo, powiat, gmina from `" . self::PNA_TABLE . "` where kodPocztowy = " . DB::getPDO()->quote($args['kodPocztowy']) . " $whereKod and nazwa = '' group by wojewodztwo, powiat, gmina";
  29. $result = DB::getPDO()->fetchall($query);
  30. if (count($result) == 1) {
  31. $kodPocztowy['wojewodztwo'] = $result[0]['wojewodztwo'];
  32. $kodPocztowy['powiat'] = $result[0]['powiat'];
  33. $kodPocztowy['gmina'] = $result[0]['gmina'];
  34. }
  35. }
  36. try {
  37. if (isset($args['wojewodztwo'])) {
  38. $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($args['wojewodztwo']) . " and POW is null";
  39. if (!($return['WOJ'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
  40. $where = "and WOJ = '{$return['WOJ']}'";
  41. }
  42. if (isset($args['powiat'])) {
  43. $args['powiat'] = preg_replace('/^M. /i', '', $args['powiat']);
  44. $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}";
  45. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
  46. if (count($result) > 1) throw new Exception("Found too many powiats");
  47. $return['WOJ'] = $result[0]['WOJ'];
  48. $return['POW'] = $result[0]['POW'];
  49. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}'";
  50. }
  51. if (isset($args['gmina'])) {
  52. $args['gmina'] = preg_replace('/^M. /i', '', $args['gmina']);
  53. $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";
  54. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("gmina not found");
  55. if (count($result) == 1) {// throw new Exception("Found too many gminas ({$query})");
  56. $return['WOJ'] = $result[0]['WOJ'];
  57. $return['POW'] = $result[0]['POW'];
  58. $return['GMI'] = $result[0]['GMI'];
  59. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and GMI = '{$return['GMI']}'";
  60. }
  61. }
  62. if (!isset($return['WOJ'])) throw new Exception("Try with data from kodPocztowy");
  63. if (isset($args['miejscowosc'])) {
  64. $args['miejscowosc'] = preg_replace('/^M. /i', '', $args['miejscowosc']);
  65. $args['miejscowosc'] = str_replace(' - ', '-', $args['miejscowosc']);
  66. $args['miejscowosc'] = str_replace(' ', '%', $args['miejscowosc']);
  67. $query = "select WOJ, POW, GMI, SYM from `" . self::SIMC_TABLE . "` where NAZWA like " . DB::getPDO()->quote($args['miejscowosc']) . " {$where}";
  68. if (!($result = DB::getPDO()->fetchall($query))) self::throwException("miejscowosc not found", $query);
  69. $return['WOJ'] = $result[0]['WOJ'];
  70. $return['POW'] = $result[0]['POW'];
  71. $return['GMI'] = $result[0]['GMI'];
  72. if (count($result) > 1) {//self::throwException("Found too many miejscowoscs", $query);
  73. $SYMarr = array_map(function ($a) {return $a['SYM'];}, $result);
  74. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and ((RODZ_GMI<8 and GMI = '{$return['GMI']}' and SYM in (" . implode(",", $SYMarr) . ")) or RODZ_GMI>=8)";
  75. } else {
  76. $return['SYM'] = $result[0]['SYM'];
  77. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and ((RODZ_GMI<8 and GMI = '{$return['GMI']}' and SYM = '{$return['SYM']}') or RODZ_GMI>=8)";
  78. }
  79. }
  80. } catch (Exception $e) {
  81. if (!isset($kodPocztowy)) throw new Exception($e->getMessage());
  82. $query = "select WOJ from `" . self::TERC_TABLE . "` where NAZWA = " . DB::getPDO()->quote($kodPocztowy['wojewodztwo']) . " and POW is null";
  83. if (!($return['WOJ'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
  84. $where = "and WOJ = '{$return['WOJ']}'";
  85. $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}";
  86. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
  87. if (count($result) > 1) throw new Exception("Found too many powiats");
  88. $return['WOJ'] = $result[0]['WOJ'];
  89. $return['POW'] = $result[0]['POW'];
  90. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}'";
  91. $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";
  92. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("gmina not found");
  93. if (count($result) == 1) {
  94. $return['WOJ'] = $result[0]['WOJ'];
  95. $return['POW'] = $result[0]['POW'];
  96. $return['GMI'] = $result[0]['GMI'];
  97. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and GMI = '{$return['GMI']}'";
  98. }
  99. if (isset($args['miejscowosc'])) {
  100. $args['miejscowosc'] = preg_replace('/^M. /i', '', $args['miejscowosc']);
  101. $args['miejscowosc'] = str_replace(' - ', '-', $args['miejscowosc']);
  102. $args['miejscowosc'] = str_replace(' ', '%', $args['miejscowosc']);
  103. $query = "select WOJ, POW, GMI, SYM from `" . self::SIMC_TABLE . "` where NAZWA like " . DB::getPDO()->quote($args['miejscowosc']) . " {$where}";
  104. if (!($result = DB::getPDO()->fetchall($query))) self::throwException("miejscowosc not found", $query);
  105. $return['WOJ'] = $result[0]['WOJ'];
  106. $return['POW'] = $result[0]['POW'];
  107. $return['GMI'] = $result[0]['GMI'];
  108. if (count($result) > 1) {//self::throwException("Found too many miejscowoscs", $query);
  109. $SYMarr = array_map(function ($a) {return $a['SYM'];}, $result);
  110. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and ((RODZ_GMI<8 and GMI = '{$return['GMI']}' and SYM in (" . implode(",", $SYMarr) . ")) or RODZ_GMI>=8)";
  111. } else {
  112. $return['SYM'] = $result[0]['SYM'];
  113. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and ((RODZ_GMI<8 and GMI = '{$return['GMI']}' and SYM = '{$return['SYM']}') or RODZ_GMI>=8)";
  114. }
  115. }
  116. }
  117. $ulicaNeeded = DB::getPDO()->fetchValue("select count(*) from `" . self::ULIC_TABLE . "` where 1 = 1 {$where}") > 0 ? true : false;
  118. if (isset($args['ulica'])) {
  119. $args['ulica'] = trim(preg_replace('/osiedle/i', 'os.', $args['ulica']));
  120. $args['ulica'] = trim(preg_replace('/aleja/i', 'al.', $args['ulica']));
  121. $args['ulica'] = trim(preg_replace('/plac/i', 'pl.', $args['ulica']));
  122. $args['ulica'] = trim(preg_replace('/kardynała/i', 'kard', $args['ulica']));
  123. $args['ulica'] = trim(preg_replace('/\(.*\)/', '', $args['ulica']));
  124. $args['ulica'] = trim(preg_replace('/-go/i', '', $args['ulica']));
  125. $args['ulica'] = trim(preg_replace('/\.$/', '%', $args['ulica']));
  126. $search = [' ', '..'];
  127. $replace = ['%', '.'];
  128. $args['ulica'] = str_replace($search, $replace, $args['ulica']);
  129. $ulica = DB::getPDO()->quote("{$args['ulica']}");
  130. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica} " .
  131. "or concat(CECHA, NAZWA_1) like {$ulica} or concat(CECHA, NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  132. $result = DB::getPDO()->fetchall($query);
  133. if (!$result) {
  134. $ulica = DB::getPDO()->quote("ul. {$args['ulica']}");
  135. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica}) " .
  136. "{$where} group by WOJ, POW, SYM_UL";
  137. $result = DB::getPDO()->fetchall($query);
  138. }
  139. if (!$result) {
  140. $ulica = DB::getPDO()->quote("ul. {$args['ulica']}%");
  141. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica} " .
  142. "or concat(CECHA, NAZWA_1) like {$ulica} or concat(CECHA, NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  143. $result = DB::getPDO()->fetchall($query);
  144. }
  145. if (!$result) {
  146. $ulica = DB::getPDO()->quote("{$args['ulica']}%");
  147. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica} " .
  148. "or concat(CECHA, NAZWA_1) like {$ulica} or concat(CECHA, NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  149. $result = DB::getPDO()->fetchall($query);
  150. }
  151. if (!$result) {
  152. $ulica = DB::getPDO()->quote("{$args['ulica']}%");
  153. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (NAZWA_1 like {$ulica} or concat(NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  154. $result = DB::getPDO()->fetchall($query);
  155. }
  156. if (!$result) {
  157. $ulica = DB::getPDO()->quote("%{$args['ulica']}");
  158. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (NAZWA_1 like {$ulica} or concat(NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  159. $result = DB::getPDO()->fetchall($query);
  160. }
  161. if (!$result) {
  162. $ulica = DB::getPDO()->quote("%{$args['ulica']}%");
  163. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (NAZWA_1 like {$ulica} or concat(NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  164. $result = DB::getPDO()->fetchall($query);
  165. }
  166. if (!$result) {
  167. preg_match('/^([^\.]*)\.([^\.]*)\.(.*)$/', $args['ulica'], $matches);
  168. if (count($matches) == 4) {
  169. $ulica = DB::getPDO()->quote(trim($matches[1]) . ". " . trim($matches[2]) . "% " . trim($matches[3]) . "%");
  170. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} " .
  171. "or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  172. $result = DB::getPDO()->fetchall($query);
  173. if (!$result) {
  174. $ulica = DB::getPDO()->quote(trim($matches[1]) . ". " . trim($matches[3]) . "%");
  175. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where concat(CECHA, ' ', NAZWA_1) like {$ulica} {$where} group by WOJ, POW, SYM_UL";
  176. $result = DB::getPDO()->fetchall($query);
  177. }
  178. if (!$result) {
  179. $ulica = DB::getPDO()->quote("ul. " . trim($matches[3]) . "%");
  180. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where concat(CECHA, ' ', NAZWA_1) like {$ulica} {$where} group by WOJ, POW, SYM_UL";
  181. $result = DB::getPDO()->fetchall($query);
  182. }
  183. }
  184. }
  185. if (!$result) {
  186. preg_match('/^([^\.]*)\.(.*)$/', $args['ulica'], $matches);
  187. if (count($matches) == 3) {
  188. $ulica = DB::getPDO()->quote("ul. " . trim($matches[1]) . "% " . trim($matches[2]) . "%");
  189. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where (concat(CECHA, ' ', NAZWA_1) like {$ulica} " .
  190. "or concat(CECHA, ' ', NAZWA_2, ' ', NAZWA_1) like {$ulica}) {$where} group by WOJ, POW, SYM_UL";
  191. $result = DB::getPDO()->fetchall($query);
  192. if (!$result) {
  193. $ulica = DB::getPDO()->quote("ul. " . trim($matches[2]) . "%");
  194. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where concat(CECHA, ' ', NAZWA_1) like {$ulica} {$where} group by WOJ, POW, SYM_UL";
  195. $result = DB::getPDO()->fetchall($query);
  196. }
  197. if (!$result) {
  198. $ulica = DB::getPDO()->quote(trim($matches[1]) . ". " . trim($matches[2]) . "%");
  199. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where concat(CECHA, ' ', NAZWA_1) like {$ulica} {$where} group by WOJ, POW, SYM_UL";
  200. $result = DB::getPDO()->fetchall($query);
  201. }
  202. if (!$result) {
  203. $ulica = DB::getPDO()->quote(trim($matches[1]) . ". %" . trim($matches[2]));
  204. $query = "select WOJ, POW, GMI, SYM, SYM_UL from `" . self::ULIC_TABLE . "` where concat(CECHA, ' ', NAZWA_1) like {$ulica} {$where} group by WOJ, POW, SYM_UL";
  205. $result = DB::getPDO()->fetchall($query);
  206. }
  207. }
  208. }
  209. if (!$result) {
  210. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and GMI = '{$return['GMI']}'";
  211. $query = "select WOJ, POW, GMI, SYM from `" . self::SIMC_TABLE . "` where NAZWA like " . DB::getPDO()->quote($args['ulica']) . " {$where}";
  212. $result = DB::getPDO()->fetchall($query);
  213. if (count($result) == 1) $ulicaNeeded = false;
  214. }
  215. if (!$result) {
  216. if (isset($return['SYM'])) $where2 = "and SYM = '{$return['SYM']}'";
  217. else $where2 = "";
  218. $where = "and WOJ = '{$return['WOJ']}' and POW = '{$return['POW']}' and ((RODZ_GMI<8 and GMI = '{$return['GMI']}' {$where2}) or RODZ_GMI>=8)";
  219. $query = "select count(*) from `" . self::ULIC_TABLE . "` where 1 = 1 {$where}";
  220. if ($liczbaUlic = DB::getPDO()->fetchValue($query)) throw new Exception(json_encode(['msg' => "ulica not found", 'sql' => $query]));
  221. } else {
  222. if (count($result) > 1) self::throwException("Found too many ulicas", $query);
  223. $return['WOJ'] = $result[0]['WOJ'];
  224. $return['POW'] = $result[0]['POW'];
  225. $return['GMI'] = $result[0]['GMI'];
  226. $return['SYM'] = $result[0]['SYM'];
  227. if (isset($result[0]['SYM_UL'])) $return['SYM_UL'] = $result[0]['SYM_UL'];
  228. elseif ($ulicaNeeded) throw new Exception("Ulica not found, but needed");
  229. }
  230. if (!isset($return['SYM'])) {
  231. if (isset($SYMarr)) $return['SYM'] = $SYMarr[0];
  232. else throw new Exception("miejscowosc not found");
  233. }
  234. } elseif (isset($return['SYM'])) {
  235. $query = "select count(*) from `" . self::ULIC_TABLE . "` where `SYM` = '{$return['SYM']}'";
  236. if (DB::getPDO()->fetchValue($query)) throw new Exception(json_encode(['msg' => "missing required parameter - ulica", 'sql' => $query]));
  237. }
  238. return $return;
  239. }
  240. public static function verify($args) {
  241. $argsAvailable = ["WOJ", "POW", "GMI", "SYM", "SYM_UL"];
  242. self::checkArgs($args, $argsAvailable);
  243. if (!(isset($args['SYM']) && isset($args['SYM_UL']))) throw new Exception("Missing SYM or/and SYM_UL");
  244. if ($args['SYM_UL']) {
  245. $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']);
  246. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("ulica not found");
  247. if (count($result) > 1) throw new Exception("Found too many ulicas");
  248. } else {
  249. $query = "select count(*) from `" . self::ULIC_TABLE . "` where `SYM` = '{$args['SYM']}'";
  250. if (DB::getPDO()->fetchValue($query)) throw new Exception("Invalid SYM_UL");
  251. $query = "select `WOJ`, `POW`, `GMI` from `" . self::SIMC_TABLE . "` where SYM = " . DB::getPDO()->quote($args['SYM']);
  252. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("miejscowosc not found");
  253. }
  254. return $result[0];
  255. }
  256. public static function getNames($args) {
  257. $result = self::verify($args);
  258. if ($args['SYM_UL']) {
  259. $return_ul['ulica_cecha'] = $result['CECHA'];
  260. $return_ul['ulica_nazwa_1'] = $result['NAZWA_1'];
  261. $return_ul['ulica_nazwa_2'] = $result['NAZWA_2'];
  262. } else $return_ul = [];
  263. if (isset($args['WOJ'])) {
  264. if ($args['WOJ'] != $result['WOJ']) throw new Exception("Invalid WOJ");
  265. } else $args['WOJ'] = $result['WOJ'];
  266. if (isset($args['POW'])) {
  267. if ($args['POW'] != $result['POW']) throw new Exception("Invalid POW");
  268. } else $args['POW'] = $result['POW'];
  269. if (isset($args['GMI'])) {
  270. if ($args['GMI'] != $result['GMI']) throw new Exception("Invalid POW");
  271. } else $args['GMI'] = $result['GMI'];
  272. $query = "select NAZWA from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW is null";
  273. if (!($return['wojewodztwo'] = DB::getPDO()->fetchValue($query))) throw new Exception("wojewodztwo not found");
  274. $query = "select NAZWA, NAZWA_DOD from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = '{$args['POW']}' and GMI is null";
  275. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("powiat not found");
  276. if (count($result) > 1) throw new Exception("Found too many powiats");
  277. $return['powiat'] = $result[0]['NAZWA'];
  278. $return['powiat_rodzaj'] = $result[0]['NAZWA_DOD'];
  279. $query = "select NAZWA, NAZWA_DOD from `" . self::TERC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = '{$args['POW']}' and GMI = '{$args['GMI']}' group by WOJ, POW, GMI, NAZWA";
  280. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("gmina not found");
  281. if (count($result) > 1) throw new Exception("Found too many gminas");
  282. $return['gmina'] = $result[0]['NAZWA'];
  283. $return['gmina_rodzaj'] = $result[0]['NAZWA_DOD'];
  284. $query = "select NAZWA from `" . self::SIMC_TABLE . "` where WOJ = '{$args['WOJ']}' and POW = '{$args['POW']}' and GMI = '{$args['GMI']}' and SYM = '{$args['SYM']}'";
  285. if (!($result = DB::getPDO()->fetchall($query))) throw new Exception("miejscowosc not found");
  286. if (count($result) > 1) throw new Exception("Found too many miejscowoscs");
  287. $return['miejscowosc'] = $result[0]['NAZWA'];
  288. return array_merge($return, $return_ul);
  289. }
  290. }