Added some linked data in Order to cache
This commit is contained in:
@@ -169,17 +169,24 @@ class Order extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($name == "owner") {
|
||||
$this->owner = new Address($this->owner_id);
|
||||
$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 == "contact") {
|
||||
$this->contact = new Address($this->contact_id);
|
||||
return $this->contact;
|
||||
}
|
||||
|
||||
if($name == "billingaddress") {
|
||||
$this->billingaddress = new Address($this->billingaddress_id);
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -209,24 +216,51 @@ class Order extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = new User($this->create_by);
|
||||
$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 = new User($this->edit_by);
|
||||
$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;
|
||||
|
||||
@@ -42,23 +42,42 @@ class OrderProduct extends mfBaseModel {
|
||||
|
||||
|
||||
if($name == "creator") {
|
||||
if($this->id) {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$this->creator = new User($this->create_by);
|
||||
return $this->creator;
|
||||
} else {
|
||||
return null;
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
if($this->id) {
|
||||
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
return $this->editor;
|
||||
} else {
|
||||
return null;
|
||||
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);
|
||||
@@ -67,7 +86,7 @@ class OrderProduct extends mfBaseModel {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
|
||||
@@ -15,7 +15,13 @@ class Product extends mfBaseModel {
|
||||
$this->attributes = [];
|
||||
|
||||
// get tech attribs
|
||||
$ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]);
|
||||
$ptattribs = mfValuecache::singleton()->get("ProducttechAttributes-techid-".$this->producttech_id);
|
||||
if($ptattribs === null) {
|
||||
$ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]);
|
||||
if(count($ptattribs)) {
|
||||
mfValuecache::singleton()->set("ProducttechAttributes-techid-".$this->producttech_id, $ptattribs);
|
||||
}
|
||||
}
|
||||
// fill atrribs with existing values of product attribs
|
||||
foreach($ptattribs as $pta) {
|
||||
$attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]);
|
||||
|
||||
@@ -278,7 +278,13 @@ class Termination extends mfBaseModel {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "status") {
|
||||
$this->status = TerminationstatusModel::getOne($this->status_id);
|
||||
$this->status = mfValuecache::singleton()->get("wfStatus-".$this->status_id);
|
||||
if($this->status === null) {
|
||||
$this->status = TerminationstatusModel::getOne($this->status_id);
|
||||
if($this->status->id) {
|
||||
mfValuecache::singleton()->set("wfStatus-".$this->status_id, $this->status);
|
||||
}
|
||||
}
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
@@ -293,7 +299,14 @@ class Termination extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($name == "lineworker") {
|
||||
$this->lineworker = new Address($this->getProperty("building")->lineworker_id);
|
||||
$lineworker_id = $this->getProperty("building")->lineworker_id;
|
||||
$this->lineworker = mfValuecache::singleton()->get("mfObjectmodel-Address-$lineworker_id");
|
||||
if($this->lineworker === null) {
|
||||
$this->lineworker = new Address($this->getProperty("building")->lineworker_id);
|
||||
if($this->lineworker->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-$lineworker_id", $this->lineworker);
|
||||
}
|
||||
}
|
||||
return $this->lineworker;
|
||||
}
|
||||
|
||||
@@ -316,7 +329,9 @@ class Termination extends mfBaseModel {
|
||||
$this->linework_enabler = mfValuecache::singleton()->get("Worker-id-".$this->linework_enabled_by);
|
||||
if(!$this->linework_enabler) {
|
||||
$this->linework_enabler = new User($this->linework_enabled_by);
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->linework_enabled_by, $this->linework_enabler);
|
||||
if($this->linework_enabler->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->linework_enabled_by, $this->linework_enabler);
|
||||
}
|
||||
}
|
||||
return $this->linework_enabler;
|
||||
}
|
||||
@@ -342,7 +357,7 @@ class Termination extends mfBaseModel {
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
if($this->$name === null) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,3 +30,16 @@ $request=array_merge($_GET,$_POST);
|
||||
|
||||
$app=new mfRouter($request);
|
||||
|
||||
|
||||
if(defined("MFVALUECACHE_DEBUG") && MFVALUECACHE_DEBUG) {
|
||||
$i = 0;
|
||||
$cache = mfValuecache::singleton()->getCache();
|
||||
echo "<pre class='xdebug-var-dump'>\n";
|
||||
echo "<small>mfValuecache keys total: ".count($cache)."</small>\n";
|
||||
foreach($cache as $key => $value) {
|
||||
echo "\t$i => $key (". gettype($value).")\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo "</pre>";
|
||||
}
|
||||
Reference in New Issue
Block a user