From 1167b426db23a9e8147f641b1c1e4491036c574e Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Jul 2024 13:51:25 -0700 Subject: [PATCH 1/3] [TM-1093] Sites in restoration-in-progress need to count as approved. --- app/Models/V2/Sites/Site.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Models/V2/Sites/Site.php b/app/Models/V2/Sites/Site.php index a7747f69c..100f99621 100644 --- a/app/Models/V2/Sites/Site.php +++ b/app/Models/V2/Sites/Site.php @@ -195,6 +195,14 @@ public function toSearchableArray() ]; } + /** + * Overrides the method from HasEntityStatusScopesAndTransitions + */ + public function scopeIsApproved(Builder $query): Builder + { + return $query->whereIn('status', [EntityStatusStateMachine::APPROVED, SiteStatusStateMachine::RESTORATION_IN_PROGRESS]); + } + /** RELATIONS */ public function framework(): BelongsTo { From 9f785125b1b0e1435f04b8c8fee4b75ef160d4d9 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Jul 2024 14:13:46 -0700 Subject: [PATCH 2/3] [TM-1093] Sites in restoration-in-progress need to count as approved. --- app/Models/V2/Projects/Project.php | 2 +- app/Models/V2/Sites/Site.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Models/V2/Projects/Project.php b/app/Models/V2/Projects/Project.php index f390ea725..59f576a79 100644 --- a/app/Models/V2/Projects/Project.php +++ b/app/Models/V2/Projects/Project.php @@ -498,7 +498,7 @@ private function submittedSiteReports(): HasManyThrough // a status field. return $this ->siteReports() - ->where('v2_sites.status', EntityStatusStateMachine::APPROVED) + ->whereIn('v2_sites.status', Site::$approvedStatuses) ->whereNotIn('v2_site_reports.status', SiteReport::UNSUBMITTED_STATUSES); } diff --git a/app/Models/V2/Sites/Site.php b/app/Models/V2/Sites/Site.php index 100f99621..724aac977 100644 --- a/app/Models/V2/Sites/Site.php +++ b/app/Models/V2/Sites/Site.php @@ -72,6 +72,11 @@ class Site extends Model implements MediaModel, AuditableContract, EntityModel, submitForApproval as entityStatusSubmitForApproval; } + public static array $approvedStatuses = [ + EntityStatusStateMachine::APPROVED, + SiteStatusStateMachine::RESTORATION_IN_PROGRESS, + ]; + public static array $statuses = [ EntityStatusStateMachine::STARTED => 'Started', EntityStatusStateMachine::AWAITING_APPROVAL => 'Awaiting approval', @@ -200,7 +205,7 @@ public function toSearchableArray() */ public function scopeIsApproved(Builder $query): Builder { - return $query->whereIn('status', [EntityStatusStateMachine::APPROVED, SiteStatusStateMachine::RESTORATION_IN_PROGRESS]); + return $query->whereIn('status', self::$approvedStatuses); } /** RELATIONS */ From d5b16226ad225d1750e3946575ee2911799569f0 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 9 Jul 2024 14:29:41 -0700 Subject: [PATCH 3/3] [TM-1093] lint-fix --- app/Models/V2/Projects/Project.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Models/V2/Projects/Project.php b/app/Models/V2/Projects/Project.php index 59f576a79..fd339da90 100644 --- a/app/Models/V2/Projects/Project.php +++ b/app/Models/V2/Projects/Project.php @@ -29,7 +29,6 @@ use App\Models\V2\TreeSpecies\TreeSpecies; use App\Models\V2\Workdays\Workday; use App\Models\V2\Workdays\WorkdayDemographic; -use App\StateMachines\EntityStatusStateMachine; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model;