83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
class Product extends mfBaseModel {
|
|
private $owner;
|
|
private $productgroup;
|
|
private $producttech;
|
|
private $sla;
|
|
private $networks;
|
|
private $attributes;
|
|
|
|
public function loadAttributes() {
|
|
$this->attributes = [];
|
|
|
|
if(!$this->producttech_id) {
|
|
return [];
|
|
}
|
|
|
|
// get tech attribs
|
|
$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]);
|
|
if(!$attrib) {
|
|
$attrib = new ProductAttribute();
|
|
$attrib->product_id = $this->id;
|
|
$attrib->producttechattribute_id = $pta->id;
|
|
$attrib->value = $pta->value;
|
|
$attrib->note = $pta->note;
|
|
}
|
|
$attrib->name = $pta->name;
|
|
$attrib->type = $pta->type;
|
|
$attrib->displayname = $pta->displayname;
|
|
$attrib->description = $pta->description;
|
|
$this->attributes[$attrib->name] = $attrib;
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "owner") {
|
|
if(!$this->external_id) return null;
|
|
$this->owner = new Address($this->external_id);
|
|
return $this->owner;
|
|
}
|
|
|
|
if($name == "networks") {
|
|
$this->networks = [];
|
|
$productNetworks = ProductNetworkModel::search(['product_id' => $this->id]);
|
|
foreach($productNetworks as $pnet) {
|
|
$this->networks[$pnet->network_id] = new Network($pnet->network_id);
|
|
}
|
|
return $this->networks;
|
|
}
|
|
|
|
if($name == "attributes") {
|
|
$this->loadAttributes();
|
|
return $this->attributes;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
} |