firstname && $this->lastname) { $name = $this->firstname . " " . $this->lastname; } elseif($this->lastname) { $name = $this->lastname; } elseif($this->firstname) { $name = $this->firstname; } return $name; } public function getCompanyOrName() { if($this->company) { return $this->company; } return $this->getFullName(); } public function loadAddresstypes() { if(!$this->id) { return false; } if(!$this->parent_id) { $this->types = AddresstypeModel::search(['address_id' => $this->id], true); } else { // get types from parent $parent = $this->getProperty("parent"); $types = $parent->getProperty("types"); $this->types = $types; } return true; } public function getProperty($name) { if($this->$name == null) { if(!$this->id) { return null; } if($name == "types") { $this->loadAddresstypes(); return $this->types; } if($name == "attributes") { $attribs = AddressattributeModel::search(['address_id' => $this->id]); if(count($attribs)) { $this->attributes = []; foreach($attribs as $a) { $this->attributes[$a->name] = $a; } } return $this->attributes; } if($name == "permissions") { $this->permissions = NetworkAddressModel::search(['address_id' => $this->id]); return $permissions; } if($name == "parent") { $this->parent = new Address($this->parent_id); return $this->parent; } $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; } }