Added Contractconfig Edit
This commit is contained in:
@@ -27,13 +27,13 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$contract_id = $this->request->contract_id;
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","danger");
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($contract_id);
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","danger");
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
@@ -44,6 +44,51 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("groups", $contract->configgroups);
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$contract_id = $r->contract_id;
|
||||
|
||||
if(!is_numeric($contract_id) || $contract_id < 1) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
if(!is_array($r->itemvalues) || !count($r->itemvalues)) {
|
||||
$this->layout()->setFlash("Keine Änderungen.","info");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$error_items = [];
|
||||
|
||||
foreach($r->itemvalues as $item_id => $itemvalue) {
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->log->warn("Tried to save non-existant ContractconfigItem $item_id");
|
||||
continue;
|
||||
}
|
||||
$item->setContractId($contract_id);
|
||||
if(!$item->value->set($itemvalue)) {
|
||||
$error_items[$item->id] = $item->name;
|
||||
continue;
|
||||
}
|
||||
if(!$item->value->save()) {
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Fehler beim Speichern von".$item->name,"info");
|
||||
return $this->editAction();
|
||||
}
|
||||
}
|
||||
|
||||
if(count($error_items)) {
|
||||
$this->layout()->set("error_items", array_keys($error_items));
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Konfiguration nicht vollständig gespeichert. Fehler in folgenden Feldern:\n<br />".implode(", ", $error_items), "warning");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Konfiguration gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user