AddessLink WIP
This commit is contained in:
@@ -4,6 +4,7 @@ class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
private $links;
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
@@ -128,6 +129,19 @@ class Address extends mfBaseModel {
|
||||
return $spin;
|
||||
}
|
||||
|
||||
public function deleteLinks() {
|
||||
$links = $this->getProperty("links");
|
||||
//var_dump($links);exit;
|
||||
if(is_array($links) && count($links)) {
|
||||
foreach($links as $type => $linktypes) {
|
||||
//var_dump($type, $linktypes);exit;
|
||||
foreach($linktypes as $link) {
|
||||
//var_dump($link);exit;
|
||||
$link->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -166,6 +180,30 @@ class Address extends mfBaseModel {
|
||||
$this->childaddresses = AddressModel::search(['parent' => $this->id]);
|
||||
return $this->childaddresses;
|
||||
}
|
||||
/*
|
||||
if($name == "links_to") {
|
||||
$links = AddressLinkModel::search(['address_id' => $this->id]);
|
||||
foreach($links as $link) {
|
||||
if(!array_key_exists($link->type, $this->links_to)) {
|
||||
$this->links_to[$link->type] = [];
|
||||
}
|
||||
$this->links_to[$link->type][] = $link->linked_to;
|
||||
}
|
||||
return $this->links_to;
|
||||
}*/
|
||||
|
||||
if($name == "links") {
|
||||
$links = AddressLinkModel::search(['origin_address_id' => $this->id]);
|
||||
//var_dump($links);exit;
|
||||
foreach($links as $link) {
|
||||
if(!array_key_exists($link->type, $this->links)) {
|
||||
$this->links[$link->type] = [];
|
||||
}
|
||||
$this->links[$link->type][] = $link;
|
||||
//var_dump($this->links);exit;
|
||||
}
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -104,7 +104,7 @@ class AddressController extends mfBaseController {
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
//var_dump($r->get());exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$address = new Address($id);
|
||||
@@ -228,6 +228,24 @@ class AddressController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$address->deleteLinks();
|
||||
//var_dump($r->links);exit;
|
||||
if(is_array($r->links) && count($r->links)) {
|
||||
//var_dump($r->links);exit;
|
||||
foreach($r->links as $linknum => $link) {
|
||||
if(!$link['type'] || !$link['address_id']) {
|
||||
continue;
|
||||
}
|
||||
$l = AddressLinkModel::create([
|
||||
'origin_address_id' => $new_id,
|
||||
'type' => $link['type'],
|
||||
'address_id' => $link['address_id']
|
||||
]);
|
||||
$l->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Address", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
@@ -287,6 +305,12 @@ class AddressController extends mfBaseController {
|
||||
$role = "billing";
|
||||
$po = 0;
|
||||
}
|
||||
if($this->request->role == "techcontact") {
|
||||
$role = "techcontact";
|
||||
$po = 0;
|
||||
}
|
||||
|
||||
$this->log->debug(print_r($this->request->get(),true));
|
||||
|
||||
$addresses = [];
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class AddressModel {
|
||||
$res = $db->select("Address", "*", "$where ORDER BY company, lastname, firstname, zip, city LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Voicenumber($data);
|
||||
$item = new Address($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user