Added forms for Contractconfig
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
class Productgroup extends mfBaseModel {
|
||||
private $products;
|
||||
private $contractconfiggroups;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -21,6 +22,20 @@ class Productgroup extends mfBaseModel {
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
if($name == "contractconfiggroups") {
|
||||
$this->contractconfiggroups = mfValuecache::singleton()->get("Contractconfiggroups-byProductgroupid-".$this->id);
|
||||
if($this->contractconfiggroups === null) {
|
||||
$this->contractconfiggroups = [];
|
||||
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $this->id]) as $ccpg) {
|
||||
$this->contractconfiggroups[$ccpg->contractconfiggroup_id] = $ccpg->contractconfiggroup;
|
||||
}
|
||||
if(count($this->contractconfiggroups)) {
|
||||
mfValuecache::singleton()->set("Contractconfiggroups-byProductgroupid-".$this->id, $this->contractconfiggroups);
|
||||
}
|
||||
}
|
||||
return $this->contractconfiggroups;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
|
||||
@@ -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