263 lines
8.4 KiB
PHP
263 lines
8.4 KiB
PHP
<?php
|
|
|
|
class Contract extends mfBaseModel {
|
|
private $owner;
|
|
private $billingaddress;
|
|
private $product;
|
|
private $orderproduct;
|
|
private $termination;
|
|
private $sla;
|
|
private $contractConfigGroups;
|
|
private $contractConfigItems;
|
|
private $configgroups;
|
|
private $links;
|
|
private $linkFrom;
|
|
private $linkTo;
|
|
private $upgradeFrom;
|
|
private $upgradeTo;
|
|
private $downgradeFrom;
|
|
private $downgradeTo;
|
|
private $productchangeFrom;
|
|
private $productchangeTo;
|
|
private $relocationFrom;
|
|
private $relocationTo;
|
|
private $finisher;
|
|
private $canceler;
|
|
private $creator;
|
|
private $editor;
|
|
|
|
|
|
private function getLinks() {
|
|
$this->linkFrom = [];
|
|
$this->linkTo = [];
|
|
$this->upgradeFrom = [];
|
|
$this->upgradeTo = [];
|
|
$this->downgradeFrom = [];
|
|
$this->downgradeTo = [];
|
|
$this->productchangeFrom = [];
|
|
$this->productchangeTo = [];
|
|
$this->relocationFrom = [];
|
|
$this->relocationTo = [];
|
|
|
|
// Links targeting this contract (to)
|
|
foreach(ContractLinkModel::search(['origin_contract_id' => $this->id]) as $link) {
|
|
switch($link->type) {
|
|
case "link":
|
|
$this->linkTo[] = $link;
|
|
break;
|
|
case "upgrade":
|
|
$this->upgradeTo[] = $link;
|
|
break;
|
|
case "downgrade":
|
|
$this->downgradeTo[] = $link;
|
|
break;
|
|
case "productchange":
|
|
$this->productchangeTo[] = $link;
|
|
break;
|
|
case "relocation":
|
|
$this->relocationTo[] = $link;
|
|
break;
|
|
default:
|
|
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
|
break;
|
|
}
|
|
}
|
|
|
|
foreach(ContractLinkModel::search(['contract_id' => $this->id]) as $link) {
|
|
switch($link->type) {
|
|
case "link":
|
|
$this->linkFrom[] = $link;
|
|
break;
|
|
case "upgrade":
|
|
$this->upgradeFrom[] = $link;
|
|
break;
|
|
case "downgrade":
|
|
$this->downgradeFrom[] = $link;
|
|
break;
|
|
case "productchange":
|
|
$this->productchangeFrom[] = $link;
|
|
break;
|
|
case "relocation":
|
|
$this->relocationFrom[] = $link;
|
|
break;
|
|
default:
|
|
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*$this->links = mfValuecache::singleton()->get("ContractLinks-origin-".$this->id);
|
|
if(!$this->links) {
|
|
$this->links = [];
|
|
foreach(ContractLinkModel::search(["origin_contract_id" => $this->id]) as $link) {
|
|
if(array_key_exists($link->type, $this->links)) {
|
|
$this->links[$link->type] = [];
|
|
}
|
|
$this->links[$link->type][] = $link;
|
|
}
|
|
}
|
|
if(count($this->links)) {
|
|
mfValuecache::singleton()->set("ContractLinks-origin-".$this->id, $this->links);
|
|
}
|
|
*/
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if(!$this->id) {
|
|
return null;
|
|
}
|
|
|
|
if($name == "owner") {
|
|
$this->owner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->owner_id);
|
|
if($this->owner === null) {
|
|
$this->owner = new Address($this->owner_id);
|
|
if($this->owner->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->owner_id, $this->owner);
|
|
}
|
|
}
|
|
return $this->owner;
|
|
}
|
|
|
|
if($name == "billingaddress") {
|
|
|
|
$this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id);
|
|
if($this->billingaddress === null) {
|
|
$this->billingaddress = new Address($this->billingaddress_id);
|
|
if($this->billingaddress->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress);
|
|
}
|
|
}
|
|
return $this->billingaddress;
|
|
}
|
|
|
|
if($name == "product") {
|
|
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
|
if($this->product === null) {
|
|
$this->product = new Product($this->product_id);
|
|
if($this->product->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Product-".$this->product_id, $this->product);
|
|
}
|
|
}
|
|
return $this->product;
|
|
}
|
|
|
|
if($name == "orderproduct") {
|
|
$this->orderproduct = mfValuecache::singleton()->get("mfObjectmodel-OrderProduct-".$this->orderproduct_id);
|
|
if($this->orderproduct === null) {
|
|
$this->orderproduct = new OrderProduct($this->orderproduct_id);
|
|
if($this->orderproduct->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-OrderProduct-".$this->orderproduct_id, $this->orderproduct);
|
|
}
|
|
}
|
|
return $this->orderproduct;
|
|
}
|
|
|
|
if($name == "contractConfigGroups") {
|
|
$product = $this->getProperty("product");
|
|
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
|
|
return $this->contractConfigGroups;
|
|
}
|
|
|
|
if($name == "configgroups") {
|
|
$product = $this->getProperty("product");
|
|
$this->configgroups = [];
|
|
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $product->productgroup_id]) as $ccpg) {
|
|
$ccpg->contractconfiggroup->setContractId($this->id);
|
|
$this->configgroups[] = $ccpg->contractconfiggroup;
|
|
}
|
|
return $this->configgroups;
|
|
}
|
|
|
|
if($name == "contractConfigItems") {
|
|
$product = $this->getProperty("product");
|
|
|
|
$this->contractConfigItems = [];
|
|
foreach(ProducttechAttributeModel::search(['producttech_id' => $product->producttech_id, "forcontract" => 1]) as $item) {
|
|
$item->setContractId($this->id);
|
|
$this->contractConfigItems [] = $item;
|
|
}
|
|
|
|
return $this->contractConfigItems;
|
|
}
|
|
|
|
if($name == "links") {
|
|
$this->links = ContractLinkModel::includesContractId($this->id, ["type" => $link]);
|
|
return $this->links;
|
|
}
|
|
|
|
if(in_array($name, ['linkFrom','linkTo','upgradeFrom','upgradeTo','downgradeFrom','downgradeTo','productchangeFrom','productchangeTo','relocationFrom','relocationTo'])) {
|
|
if($this->$name === null) {
|
|
$this->getLinks();
|
|
}
|
|
return $this->$name;
|
|
}
|
|
|
|
if($name == "finisher") {
|
|
$this->finisher = mfValuecache::singleton()->get("Worker-id-".$this->finish_date_by);
|
|
if($this->finisher === null) {
|
|
$this->finisher = new User($this->finish_date_by);
|
|
if($this->finisher->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->finish_date_by, $this->finisher);
|
|
}
|
|
}
|
|
return $this->finisher;
|
|
}
|
|
|
|
if($name == "canceler") {
|
|
$this->canceler = mfValuecache::singleton()->get("Worker-id-".$this->cancel_date_by);
|
|
if($this->canceler === null) {
|
|
$this->canceler = new User($this->cancel_date_by);
|
|
if($this->canceler->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->cancel_date_by, $this->canceler);
|
|
}
|
|
}
|
|
return $this->canceler;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
|
|
} |