added contact edit button

This commit is contained in:
Luca Haid
2025-03-25 10:38:20 +01:00
parent 7be3446383
commit 321726718f
11 changed files with 157 additions and 50 deletions
@@ -152,21 +152,16 @@ class ConstructionConsentProject extends mfBaseModel {
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentProject
LEFT JOIN ConstructionConsentNetwork ON (ConstructionConsentNetwork.constructionconsentproject_id = ConstructionConsentNetwork.id)
WHERE $where
GROUP BY ConstructionConsentProject.id
";
$sql = "SELECT COUNT(*) AS cnt FROM ConstructionConsentProject WHERE $where";
//mfLoghandler::singleton()->debug($sql);
$result = $db->query($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
if ($result && $db->num_rows($result) > 0) {
$data = $db->fetch_object($result);
return (int)$data->cnt;
}
return 0;
}
@@ -217,6 +212,22 @@ class ConstructionConsentProject extends mfBaseModel {
}
}
if(array_key_exists("id", $filter)) {
if(is_numeric($filter["id"])) {
$where .= " AND ConstructionConsentProject.id = ".$filter["id"];
} elseif(is_array($filter["id"])) {
$ids = [];
foreach($filter["id"] as $id) {
if(is_numeric($id)) {
$ids[] = $id;
}
}
if(count($ids)) {
$where .= " AND ConstructionConsentProject.id IN (".implode(",", $ids).")";
}
}
}
if(array_key_exists("add-where", $filter)) {
@@ -10,45 +10,39 @@ class ConstructionConsentProjectController extends mfBaseController {
$this->me = $me;
$this->layout()->set("me", $me);
if (!($me->is(["Admin","netowner","salespartner"]) && in_array($me->address_id, [1,209,5908,2187]))) $this->redirect("Dashboard");
if ($this->me->is("Admin")) $this->constructionConsentProjects = array_column(ConstructionConsentProject::getAll(), 'id');
else {
$constructionConsentProjects = json_decode((new WorkerFlag($this->me->id, "constructionConsent_projects"))->value() ?? '[]');
empty($constructionConsentProjects) ? $this->redirect("Dashboard") : $this->constructionConsentProjects = $constructionConsentProjects;
}
}
protected function indexAction() : void {
$this->layout()->setTemplate("ConstructionConsentProject/Index");
$sessionKey = MFAPPNAME . '-ConstructionConsentProject-filter';
if ($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter']);
unset($_SESSION[$sessionKey]);
}
$filter = [];
if (is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'] = $filter;
} else {
if (array_key_exists(MFAPPNAME . '-ConstructionConsentProject-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsentProject-filter'];
}
$filter = is_array($this->request->filter)
? $this->request->filter
: $_SESSION[$sessionKey] ?? [];
if (isset($this->request->filter)) {
$_SESSION[$sessionKey] = $filter;
}
$this->layout->set("filter", $filter);
$filter = $this->getPreparedFilter($filter);
// pagination defaults
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 25;
$pagination['maxItems'] = 0;
if (is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
//var_dump($filter);exit;
$pagination['maxItems'] = ConstructionConsentProject::count($filter);
$projects = ConstructionConsentProject::getAll();
$this->layout()->set("projects", $projects);
$this->layout()->set("pagination", $pagination);
$prepared = $this->getPreparedFilter($filter);
$prepared["id"] = $this->constructionConsentProjects;
$this->layout()->setTemplate("ConstructionConsentProject/Index");
$this->layout()->set("filter", $filter);
$this->layout()->set("projects", ConstructionConsentProject::search($prepared));
$this->layout()->set("pagination", [
'start' => (int)($this->request->s ?? 0),
'count' => 25,
'maxItems' => ConstructionConsentProject::count($prepared)
]);
}
private function getPreparedFilter($filter) {