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; }