Finished Addressattribute

This commit is contained in:
Frank Schubert
2021-06-24 20:07:02 +02:00
parent 1b4226f762
commit 1c6acca834
5 changed files with 169 additions and 5 deletions
+12 -1
View File
@@ -3,7 +3,7 @@
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
@@ -44,6 +44,17 @@ class Address extends mfBaseModel {
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);
+15 -3
View File
@@ -42,7 +42,7 @@ class AddressController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
$id = $r->id;
//var_dump($r);
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$address = new Address($id);
@@ -94,7 +94,7 @@ class AddressController extends mfBaseController {
foreach($address->types as $existing_type) {
//var_dump($existing_type);
//var_dump($new_types);
echo $existing_type->type;
//echo $existing_type->type;
if(!in_array($existing_type->type, $new_types)) {
$existing_type->delete();
} else {
@@ -108,7 +108,19 @@ class AddressController extends mfBaseController {
$type_object = AddresstypeModel::create(['address_id' => $address->id, 'type' => $type]);
$type_object->save();
$address->types[$type] = $type_object;
}
}
$attribs = $r->attributes;
//var_dump($attribs);exit;
if(is_array($attribs) && count($attribs)) {
foreach($attribs as $atttrib => $value) {
$aa = AddressattributeModel::getFirst(["address_id" => $new_id, "name" => $attrib]);
if(!$aa) {
$aa = AddressattributeModel::create(["address_id" => $new_id, "name" => $attrib]);
}
$aa->value = $value;
$aa->save();
}
}