Skip to content

Commit

Permalink
Merge pull request #210 from wri/removeProjectFromSitePolygonTableFixes
Browse files Browse the repository at this point in the history
fix issues after removing project_id column from site_polygon table
  • Loading branch information
cesarLima1 authored May 20, 2024
2 parents 111fb2d + 383c41d commit 6c7a52f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/Helpers/GeometryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions app/Helpers/TerrafundDashboardQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 6c7a52f

Please sign in to comment.