From 383c41d14b9c7616a154f8cec737f1706d17bd94 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 20 May 2024 11:50:52 -0400 Subject: [PATCH] fix issues after removing project_id column from site_polygon table --- app/Helpers/GeometryHelper.php | 8 +++++++- app/Helpers/TerrafundDashboardQueryHelper.php | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 69c575d68..b05f20b56 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -11,7 +11,13 @@ class GeometryHelper { public function centroidOfProject($projectUuid) { - $sitePolygons = SitePolygon::where('project_id', $projectUuid)->get(); + $project = Project::where('uuid', $projectUuid)->first(); + + if (!$project) { + return null; + } + + $sitePolygons = $project->sitePolygons; if ($sitePolygons->isEmpty()) { return null; // Return null if no polygons are found for the given projectUuid diff --git a/app/Helpers/TerrafundDashboardQueryHelper.php b/app/Helpers/TerrafundDashboardQueryHelper.php index 604d629de..f6a4b8745 100644 --- a/app/Helpers/TerrafundDashboardQueryHelper.php +++ b/app/Helpers/TerrafundDashboardQueryHelper.php @@ -28,7 +28,9 @@ public static function getPolygonIdsOfProject($request) { $projectIds = TerrafundDashboardQueryHelper::buildQueryFromRequest($request) ->pluck('uuid'); - $polygonsIds = SitePolygon::whereIn('project_id', $projectIds)->pluck('poly_id'); + $polygonsIds = SitePolygon::whereHas('site.project', function ($query) use ($projectIds) { + $query->whereIn('uuid', $projectIds); + })->pluck('poly_id'); return $polygonsIds; } @@ -44,9 +46,11 @@ public static function getPolygonsByStatusOfProject($request) foreach ($statuses as $status) { // Get polygons of the project filtered by status - $polygonsOfProject = SitePolygon::whereIn('project_id', $projectIds) - ->where('status', $status) - ->pluck('poly_id'); + $polygonsOfProject = SitePolygon::whereHas('site.project', function ($query) use ($projectIds) { + $query->whereIn('uuid', $projectIds); + }) + ->where('status', $status) + ->pluck('poly_id'); $polygons[$status] = $polygonsOfProject; }