Skip to content

Commit

Permalink
feat: add CTS theory exam back to waiting list view (#3307)
Browse files Browse the repository at this point in the history
  • Loading branch information
AxonC authored Oct 31, 2023
1 parent 4e6a274 commit 71dae86
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ public function form(Form $form): Form
})
->visible(fn ($record) => $record->pivot->flags->filter(fn ($flag) => $flag->endorsement_id != null)->isNotEmpty()),

Forms\Components\Fieldset::make('cts_theory_exam')
->label('CTS Theory Exam')
->schema(function ($record) {
return [
Forms\Components\Toggle::make('cts_theory_exam')
->label('Passed')
->afterStateHydrated(fn ($component, $state) => $component->state((bool) $record->pivot->theory_exam_passed))
->disabled(),
];
})
->visible(fn ($record) => $record->waitingList->feature_toggles['check_cts_theory_exam'] ?? true),

Forms\Components\Fieldset::make('manual_flags')
->label('Manual Flags')
->schema(function ($record) {
Expand Down Expand Up @@ -106,6 +118,7 @@ public function table(Table $table): Table
Tables\Columns\TextColumn::make('account_id')->label('CID')->searchable(),
Tables\Columns\TextColumn::make('name')->label('Name')->searchable(['name_first', 'name_last']),
Tables\Columns\TextColumn::make('pivot.created_at')->label('Added on')->dateTime('M dS Y'),
Tables\Columns\IconColumn::make('pivot.cts_theory_exam')->boolean()->label('CTS Theory Exam')->getStateUsing(fn ($record) => $record->pivot->theory_exam_passed)->visible(fn ($record) => $record->waitingList->feature_toggles['check_cts_theory_exam'] ?? true),
Tables\Columns\IconColumn::make('pivot.atc_hour_check')->boolean()->label('Hour check')->getStateUsing(fn ($record) => Arr::get($record->pivot?->eligibility_summary, 'base_controlling_hours')),
Tables\Columns\IconColumn::make('pivot.flags_check')->boolean()->label('Flags check')->getStateUsing(fn ($record) => (bool) Arr::get($record->pivot?->flags_status_summary, 'overall')),
Tables\Columns\IconColumn::make('pivot.eligible')->boolean()->label('Eligible')->getStateUsing(fn ($record) => $record->pivot->eligible),
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Cts/TheoryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function forAccount(int $account_id): ?Collection
try {
$memberId = Member::where('cid', $account_id)->firstOrFail()->id;
} catch (ModelNotFoundException) {
Log::warning("No member found for account_id ${$account_id}. Likely sync problems.");
Log::warning("No member found for account_id {$account_id}. Likely sync problems.");

return null;
}
Expand Down
49 changes: 38 additions & 11 deletions app/Models/Training/WaitingList/WaitingListAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Models\NetworkData\Atc;
use App\Models\Training\WaitingList;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;
Expand All @@ -20,7 +22,7 @@ class WaitingListAccount extends Pivot

public $fillable = ['added_by', 'deleted_at', 'notes', 'eligible', 'flags_status_summary', 'eligibility_summary'];

protected $appends = ['atcHourCheck'];
protected $appends = ['atcHourCheck', 'theory_exam_passed'];

protected $casts = [
'eligible' => 'boolean',
Expand Down Expand Up @@ -176,23 +178,48 @@ public function allFlagsChecker()
return true;
}

public function getTheoryExamPassedAttribute(): ?bool
public function theoryExamPassed(): Attribute
{
if ($this->waitingList->department === WaitingList::PILOT_DEPARTMENT || ! $this->waitingList->cts_theory_exam_level) {
return null;
}
$passed = false;

$result = TheoryResult::forAccount($this->account_id);
if ($this->waitingList->department === WaitingList::ATC_DEPARTMENT) {
try {
$result = TheoryResult::forAccount($this->account_id);
} catch (ModelNotFoundException) {
return Attribute::make(
get: fn () => false,
);
}

if (! $result || ! $result->count()) {
return null;
if ($result && $result->count()) {
$passed = $result
->where('exam', $this->waitingList->cts_theory_exam_level)
->where('pass', true)->count() > 0;
}
}

return $result
->where('exam', $this->waitingList->cts_theory_exam_level)
->where('pass', true)->count() > 0;
return Attribute::make(
get: fn () => $passed,
);
}

// public function getTheoryExamPassedAttribute(): ?bool
// {
// if ($this->waitingList->department === WaitingList::PILOT_DEPARTMENT || ! $this->waitingList->cts_theory_exam_level) {
// return null;
// }

// $result = TheoryResult::forAccount($this->account_id);

// if (! $result || ! $result->count()) {
// return null;
// }

// return $result
// ->where('exam', $this->waitingList->cts_theory_exam_level)
// ->where('pass', true)->count() > 0;
// }

public function setNotesAttribute($value)
{
$this->attributes['notes'] = (string) $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function itShouldDetectWhenTheoryExamFailed()
}

/** @test */
public function itShouldReturnNullWhenPilotWaitingList()
public function itShouldReturnFalseWhenPilotWaitingList()
{
$waitingList = factory(WaitingList::class)->create([
'cts_theory_exam_level' => null,
Expand All @@ -75,7 +75,7 @@ public function itShouldReturnNullWhenPilotWaitingList()

$waitingList->addToWaitingList($this->account, $this->privacc);

$this->assertNull($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
$this->assertFalse($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
}

/** @test */
Expand All @@ -87,7 +87,7 @@ public function itShouldReturnNullWhenNoExamConfigured()

$waitingList->addToWaitingList($this->account, $this->privacc);

$this->assertNull($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
$this->assertFalse($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
}

/** @test */
Expand All @@ -99,7 +99,7 @@ public function itShouldReturnNullWhenNoTheoryResultFound()

$waitingList->addToWaitingList($this->account, $this->privacc);

$this->assertNull($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
$this->assertFalse($waitingList->accounts->find($this->account->id)->pivot->theoryExamPassed);
}

/** @test */
Expand Down

0 comments on commit 71dae86

Please sign in to comment.