diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index 20b4fe4d1..08082a108 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -43,7 +43,7 @@ $pagination_entity_name = "Zustimmungserklärungen"; -
+
-
+
+
+ + +
+ +
+ + +
+
" /> @@ -89,6 +109,9 @@ $pagination_entity_name = "Zustimmungserklärungen";
+ 0) : ?>
+
diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index 83fb93883..f1a53761f 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -154,7 +154,7 @@ class ConstructionConsent extends mfBaseModel { } return $this->adb_hausnummer; } - + if($name == "adb_strasse") { if(!$this->adb_strasse_id) return null; $strasse = new ADBStrasse($this->adb_strasse_id); @@ -307,7 +307,7 @@ class ConstructionConsent extends mfBaseModel { return $this->$name; } - + /******************************** * Begin static Model functions */ @@ -339,7 +339,7 @@ class ConstructionConsent extends mfBaseModel { return $model; } - + public static function getAll() { $items = []; @@ -377,37 +377,46 @@ class ConstructionConsent extends mfBaseModel { } public static function count($filter) { - $db = FronkDB::singleton(); - - $where = self::getSqlFilter($filter); - $sql = "SELECT COUNT(*) as cnt FROM ConstructionConsent - LEFT JOIN ".ADDRESSDB_DBNAME.".view_hausnummer ON (ConstructionConsent.adb_hausnummer_id = view_hausnummer.hausnummer_id) - WHERE $where"; - - //mfLoghandler::singleton()->debug($sql); - - $res = $db->query($sql); - if($db->num_rows($res)) { - $data = $db->fetch_object($res); - return $data->cnt; - } - return 0; + return self::search($filter, false, false, true); } - public static function search($filter, $limit = false, $order = false) { - //var_dump($filter);exit; + public static function search($filter, $limit = false, $order = false, $returnCount = false) { $items = []; if(!$order) { $order = "adb_hausnummer_id ASC"; } + $having = ''; + if(array_key_exists("status_light", $filter) && strlen(trim($filter['status_light'])) > 2) { + $having = " HAVING status_light = '".$filter['status_light']."'"; + } $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT * FROM ConstructionConsent - LEFT JOIN ".ADDRESSDB_DBNAME.".view_hausnummer ON (ConstructionConsent.adb_hausnummer_id = view_hausnummer.hausnummer_id) + $sql = "SELECT + ConstructionConsent.*, + COALESCE(SUM(cwo.result = 'denied'), 0) AS denied_count, + COALESCE(SUM(cwo.result = 'unresolvable'), 0) AS unresolvable_count, + COALESCE(SUM(cwo.result = 'moved'), 0) AS moved_count, + COALESCE(SUM(cwo.result = 'accepted'), 0) AS accepted_count, + COUNT(cwo.id) AS total_owners, + CASE + WHEN COALESCE(SUM(cwo.result = 'denied'), 0) > 0 THEN 'red' + WHEN COALESCE(SUM(cwo.result = 'unresolvable'), 0) > 0 + OR COALESCE(SUM(cwo.result = 'moved'), 0) > 0 THEN 'yellow' + WHEN COALESCE(SUM(cwo.result = 'accepted'), 0) = COUNT(cwo.id) + AND COUNT(cwo.id) > 0 THEN 'green' + ELSE 'blue' + END AS status_light + FROM ConstructionConsent + LEFT JOIN ConstructionConsentOwner cwo + ON ConstructionConsent.id = cwo.constructionconsent_id + LEFT JOIN addressdb.view_hausnummer vh + ON ConstructionConsent.adb_hausnummer_id = vh.hausnummer_id WHERE $where + GROUP BY ConstructionConsent.id + $having ORDER BY $order"; if(is_array($limit) && count($limit)) { @@ -418,16 +427,15 @@ class ConstructionConsent extends mfBaseModel { } } - mfLoghandler::singleton()->debug($sql); - $res = $db->query($sql); if($db->num_rows($res)) { + if ($returnCount) return $db->num_rows($res); while($data = $db->fetch_object($res)) { $items[$data->id] = new ConstructionConsent($data); } } - return $items; + return $returnCount ? 0 : $items; } private static function getSqlFilter($filter) { @@ -439,7 +447,7 @@ class ConstructionConsent extends mfBaseModel { $where .= " AND ConstructionConsent.constructionconsentproject_id=$project_id"; } } - + if(array_key_exists("constructionconsentproject_id", $filter)) { $constructionconsentproject_id = $filter['constructionconsentproject_id']; if(is_numeric($constructionconsentproject_id)) { @@ -481,14 +489,14 @@ class ConstructionConsent extends mfBaseModel { $where .= " AND status='$status'"; } } - + if(array_key_exists("result", $filter)) { $result = FronkDB::singleton()->escape($filter["result"]); if($result) { $where .= " AND result='$result'"; } } - + if(array_key_exists("owner_name", $filter)) { $owner_name = FronkDB::singleton()->escape($filter["owner_name"]); if($owner_name) {