uid === "string") { $this->uid = ""; } } public function createUcode() { $ucode = $this->generateNewUcode(); while(PreorderModel::search(['ucode' => $ucode])) { $ucode = $this->generateNewUcode(); } $this->ucode = $ucode; return $this->ucode; } private function generateNewUcode() { $chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; $charsLength = strlen($chars); $ucode = ''; for ($i = 0; $i < 8; $i++) { $ucode .= $chars[rand(0, $charsLength - 1)]; } return $ucode; } public function getApiArray() { if(!$this->id) { return false; } $hausnummer = $this->getProperty("adb_hausnummer"); $wohneinheit = $this->getProperty("adb_wohneinheit"); $campaign = $this->getProperty("campaign"); $a = []; $a['code'] = strtoupper($this->ucode); $a['oaid'] = $this->oaid; $a['extref'] = $this->extref; $a['status'] = $this->getProperty("status")->getApiArray(); $a['connectionType'] = $this->connection_type; $a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1; $a['isAdditionalOrder'] = ($this->is_additional_order) ? true : false; $a['technology'] = ($this->technology) ? $this->technology : null; $a['patchposition'] = ($this->patchposition) ? $this->patchposition : null; $a['preorderType'] = $this->type; $a['acceptMarketing'] = ($this->accept_marketing) ? true : false; $a['acceptAgb'] = ($this->accept_agb) ? true : false; $a['acceptDsgvo'] = ($this->accept_dsgvo) ? true : false; $a['acceptWithdrawal'] = ($this->accept_withdrawal) ? true : false; $a['acceptDigging'] = ($this->accept_digging) ? true : false; $a['address_info'] = ($this->address_info) ? $this->address_info : null; $address = []; $address['cluster_id'] = $hausnummer->netzgebiet->extref; $address['street'] = $hausnummer->strasse->name; $address['housenumber'] = $hausnummer->hausnummer; $address['zip'] = $hausnummer->plz->plz; $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; $address['municipality'] = $hausnummer->strasse->gemeinde->name; } else { unset($address['municipality']); } $customer = []; $customer['company'] = ($this->company) ? $this->company : null; $customer['uid'] = ($this->uid) ? $this->uid : null; $customer['firstnam'] = ($this->firstname) ? $this->firstname : null; $customer['lastname'] = ($this->lastname) ? $this->lastname : null; $customer['street'] = ($this->street) ? $this->street : null; $customer['housenumber'] = ($this->housenumber) ? $this->housenumber : null; $customer['zip'] = ($this->zip) ? $this->zip : null; $customer['city'] = ($this->city) ? $this->city : null; $customer['block'] = ($this->block) ? $this->block : null; $customer['stock'] = ($this->stock) ? $this->stock : null; $customer['stiege'] = ($this->stiege) ? $this->stiege : null; $customer['tuer'] = ($this->tuer) ? $this->tuer : null; $customer['unit_string'] = ($this->unit_string) ? $this->unit_string : null; $customer['phone'] = ($this->phone) ? $this->phone : null; $customer['email'] = ($this->email) ? $this->email : null; $a['address'] = $address; $a['customer'] = $customer; $a['addonServices'] = null; if($this->addon_services) { $addon_services = json_decode($this->addon_services); if(json_last_error() === JSON_ERROR_NONE) { $a['addonServices'] = $addon_services; } } $a['additionalData'] = null; if($this->addon_data) { $addon_data = json_decode($this->addon_data); if(json_last_error() === JSON_ERROR_NONE) { $a['additionalData'] = $addon_data; } } $a['created'] = date("c", $this->create); $a['created_ts'] = (int)$this->create; $a['updated'] = date("c", $this->edit); $a['updated_ts'] = (int)$this->edit; return $a; } public function getProperty($name) { if($this->$name == null) { if($name == "campaign") { $this->campaign = new Preordercampaign($this->preordercampaign_id); return $this->campaign; } if($name == "status") { $this->status = mfValuecache::singleton()->get("mfObjectmodel-Preorderstatus-".$this->status_id); if(!$this->status) { $this->status = new Preorderstatus($this->status_id); if($this->status->id) { mfValuecache::singleton()->set("mfObjectmodel-Preorderstatus-".$this->status_id, $this->status); } } return $this->status; } if($name == "partner") { $this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id); if(!$this->partner) { $this->partner = new Address($this->partner_id); if($this->partner->id) { mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->partner_id, $this->partner); } } return $this->partner; } if($name == "building") { $this->building = mfValuecache::singleton()->get("mfObjectmodel-Building-".$this->building_id); if(!$this->building) { $this->building = new Building($this->building_id); if($this->building->id) { mfValuecache::singleton()->set("mfObjectmodel-Building-".$this->building_id, $this->building); } } return $this->building; } if($name == "adb_hausnummer") { $this->adb_hausnummer = new ADBHausnummer($this->adb_hausnummer_id); return $this->adb_hausnummer; } if($name == "adb_wohneinheit") { $this->adb_wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); return $this->adb_wohneinheit; } if($name == "addon_services") { } if($name == "attribute") { if(!$this->attributes) { return null; } $this->attribute = json_decode($this->attributes, true); return $this->attribute; } if($name == "creator") { $user = mfValuecache::singleton()->get("Worker-id-".$this->create_by); if($user) { $this->creator = $user; return $this->creator; } $this->creator = new User($this->create_by); if($this->creator->id) { mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); } return $this->creator; } if($name == "editor") { $this->editor = new User($this->edit_by); return $this->editor; } $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); if(!$this->$name) { $this->$name = new $classname($this->$idfield); } if($this->$name->id) { mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); return $this->$name; } else { return null; } } return $this->$name; } public function __clone() { $me = new User; $me->loadMe(); $old_id = $this->id; //$old_ucode = $this->ucode; $this->id = null; $this->data = clone($this->data); $this->_old_data = new StdClass(); $this->status = null; $this->campaign = null; $this->partner = null; $this->building = null; $this->adb_hausnummer = null; $this->adb_wohneinheit; // cleanup Preorder data $this->create_by = $me->id; $this->edit_by = $me->id; $this->create = null; $this->edit = null; $this->saved = 0; $this->mode = "new"; //$this->save(); $this->log->debug("Cloned Preorder $old_id"); } }