Started work on Address
This commit is contained in:
87
application/Address/AddressController.php
Normal file
87
application/Address/AddressController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class AddressController extends mfBaseController {
|
||||
private $filter;
|
||||
|
||||
protected function indexAction() {
|
||||
$filter = $this->request->filter;
|
||||
$addresses = AddressModel::search($filter);
|
||||
|
||||
$this->layout()->set("addresses", $addresses);
|
||||
$this->layout()->set("filter", $filter);
|
||||
$this->layout()->set("request", $this->request);
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Address/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$address = new Address($this->request->id);
|
||||
$this->layout()->set("address", $address);
|
||||
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
$id = $r->id;
|
||||
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$address = new Address($id);
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
$this->redirect("Address");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
$data['parent_id'] = $r->parent_id;
|
||||
$data['company'] = $r->company;
|
||||
$data['firstname'] = $r->firstname;
|
||||
$data['lastname'] = $r->lastname;
|
||||
$data['street'] = $r->street;
|
||||
$data['zip'] = $r->zip;
|
||||
$data['city'] = $r->city;
|
||||
$data['country'] = $r->country;
|
||||
$data['phone'] = $r->phone;
|
||||
$data['fax'] = $r->fax;
|
||||
$data['mobile'] = $r->mobile;
|
||||
$data['email'] = $r->email;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = 1;
|
||||
$address = AddressModel::create($data);
|
||||
} else {
|
||||
$address->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $address->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("address", $address);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Address", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user