Overhauled Address linking
This commit is contained in:
@@ -5,6 +5,7 @@ class Address extends mfBaseModel {
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
private $links;
|
||||
private $linked_as;
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
@@ -129,7 +130,7 @@ class Address extends mfBaseModel {
|
||||
return $spin;
|
||||
}
|
||||
|
||||
public function deleteLinks() {
|
||||
/*public function deleteLinks() {
|
||||
$links = $this->getProperty("links");
|
||||
//var_dump($links);exit;
|
||||
if(is_array($links) && count($links)) {
|
||||
@@ -141,7 +142,7 @@ class Address extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -205,6 +206,18 @@ class Address extends mfBaseModel {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
if($name == "linked_as") {
|
||||
$linked_as = AddressLinkModel::search(['address_id' => $this->id]);
|
||||
foreach($linked_as as $link) {
|
||||
if(!array_key_exists($link->type, $this->linked_as)) {
|
||||
$this->linked_as[$link->type] = [];
|
||||
}
|
||||
$this->linked_as[$link->type][] = $link;
|
||||
//var_dump($this->links);exit;
|
||||
}
|
||||
return $this->linked_as;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
@@ -84,13 +84,36 @@ class AddressController extends mfBaseController {
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Address/Form");
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
|
||||
$parents = AddressModel::search(['parent_id' => null]);
|
||||
$this->layout()->set("parents", $parents);
|
||||
}
|
||||
|
||||
protected function viewAction() {
|
||||
$this->layout()->setTemplate("Address/View");
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
$this->layout->set("f", $this->request->f);
|
||||
$this->layout->set("s", $this->request->s);
|
||||
|
||||
$address = new Address($this->request->id);
|
||||
$this->layout()->set("address", $address);
|
||||
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
$this->redirect("Address");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$address = new Address($this->request->id);
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
$this->layout->set("f", $this->request->f);
|
||||
$this->layout->set("s", $this->request->s);
|
||||
|
||||
$this->layout()->set("address", $address);
|
||||
|
||||
if(!$address->id) {
|
||||
@@ -101,6 +124,27 @@ class AddressController extends mfBaseController {
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function deleteLink() {
|
||||
$id = $this->request->id;
|
||||
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
$this->redirect("Address");
|
||||
}
|
||||
|
||||
$link = new AddressLink($id);
|
||||
if(!$link->id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
$this->redirect("Address");
|
||||
}
|
||||
|
||||
$address_id = $link->origin_address_id;
|
||||
$link->delete();
|
||||
$this->layout()->setFlash("Verknüpfung erfolgreich entfernt", "success");
|
||||
$this->redirect("Address", "edit", ['id' => $address_id]);
|
||||
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
@@ -229,7 +273,13 @@ class AddressController extends mfBaseController {
|
||||
}
|
||||
|
||||
|
||||
$address->deleteLinks();
|
||||
//$address->deleteLinks();
|
||||
|
||||
$existing_links = [];
|
||||
foreach(AddressLinkModel::search(['origin_address_id', $new_id]) as $elink) {
|
||||
$existing_links[$elink->address_id] = $elink;
|
||||
}
|
||||
|
||||
//var_dump($r->links);exit;
|
||||
if(is_array($r->links) && count($r->links)) {
|
||||
//var_dump($r->links);exit;
|
||||
@@ -237,17 +287,42 @@ class AddressController extends mfBaseController {
|
||||
if(!$link['type'] || !$link['address_id']) {
|
||||
continue;
|
||||
}
|
||||
if(array_key_exists($link['address_id'], $existing_links)) {
|
||||
continue;
|
||||
}
|
||||
$l = AddressLinkModel::create([
|
||||
'origin_address_id' => $new_id,
|
||||
'type' => $link['type'],
|
||||
'address_id' => $link['address_id']
|
||||
]);
|
||||
$l->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$sq = "";
|
||||
$query = [];
|
||||
if($r->s) {
|
||||
$query['s'] = $r->s;
|
||||
}
|
||||
if($r->filter) {
|
||||
$query["filter"] = $r->filter;
|
||||
}
|
||||
if($r->return != "index") {
|
||||
$query['id'] = $new_id;
|
||||
}
|
||||
|
||||
$qs = http_build_query($query);
|
||||
|
||||
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Address", "Edit", ['id' => $new_id]);
|
||||
if($r->return == "index") {
|
||||
$this->redirect("Address", "Index", $qs);
|
||||
}
|
||||
if($r->f == "view") {
|
||||
$this->redirect("Address", "View", $qs);
|
||||
}
|
||||
$this->redirect("Address", "Edit", $qs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -346,13 +346,13 @@ class AddressModel {
|
||||
$where .= " AND Address.create_by IN (". implode(",",$create_by).")";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(array_key_exists("parents_only", $filter)) {
|
||||
$po = $filter['parents_only'];
|
||||
if($po) {
|
||||
$where .= " AND parent_id IS NULL";
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user