WIP Preorderconstruction API
This commit is contained in:
@@ -8,7 +8,7 @@ class PreorderconstructionApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
protected function authenticated() {
|
||||
if($this->me->username != "fronk") {
|
||||
if($this->me->username != "preorder-construction-api-slc") {
|
||||
return \mfResponse::Forbidden();
|
||||
}
|
||||
}
|
||||
@@ -20,21 +20,27 @@ class PreorderconstructionApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::Forbidden();
|
||||
}*/
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
$adb_network_ids = [];
|
||||
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if(!$user_network_ids) {
|
||||
return mfResponse::Ok([]);
|
||||
}
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
$adb_network_ids = [];
|
||||
foreach($my_networks as $network) {
|
||||
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
||||
$netzgebiet_ids[] = $network->id;
|
||||
$adb_network_ids[] = $network->adb_netzgebiet_id;
|
||||
}
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
//var_dump($user_network_ids);exit;
|
||||
if(!is_array($user_network_ids) || !count($user_network_ids)) {
|
||||
return mfResponse::Ok([]);
|
||||
}
|
||||
|
||||
foreach($user_network_ids as $network_id) {
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) continue;
|
||||
if(!$network->adb_netzgebiet_id) continue;
|
||||
$adb_network_ids[] = $network->adb_netzgebiet_id;
|
||||
}
|
||||
|
||||
|
||||
$sd_terms = [];
|
||||
$md_terms = [];
|
||||
|
||||
@@ -144,6 +150,34 @@ class PreorderconstructionApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
protected function getPreorders() {
|
||||
$campaign_ids = [];
|
||||
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if(!$user_network_ids) {
|
||||
return mfResponse::Ok([]);
|
||||
}
|
||||
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
//var_dump($user_network_ids);exit;
|
||||
if(!is_array($user_network_ids) || !count($user_network_ids)) {
|
||||
return mfResponse::Ok([]);
|
||||
}
|
||||
|
||||
foreach($user_network_ids as $network_id) {
|
||||
foreach(PreordercampaignModel::search(["network_id" => $network_id]) as $campaign) {
|
||||
$campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($campaign_ids);exit;
|
||||
|
||||
$preorders = [];
|
||||
foreach(PreorderModel::searchActive(["preordercampaign_id" => $campaign_ids]) as $preorder) {
|
||||
$preorders[] = $preorder->getApiArray(["full_home"]);
|
||||
}
|
||||
|
||||
|
||||
return mfResponse::Ok(["preorders" => $preorders]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -704,11 +704,18 @@ class Preorder extends mfBaseModel {
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
public function getApiArray($options = []) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$include_full_home = false;
|
||||
|
||||
if(in_array("full_home", $options)) {
|
||||
$include_full_home = true;
|
||||
}
|
||||
|
||||
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
$campaign = $this->getProperty("campaign");
|
||||
@@ -756,12 +763,6 @@ class Preorder extends mfBaseModel {
|
||||
$address['city'] = $hausnummer->strasse->gemeinde->name;
|
||||
$address['municipality'] = "";
|
||||
$address['district'] = $hausnummer->ortschaft->name;
|
||||
$address['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
//$address['stiege'] = ($wohneinheit->stiege) ? $wohneinheit->stiege : null;
|
||||
$address['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
$address['unit_string'] = ($wohneinheit->bezeichner) ? $wohneinheit->bezeichner : null;
|
||||
$address['is_shipping'] = ($this->shipping_address == "address") ? true : false;
|
||||
|
||||
if($campaign->district_is_city) {
|
||||
$address['city'] = $hausnummer->ortschaft->name;
|
||||
@@ -770,6 +771,44 @@ class Preorder extends mfBaseModel {
|
||||
unset($address['municipality']);
|
||||
}
|
||||
|
||||
if(!$include_full_home) {
|
||||
$address['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
$address['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
$address['unit_string'] = ($wohneinheit->bezeichner) ? $wohneinheit->bezeichner : null;
|
||||
} else {
|
||||
$home = [];
|
||||
|
||||
$home_status = $wohneinheit->status->getApiArray();
|
||||
foreach(ADBWohneinheitStatusflagValueModel::search(["hausnummer_id" => $hausnummer->id]) as $sflag) {
|
||||
$home_status["flags"][] = [
|
||||
"code" => (int)$sflag->flag->code,
|
||||
"text" => $sflag->flag->name,
|
||||
"value" => ($sflag->value == 1)
|
||||
];
|
||||
}
|
||||
|
||||
$home["id"] = (int)$wohneinheit->id;
|
||||
$home["status"] = $home_status;
|
||||
$home['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$home['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
$home['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
$home['unit_string'] = ($wohneinheit->bezeichner) ? $wohneinheit->bezeichner : null;
|
||||
$home["rimo_external_id"] = $wohneinheit->extref;
|
||||
$home["nutzung"] = $wohneinheit->nutzung;
|
||||
$home["rimo_executionstate"] = $wohneinheit->rimo_ex_state;
|
||||
$home["rimo_operationalstate"] = $wohneinheit->rimo_op_state;
|
||||
|
||||
$home['created'] = date("c", $wohneinheit->create);
|
||||
$home['created_ts'] = (int)$wohneinheit->create;
|
||||
$home['updated'] = date("c", $wohneinheit->edit);
|
||||
$home['updated_ts'] = (int)$wohneinheit->edit;
|
||||
|
||||
$address['address_id'] = (int)$hausnummer->id;
|
||||
}
|
||||
|
||||
$address['is_shipping'] = ($this->shipping_address == "address") ? true : false;
|
||||
|
||||
$customer = [];
|
||||
$customer['company'] = ($this->company) ? $this->company : null;
|
||||
$customer['uid'] = ($this->uid) ? $this->uid : null;
|
||||
@@ -788,6 +827,9 @@ class Preorder extends mfBaseModel {
|
||||
$customer['email'] = ($this->email) ? $this->email : null;
|
||||
|
||||
$a['address'] = $address;
|
||||
if($include_full_home) {
|
||||
$a["home"] = $home;
|
||||
}
|
||||
$a['customer'] = $customer;
|
||||
|
||||
$a['addonServices'] = null;
|
||||
|
||||
Reference in New Issue
Block a user