From 1563c8922e4cad35b1cbf1d9895e0dc939238935 Mon Sep 17 00:00:00 2001
From: Luca Haid
Date: Mon, 14 Apr 2025 13:12:45 +0200
Subject: [PATCH] added pipework history job
---
application/Building/BuildingModel.php | 11 +++-
scripts/pipework/run-weekly-email.php | 80 ++++++++++++++++++++++++--
2 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php
index a408f8a93..59de6146c 100644
--- a/application/Building/BuildingModel.php
+++ b/application/Building/BuildingModel.php
@@ -115,7 +115,6 @@ class BuildingModel {
LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id)
WHERE $where
ORDER BY network_id, pop_id, street, zip, city";
-
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
@@ -270,6 +269,13 @@ class BuildingModel {
$where .= " AND city like '$city'";
}
}
+
+ if(array_key_exists(">create", $filter)) {
+ $create = FronkDB::singleton()->escape($filter[">create"]);
+ if($create) {
+ $where .= " AND Building.`create` > $create";
+ }
+ }
//var_dump($filter, $where);exit;
return $where;
@@ -283,6 +289,7 @@ class BuildingModel {
wi.id AS item_id,
wi.name AS item_name,
wi.num AS item_num,
+ wi.object_type AS item_object_type,
wi.label AS item_label,
wi.type AS item_type,
wv.id AS value_id,
@@ -294,7 +301,7 @@ class BuildingModel {
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.name NOT LIKE '%delimiter%'"];
+ $where = ["wi.name NOT LIKE '%delimiter%'"];
if ($from !== null && $to !== null) {
$where[] = "(wv.changed >= " . intval($from) . " AND wv.changed <= " . intval($to) . ")";
diff --git a/scripts/pipework/run-weekly-email.php b/scripts/pipework/run-weekly-email.php
index d48c21052..980482e94 100644
--- a/scripts/pipework/run-weekly-email.php
+++ b/scripts/pipework/run-weekly-email.php
@@ -29,6 +29,8 @@ $allNetworkData = [];
$from = strtotime("-1 week"); // Simpler timestamp generation
$to = time();
+$newBuildings = [];
+
foreach ($networkIDs as $networkID) {
try {
$network = new Network($networkID); // Assuming Network class is loaded
@@ -39,6 +41,28 @@ foreach ($networkIDs as $networkID) {
// Optional: Log or handle cases where a Network object couldn't be created
error_log("Could not load Network with ID: " . $networkID);
}
+
+ // fetch new buildings
+ $newBuildingsNetwork = BuildingModel::search([
+ 'network_id' => $networkID,
+ '>create' => $from,
+ ]);
+ if ($newBuildingsNetwork) {
+ foreach ($newBuildingsNetwork as $building) {
+ if (!isset($newBuildings[$network->name])) {
+ $newBuildings[$network->name] = [];
+ }
+ $newBuildings[$network->name][] = [
+ 'network_id' => $networkID,
+ 'network_name' => $network->name,
+ 'building_id' => $building->id,
+ 'street' => $building->street,
+ 'zip' => $building->zip,
+ 'city' => $building->city,
+ ];
+ }
+ }
+
} catch (Exception $e) {
// Optional: Log or handle exceptions during data fetching for a specific network
error_log("Error fetching data for Network ID " . $networkID . ": " . $e->getMessage());
@@ -129,6 +153,32 @@ HTML;
Netzwerk: {$networkNameHtml}
HTML;
+// Check if there are new buildings and show them
+ if (!empty($newBuildings[$networkName])) {
+ $html .= <<Neue Gebäude:
+
+HTML;
+
+ foreach ($newBuildings[$networkName] as $building) {
+ $buildingStreet = htmlspecialchars($building['street']);
+ $buildingZip = htmlspecialchars($building['zip']);
+ $buildingCity = htmlspecialchars($building['city']);
+ $html .= <<{$buildingStreet}, {$buildingZip} {$buildingCity}
+HTML;
+ }
+ $html .= <<
+HTML;
+
+ } else {
+ $noNewBuildingsMsg = htmlspecialchars("Keine neuen Gebäude für dieses Netzwerk.");
+ $html .= <<{$noNewBuildingsMsg}
+HTML;
+ }
+
if (empty($networkData)) {
$noChangesMsg = htmlspecialchars("Keine Änderungen im Tiefbau für diesen Zeitraum.");
$html .= <<
+ | Art |
Straße |
Ort |
Feld |
@@ -185,11 +236,32 @@ HTML;
$street = htmlspecialchars($item->building_street ?? 'N/A');
$city = htmlspecialchars($item->building_city ?? 'N/A');
$label = htmlspecialchars($item->item_label ?? 'N/A');
+
+ if (strpos($label, 'Tiefbau abgeschlossen') !== false) {
+ $label = 'Tiefbau angeschlossen';
+ }
+ if (strpos($label, 'Leitungsbau abgeschlossen') !== false) {
+ $label = 'Leitungsbau angeschlossen';
+ }
+
$editedAt = date("d.m.Y H:i", $item->last_edited_at); // Shortened format for space
- $type = intval($item->item_num) > 150 ? 'Ist-Zustand' : 'Planung';
+ if ($item->item_object_type == 'Building') {
+ $type = intval($item->item_num) > 150 ? 'Ist-Zustand' : 'Planung';
+ $type2 = 'Tiefbau';
+ } else if ($item->item_object_type == 'Termination') {
+ if (intval($item->item_num) > 0 && intval($item->item_num) < 1005) $type = 'Planung';
+ else if (intval($item->item_num) > 1005 && intval($item->item_num) < 2005) $type = 'Ist-Zustand';
+ else $type = 'Zusätzlich';
+
+ $type2 = 'Leitungsbau';
+ } else {
+ $type = 'Unbekannt';
+ $type2 = 'Unbekannt';
+ }
$html .= <<
+ {$type2} |
{$street} |
{$city} |
{$label} |
@@ -256,7 +328,7 @@ try {
// Recipients
$mail->setFrom('thetool@xinon.at', 'XINON TheTool'); // Use sender address from config if available
- $mail->addAddress('mark.zaff@xinon.eu', 'Mark Zaff');
+// $mail->addAddress('mark.zaff@xinon.eu', 'Mark Zaff');
$mail->addAddress('luca.haid@xinon.eu', 'Luca Haid');
// Content
@@ -277,6 +349,4 @@ try {
error_log("E-Mail konnte nicht gesendet werden. Mailer Error: {$mail->ErrorInfo}");
// Output a user-friendly message
echo "E-Mail konnte nicht gesendet werden. Fehlerdetails wurden protokolliert. Mailer Error: {$mail->ErrorInfo}" . PHP_EOL; // German output
-}
-
-?>
\ No newline at end of file
+}?>
\ No newline at end of file