loadMe(); $data["edit_by"] = $me->id; } return $data; } 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; } public function __clone() { $me = new User; $me->loadMe(); $old_id = $this->id; $this->id = null; $this->name .= " - Kopie"; // cleanup data $this->create_by = $me->id; $this->edit_by = $me->id; $this->create = null; $this->edit = null; $this->saved = 0; $this->mode = "new"; $this->_old_data = new StdClass(); $this->log->debug("Cloned Product $old_id"); } }