changes for mark

This commit is contained in:
Luca Haid
2025-04-10 12:45:12 +02:00
parent 9df3e9f926
commit 4d8806c64a
6 changed files with 254 additions and 5 deletions

View File

@@ -167,6 +167,13 @@ class BuildingModel {
$where .= " AND Building.pipeworker_id=$pipeworker_id";
}
}
if(array_key_exists("pipework_enabled", $filter)) {
$pipework_enabled = $filter['pipework_enabled'];
if(!empty($pipework_enabled) || $pipework_enabled === "0") {
$where .= " AND Building.pipework_enabled=$pipework_enabled";
}
}
if(array_key_exists("type", $filter) && is_array($filter['type']) && count($filter['type'])) {
$ot = $filter['type'];
@@ -267,5 +274,54 @@ class BuildingModel {
//var_dump($filter, $where);exit;
return $where;
}
public static function getHistory($from, $to, $network_id, $street_filter): array {
$sql = "SELECT b.id AS building_id,
b.street AS building_street,
b.zip AS building_zip,
b.city AS building_city,
wi.id AS item_id,
wi.name AS item_name,
wi.label AS item_label,
wi.type AS item_type,
wv.id AS value_id,
wv.value_string,
wv.value_int,
wv.value_text,
(wv.create) AS created_at,
wv.create_by AS created_by_user_id,
(wv.edit) AS last_edited_at,
wv.edit_by AS last_edited_by_user_id
FROM Workflowvalue wv
JOIN Workflowitem wi ON wv.item_id = wi.id
JOIN Building b ON wv.object_id = b.id";
$where = ["wi.object_type = 'Building'", "wi.num < 150"];
if ($from !== null && $to !== null) {
$where[] = "((wv.create >= " . intval($from) . " AND wv.create <= " . intval($to) . ") OR (wv.edit >= " . intval($from) . " AND wv.edit <= " . intval($to) . "))";
}
if ($network_id !== null) {
$where[] = "b.network_id = " . intval($network_id);
}
if (!empty($street_filter)) {
$escaped_street = addslashes($street_filter);
$where[] = "b.street LIKE '%" . $escaped_street . "%'";
}
$sql .= " WHERE " . implode(" AND ", $where);
$sql .= " ORDER BY wv.edit DESC, wv.create DESC;";
$db = FronkDB::singleton();
$res = $db->query($sql);
if ($db->num_rows($res)) {
$items = [];
while ($data = $db->fetch_object($res)) {
$items[] = $data;
}
return $items;
} else {
return [];
}
}
}