118 lines
3.0 KiB
PHP
118 lines
3.0 KiB
PHP
<?php
|
|
|
|
class ProductgroupController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->isAdmin()) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$this->layout()->setTemplate("Productgroup/Index");
|
|
|
|
$filter = [];
|
|
if(is_array($this->request->filter)) {
|
|
$filter = $this->request->filter;
|
|
}
|
|
|
|
$this->layout->set("filter", $filter);
|
|
|
|
if($filter) {
|
|
$filter = $this->getPreparedFilter($filter);
|
|
}
|
|
|
|
// pagination defaults
|
|
$pagination = [];
|
|
$pagination['start'] = 0;
|
|
$pagination['count'] = 20;
|
|
$pagination['maxItems'] = 0;
|
|
|
|
if(is_numeric($this->request->s)) {
|
|
$pagination['start'] = intval($this->request->s);
|
|
}
|
|
|
|
$pagination['maxItems'] = ProductgroupModel::count($filter);
|
|
$this->layout()->set("pagination", $pagination);
|
|
$productgroups = ProductgroupModel::search($filter, $pagination);
|
|
$this->layout()->set("productgroups", $productgroups);
|
|
}
|
|
|
|
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]);
|
|
}
|
|
|
|
|
|
} |