2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Models\Acars;
|
2018-01-02 23:40:42 +08:00
|
|
|
use App\Models\Enums\AcarsType;
|
2017-12-28 06:47:22 +08:00
|
|
|
use App\Models\Pirep;
|
|
|
|
use App\Models\Enums\PirepState;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2017-12-28 06:47:22 +08:00
|
|
|
class AcarsRepository extends BaseRepository //implements CacheableInterface
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2017-12-28 06:47:22 +08:00
|
|
|
//use CacheableRepository;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Acars::class;
|
|
|
|
}
|
|
|
|
|
2018-01-02 06:01:01 +08:00
|
|
|
/**
|
|
|
|
* @param $pirep_id
|
|
|
|
* @param $type
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function forPirep($pirep_id, $type)
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2018-01-02 06:01:01 +08:00
|
|
|
$where = [
|
|
|
|
'pirep_id' => $pirep_id,
|
|
|
|
'type' => $type,
|
|
|
|
];
|
|
|
|
|
2018-01-02 23:40:42 +08:00
|
|
|
$order_by = 'created_at';
|
|
|
|
if($type === AcarsType::ROUTE) {
|
|
|
|
$order_by = 'order';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->orderBy('order', 'asc')->findWhere($where);
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
2017-12-28 06:47:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all of the PIREPS that are in-progress, and then
|
|
|
|
* get the latest update for those flights
|
|
|
|
* @return Pirep
|
|
|
|
*/
|
|
|
|
public function getPositions()
|
|
|
|
{
|
|
|
|
return Pirep::with(['airline', 'position'])
|
|
|
|
->where(['state' => PirepState::IN_PROGRESS])
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function getAllAcarsPoints()
|
|
|
|
{
|
|
|
|
return Pirep::with('acars')->where([
|
|
|
|
'state' => PirepState::IN_PROGRESS
|
|
|
|
]);
|
|
|
|
}
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|