|
|
|
@@ -29,53 +29,100 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function authenticated() {
|
|
|
|
|
$campaignApiusers = PreordercampaignApiuserModel::search(["worker_id" => $this->me->id]);
|
|
|
|
|
|
|
|
|
|
if(!$campaignApiusers) {
|
|
|
|
|
$cau = new PreordercampaignApiuser();
|
|
|
|
|
$cau->preordercampaign_id = 1;
|
|
|
|
|
$campaignApiusers = [$cau];
|
|
|
|
|
}
|
|
|
|
|
if($this->me->is("preorderaddressreporting")) {
|
|
|
|
|
$preorder_networks = json_decode($this->me->getFlag("preorder_networks"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach($campaignApiusers as $campaignApiuser) {
|
|
|
|
|
$campaign = new Preordercampaign($campaignApiuser->preordercampaign_id);
|
|
|
|
|
if($campaign) {
|
|
|
|
|
foreach(PreordercampaignSalesclusterModel::search(['preordercampaign_id' => $campaign->id]) as $campain_scluster) {
|
|
|
|
|
if(!in_array($campain_scluster->salescluster_id, $this->filter_salescluster_ids)) {
|
|
|
|
|
$this->filter_salescluster_ids[] = $campain_scluster->salescluster_id;
|
|
|
|
|
if(!is_array($preorder_networks) || !count($preorder_networks)) {
|
|
|
|
|
return mfResponse::Forbidden();
|
|
|
|
|
}
|
|
|
|
|
//$this->filter_salescluster_ids = $preorder_networks;
|
|
|
|
|
|
|
|
|
|
foreach($preorder_networks as $network_id) {
|
|
|
|
|
$network = new Network($network_id);
|
|
|
|
|
$adb_netzgebiet_id = $network->adb_netzgebiet_id;
|
|
|
|
|
foreach(PreordercampaignSalesclusterModel::search(["salescluster_id" => $adb_netzgebiet_id]) as $campaign_scluster) {
|
|
|
|
|
if(!in_array($campaign_scluster->salescluster_id, $this->filter_salescluster_ids)) {
|
|
|
|
|
$this->filter_salescluster_ids[] = $campaign_scluster->salescluster_id;
|
|
|
|
|
}
|
|
|
|
|
$campaign = new Preordercampaign($campaign_scluster->preordercampaign_id);
|
|
|
|
|
if(!$campaign->id) continue;
|
|
|
|
|
$this->campaigns_by_scluster[$adb_netzgebiet_id] = $campaign_scluster->preordercampaign_id;
|
|
|
|
|
$this->campaigns[$campaign->id] = $campaign;
|
|
|
|
|
|
|
|
|
|
// get allowed preordertypes
|
|
|
|
|
if(is_array($campaign->types) && count($campaign->types)) {
|
|
|
|
|
foreach($campaign->types as $type) {
|
|
|
|
|
$this->allowed_preordertypes[] = $type->type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->campaigns_by_scluster[$campain_scluster->salescluster_id] = $campaign->id;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
$this->campaigns[$campaign->id] = $campaign;
|
|
|
|
|
|
|
|
|
|
// get allowed preordertypes
|
|
|
|
|
if(is_array($campaign->types) && count($campaign->types)) {
|
|
|
|
|
foreach($campaign->types as $type) {
|
|
|
|
|
$this->allowed_preordertypes[] = $type->type;
|
|
|
|
|
if($campaign->district_is_city == 1) {
|
|
|
|
|
$this->district_is_city = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($campaign->district_is_city == 1) {
|
|
|
|
|
$this->district_is_city = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($campaign->hausnummer_add_zusatz == 1) {
|
|
|
|
|
$this->hausnummer_add_zusatz = true;
|
|
|
|
|
|
|
|
|
|
if($campaign->hausnummer_add_zusatz == 1) {
|
|
|
|
|
$this->hausnummer_add_zusatz = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
|
|
|
|
|
$this->addAllowedOrigin($origin->hostname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
|
|
|
|
|
$this->addAllowedOrigin($origin->hostname);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$campaignApiusers = PreordercampaignApiuserModel::search(["worker_id" => $this->me->id]);
|
|
|
|
|
|
|
|
|
|
if(!$campaignApiusers) {
|
|
|
|
|
$cau = new PreordercampaignApiuser();
|
|
|
|
|
$cau->preordercampaign_id = 1;
|
|
|
|
|
$campaignApiusers = [$cau];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach($campaignApiusers as $campaignApiuser) {
|
|
|
|
|
$campaign = new Preordercampaign($campaignApiuser->preordercampaign_id);
|
|
|
|
|
if($campaign) {
|
|
|
|
|
foreach(PreordercampaignSalesclusterModel::search(['preordercampaign_id' => $campaign->id]) as $campaign_scluster) {
|
|
|
|
|
if(!in_array($campaign_scluster->salescluster_id, $this->filter_salescluster_ids)) {
|
|
|
|
|
$this->filter_salescluster_ids[] = $campaign_scluster->salescluster_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->campaigns_by_scluster[$campaign_scluster->salescluster_id] = $campaign->id;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
$this->campaigns[$campaign->id] = $campaign;
|
|
|
|
|
|
|
|
|
|
// get allowed preordertypes
|
|
|
|
|
if(is_array($campaign->types) && count($campaign->types)) {
|
|
|
|
|
foreach($campaign->types as $type) {
|
|
|
|
|
$this->allowed_preordertypes[] = $type->type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($campaign->district_is_city == 1) {
|
|
|
|
|
$this->district_is_city = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($campaign->hausnummer_add_zusatz == 1) {
|
|
|
|
|
$this->hausnummer_add_zusatz = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
|
|
|
|
|
$this->addAllowedOrigin($origin->hostname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//var_dump($this->allowed_preordertypes);exit;
|
|
|
|
|
//var_dump($this->filter_salescluster_ids, $this->campaigns_by_scluster);exit;
|
|
|
|
|
//var_dump($this->campaigns, $this->allowed_origins);exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->allowed_preordertypes = array_unique($this->allowed_preordertypes);
|
|
|
|
|
//var_dump($this->allowed_preordertypes);exit;
|
|
|
|
|
//var_dump($this->filter_salescluster_ids, $this->campaigns_by_scluster);exit;
|
|
|
|
|
//var_dump($this->campaigns, $this->allowed_origins);exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -316,135 +363,6 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
if($search == "%") {
|
|
|
|
|
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
|
|
|
|
@@ -472,7 +390,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = AddressDB::$wohneinheit_query;
|
|
|
|
|
$sql .= "\n WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer, LENGTH(tuer),tuer, zusatz, LENGTH(num), num";
|
|
|
|
|
$sql .= "\n WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer, LENGTH(`Wohneinheit`.tuer),`Wohneinheit`.tuer, zusatz, LENGTH(num), num";
|
|
|
|
|
|
|
|
|
|
//$sql = "SELECT * FROM view_wohneinheit WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer, LENGTH(tuer),tuer, zusatz, LENGTH(num), num";
|
|
|
|
|
$this->log->debug($sql);
|
|
|
|
@@ -539,7 +457,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmp_addresses[$address_key]['units'][] = [
|
|
|
|
|
$unit_data = [
|
|
|
|
|
'oaid' => $data->wohneinheit_oaid,
|
|
|
|
|
'num' => (int)$data->num,
|
|
|
|
|
'block' => $data->block,
|
|
|
|
@@ -548,6 +466,20 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
'tuer' => $data->tuer,
|
|
|
|
|
'zusatz' => $data->zusatz,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if($this->me->is("preorderaddressreporting")) {
|
|
|
|
|
if($data->partner_company) {
|
|
|
|
|
$unit_data["ordered"] = true;
|
|
|
|
|
$unit_data["orderType"] = $data->order_type;
|
|
|
|
|
$unit_data["ispName"] = $data->partner_company;
|
|
|
|
|
} else {
|
|
|
|
|
$unit_data["ordered"] = false;
|
|
|
|
|
$unit_data["orderType"] = null;
|
|
|
|
|
$unit_data["ispName"] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmp_addresses[$address_key]['units'][] = $unit_data;
|
|
|
|
|
$tmp_addresses[$address_key]['building_unit_count']++;
|
|
|
|
|
//if($data->hausnummer_oaid == "AT-8940-30400d5c") var_dump($data);
|
|
|
|
|
}
|
|
|
|
@@ -637,6 +569,11 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
foreach($counted_addresses as $ta) {
|
|
|
|
|
foreach($ta['units'] as $u) {
|
|
|
|
|
$new_address = [];
|
|
|
|
|
if($this->me->is("preorderaddressreporting")) {
|
|
|
|
|
$new_address['ordered'] = $u['ordered'];
|
|
|
|
|
$new_address['orderType'] = $u['orderType'];
|
|
|
|
|
$new_address['ispName'] = $u['ispName'];
|
|
|
|
|
}
|
|
|
|
|
$new_address['oaid'] = $u['oaid'];
|
|
|
|
|
$new_address['building_oaid'] = $ta['oaid'];
|
|
|
|
|
$new_address['cluster_id'] = $ta['cluster_id'];
|
|
|
|
@@ -727,7 +664,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
//var_dump($this->filter_salescluster_ids);exit;
|
|
|
|
|
|
|
|
|
|
$sql = AddressDB::$wohneinheit_query;
|
|
|
|
|
$sql .= "\n WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
|
|
|
|
|
$sql .= "\n WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, `Wohneinheit`.block, `Wohneinheit`.stiege, `Wohneinheit`.stock, LENGTH(num), num, LENGTH(`Wohneinheit`.tuer), `Wohneinheit`.tuer";
|
|
|
|
|
|
|
|
|
|
//$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
|
|
|
|
|
$this->log->debug($sql);
|
|
|
|
@@ -786,9 +723,10 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
} else {
|
|
|
|
|
unset($tmp_addresses[$address_key]['municipality']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmp_addresses[$address_key]['units'][] = [
|
|
|
|
|
$unit_data = [
|
|
|
|
|
'oaid' => $data->wohneinheit_oaid,
|
|
|
|
|
'num' => (int)$data->num,
|
|
|
|
|
'block' => $data->block,
|
|
|
|
@@ -796,9 +734,22 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
'stock' => $data->stock,
|
|
|
|
|
'tuer' => $data->tuer,
|
|
|
|
|
'zusatz' => $data->zusatz,
|
|
|
|
|
];
|
|
|
|
|
];
|
|
|
|
|
if($this->me->is("preorderaddressreporting")) {
|
|
|
|
|
if($data->partner_company) {
|
|
|
|
|
$unit_data["ordered"] = true;
|
|
|
|
|
$unit_data["orderType"] = $data->order_type;
|
|
|
|
|
$unit_data["ispName"] = $data->partner_company;
|
|
|
|
|
} else {
|
|
|
|
|
$unit_data["ordered"] = false;
|
|
|
|
|
$unit_data["orderType"] = null;
|
|
|
|
|
$unit_data["ispName"] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$tmp_addresses[$address_key]['units'][] = $unit_data;
|
|
|
|
|
$tmp_addresses[$address_key]['building_unit_count']++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if($format == "tree") {
|
|
|
|
|
/*foreach($tmp_addresses as $ta) {
|
|
|
|
@@ -809,6 +760,11 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
|
|
|
|
foreach($tmp_addresses as $ta) {
|
|
|
|
|
foreach($ta['units'] as $u) {
|
|
|
|
|
$new_address = [];
|
|
|
|
|
if($this->me->is("preorderaddressreporting")) {
|
|
|
|
|
$new_address['ordered'] = $u['ordered'];
|
|
|
|
|
$new_address['orderType'] = $u['orderType'];
|
|
|
|
|
$new_address['ispName'] = $u['ispName'];
|
|
|
|
|
}
|
|
|
|
|
$new_address['oaid'] = $u['oaid'];
|
|
|
|
|
$new_address['building_oaid'] = $ta['oaid'];
|
|
|
|
|
$new_address['cluster_id'] = $ta['cluster_id'];
|
|
|
|
|