phpvms/app/Widgets/LatestPireps.php
B.Fatih KOZ c2b0b69eb2
Change LatestPireps Widget Sort Order (#1099)
* Change LatestPireps Widget Sort Order

Latest pireps should be ordered by `submitted_at` instead of `created_at` . 

Pirep may be created even a day before others (with the pause/resume ability we have in acars) but it gets submitted once when the flight is ended, thus I think it should be our reference to sort them in proper order.

* Trying to Pass UnitTest
2021-03-25 09:51:16 -04:00

41 lines
928 B
PHP

<?php
namespace App\Widgets;
use App\Contracts\Widget;
use App\Models\Enums\PirepState;
use App\Repositories\PirepRepository;
/**
* Show the latest PIREPs in a view
* sorted nicely by their submit time
*/
class LatestPireps extends Widget
{
protected $config = [
'count' => 5,
];
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function run()
{
$pirepRepo = app(PirepRepository::class);
$pireps = $pirepRepo
->with(['airline', 'aircraft'])
->whereNotInOrder('state', [
PirepState::CANCELLED,
PirepState::DRAFT,
PirepState::IN_PROGRESS,
], 'submitted_at', 'desc')
->recent($this->config['count']);
return view('widgets.latest_pireps', [
'config' => $this->config,
'pireps' => $pireps,
]);
}
}