Added forms for Contractconfig
This commit is contained in:
@@ -45,11 +45,73 @@ class ProductgroupController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
|
||||
$this->layout()->setTemplate("Productgroup/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$group = new Productgroup($id);
|
||||
if(!$group->id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$this->layout()->set("group", $group);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$group = new Productgroup($id);
|
||||
if(!$group->id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
$group = new Productgroup();
|
||||
}
|
||||
|
||||
$name = trim($r->name);
|
||||
if(!$name) {
|
||||
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$group->name = $r->name;
|
||||
$id = $group->save();
|
||||
|
||||
if(!$id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("group", $group);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
// contractconfig groups
|
||||
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $id]) as $ccpg) {
|
||||
$ccpg->delete();
|
||||
}
|
||||
|
||||
foreach($r->contractconfiggroups as $cg_id) {
|
||||
$ccgroup = ContractconfiggroupProductgroupModel::create([
|
||||
"productgroup_id" => $id,
|
||||
"contractconfiggroup_id" => $cg_id
|
||||
]);
|
||||
$ccgroup->save();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Produktgruppe erfolgreich gespeichert", "success");
|
||||
$this->redirect("Productgroup","edit", ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user