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;