71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
class Address extends mfBaseModel {
|
|
protected $forcestr = ['company','zip','phone','fax','mobile','note'];
|
|
private $types;
|
|
private $attributes;
|
|
|
|
public function getFullName() {
|
|
// Assumes "Firma1 Firma2" or "firstname lastname" as readable form
|
|
$name = "";
|
|
|
|
if($this->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();
|
|
}
|
|
|
|
private function loadAddresstypes() {
|
|
if(!$this->id) {
|
|
return false;
|
|
}
|
|
|
|
$this->types = AddresstypeModel::search(['address_id' => $this->id], true);
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == 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;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
} |