Overhauled Address linking
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user