diff --git a/application/Api/v1/AddressdbApicontroller.php b/application/Api/v1/AddressdbApicontroller.php index 9cec22a8c..8815d5a44 100644 --- a/application/Api/v1/AddressdbApicontroller.php +++ b/application/Api/v1/AddressdbApicontroller.php @@ -310,6 +310,138 @@ class AddressdbApicontroller extends mfBaseApicontroller { return mfResponse::BadRequest(['message' => "Search string cannot be empty"]); } + /* + * try direct search + */ + /*$m = []; + if(preg_match('/^([^,]+)\s+(\d+\w+),\s*(\d+),?\s*(.+)$/', $search, $m)) { + if($m[1] && $m[2] && $m[3] && $m[4]) { + $dsearch['Strasse.name'] = $this->db()->escape(trim($m[1])); + $dsearch['Hausnummer.hausnummer'] = $this->db()->escape(trim($m[2])); + $dsearch['Plz.plz'] = $this->db()->escape(trim($m[3])); + if($this->district_is_city) { + $dsearch['Ortschaft.name'] = $this->db()->escape(trim($m[4])); + } else { + $dsearch['Gemeinde.name'] = $this->db()->escape(trim($m[4])); + } + + $where = "1=1"; + if(count($this->filter_salescluster_ids)) { + $where .= " AND netzgebiet_id IN (".implode(",", $this->filter_salescluster_ids).")"; + } + foreach($dsearch as $field => $value) { + $where .= " AND $field = '$value'"; + } + + $sql = AddressDB::$wohneinheit_query; + $sql .= "\n WHERE $where"; + $this->log->debug($sql); + + $res = $this->db()->query($sql); + + if($this->db()->num_rows($res)) { + $address = []; + $units = []; + $hausnummer_id = false; + while($data = $this->db()->fetch_object($res)) { + if(!$hausnummer_id) { + $hausnummer_id = $data->hausnummer_id; + + // get allowed preorderTypes + $ptypes = []; + if($data->freigabe) { + $freigaben = json_decode($data->freigabe); + if(is_array($freigaben) && count($freigaben)) { + foreach($freigaben as $freigabe) { + if(in_array($freigabe, $this->allowed_preordertypes)) { + $ptypes[] = $freigabe; + } + } + } + } + + $housenumber = $data->hausnummer; + if($this->hausnummer_add_zusatz) { + if($data->zusatz) { + $housenumber .= " (".$data->zusatz.")"; + } + } + + $address = [ + 'oaid' => $data->hausnummer_oaid, + 'cluster_id' => $data->netzgebiet_extref, + 'zip' => $data->plz, + 'city' => $data->gemeinde, + "municipality" => "", + 'district' => $data->ortschaft, + 'street' => $data->strasse, + 'housenumber' => $housenumber, + 'lot_number' => $data->grund_nr, + 'building_unit_count' => 0, + 'gps_lat' => ($data->gps_lat) ? (float)$data->gps_lat : null, + 'gps_long' => ($data->gps_long) ? (float)$data->gps_long : null, + 'rollout_year' => ($data->rollout) ? (int)$data->rollout : null, + 'rollout_info' => $data->rollout_info, + 'preorderTypes' => $ptypes, + 'units' => [] + ]; + if($this->district_is_city) { + $address['city'] = $data->ortschaft; + $address['municipality'] = $data->gemeinde; + } else { + unset($address['municipality']); + } + } + if($hausnummer_id && $hausnummer_id != $data->hausnummer_id) { + $address = []; + break; + } + + $units[] = [ + 'oaid' => $data->wohneinheit_oaid, + 'num' => (int)$data->num, + 'block' => $data->block, + 'stiege' => $data->stiege, + 'stock' => $data->stock, + 'tuer' => $data->tuer, + 'zusatz' => $data->zusatz, + ]; + } + //var_dump($address, $units);exit; + $new_addresses = []; + if($address) { + if($format == "tree") { + $new_address = $address; + $new_address['units'] = $units; + $new_addresses[] = $address; + } else { + foreach($units as $unit) { + $new_address = $address; + unset($new_address['units']); + $new_address['building_unit_count'] = count($units); + $new_address['num'] = $unit['num']; + $new_address['block'] = $unit['block']; + $new_address['stiege'] = $unit['stiege']; + $new_address['stock'] = $unit['stock']; + $new_address['tuer'] = $unit['tuer']; + $new_address['zusatz'] = $unit['zusatz']; + $new_addresses[] = $new_address; + } + } + + return mfResponse::Ok(['addresses' => $new_addresses]); + + } + + } + } + + + }*/ + + /* + * do normal search + */ $search_parts = []; $search = str_replace(",", "", $search); $tmp_search_parts = explode(" ", $search); @@ -452,24 +584,22 @@ class AddressdbApicontroller extends mfBaseApicontroller { } unset($temp_add['sort_key']); - //echo "$p $count
\n"; if($includes_int && (($count + 1) - count($search_parts) ) < 1) { - - /*if($temp_add['oaid'] == "AT-8940-30400d5c") { - echo $temp_add['sort_key']." - count $count; count(search_parts) ".count($search_parts); - //echo "blah";exit; - exit; - }*/ continue; } //var_dump(count($search_parts), $count, $count_parts, $temp_add); + /*if($temp_add['oaid'] == "AT-8954-d6c41665") { + echo $temp_add['sort_key'].": AT-8954-d6c41665: count $count; uniq_parts_count $uniq_parts_count; count_parts $count_parts; search_parts ".count($search_parts)."

\n"; + //var_dump(); + //exit; + }*/ + if($count_parts == count($search_parts)) { - $count = 50; + $count += 50; } - //var_dump($count);exit; - //var_dump($uniq_parts_count, $uniq_parts_found);exit; + if($uniq_parts_count <= count($uniq_parts_found)) { if(!array_key_exists($count, $sorted_addresses)) { $sorted_addresses[$count] = [];