116 lines
2.9 KiB
PHP
116 lines
2.9 KiB
PHP
<?php
|
|
|
|
class OrderProduct extends mfBaseModel {
|
|
private $order;
|
|
private $product;
|
|
private $termination;
|
|
private $cpeprovisioning;
|
|
private $contract;
|
|
private $voicenumbers;
|
|
private $editor;
|
|
private $creator;
|
|
|
|
public function formatAmount() {
|
|
if(!$this->id) {
|
|
return 0;
|
|
}
|
|
|
|
$m = [];
|
|
if(preg_match('/^(\d*)\.(\d+)$/', $this->amount, $m)) {
|
|
$int = $m[1];
|
|
$dec = $m[2];
|
|
|
|
if(!$dec) {
|
|
return $int;
|
|
}
|
|
|
|
if(preg_match('/^0+$/', $dec)) {
|
|
return $int;
|
|
}
|
|
|
|
$dec = preg_replace('/0+$/', "", $dec);
|
|
return "$int.$dec";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if(!$this->id) {
|
|
return null;
|
|
}
|
|
|
|
if($name == "cpeprovisioning") {
|
|
$this->cpeprovisioning = CpeprovisioningModel::getFirst(["orderproduct_id" => $this->id]);
|
|
return $this->cpeprovisioning;
|
|
}
|
|
|
|
if($name == "contract") {
|
|
$this->contract = ContractModel::getFirst(['orderproduct_id' => $this->id]);
|
|
return $this->contract;
|
|
}
|
|
|
|
if($name == "voicenumbers") {
|
|
$this->voicenumbers = [];
|
|
if(!$this->voicenumber) return [];
|
|
|
|
$json = json_decode($this->voicenumber);
|
|
|
|
if(!is_array($json)) return [];
|
|
$this->voicenumbers = $json;
|
|
|
|
return $this->voicenumbers;
|
|
}
|
|
|
|
if($name == "creator") {
|
|
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($this->creator === null) {
|
|
$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 = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
|
if($this->editor === null) {
|
|
$this->editor = new User($this->edit_by);
|
|
if($this->editor->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
/*
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = new $classname($this->$idfield);
|
|
|
|
if($this->$name->id) {
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}*/
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
} |