Files
thetool/application/ConstructionConsent/ConstructionConsentController.php
Frank Schubert 6c0d334bbc WIP tmp
2024-11-07 16:28:05 +01:00

91 lines
2.7 KiB
PHP

<?php
class ConstructionConsentController extends mfBaseController {
protected function init() : void
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Index");
if ($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME . '-ConstructionConsent-filter']);
$this->redirect("ConstructionConsent");
}
$filter = [];
if (is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter'] = $filter;
} else {
if (array_key_exists(MFAPPNAME . '-ConstructionConsent-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsent-filter'])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsent-filter'];
}
}
$this->layout->set("filter", $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);
}
//var_dump($filter);exit;
$pagination['maxItems'] = ConstructionConsent::count($filter);
$this->layout()->set("pagination", $pagination);
$items = ConstructionConsent::search($filter);
$this->layout->set("items", $items);
}
private function getPreparedFilter($filter) : array
{
$new_filter = [];
if (is_array($filter) && count($filter)) {
foreach ($filter as $name => $value) {
$new_filter[$name] = $value;
}
}
return $new_filter;
}
protected function addAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Form");
}
protected function editAction() : void {
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$item = new ConstructionConsent($id);
if(!$item || !$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$this->layout()->set("item", $item);
$this->addAction();
}
}