2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Repository;
|
2017-12-26 05:19:34 +08:00
|
|
|
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\Enums\PirepState;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Pirep;
|
2018-05-16 23:54:01 +08:00
|
|
|
use Carbon\Carbon;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class AcarsRepository
|
|
|
|
* @package App\Repositories
|
|
|
|
*/
|
|
|
|
class AcarsRepository extends Repository
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
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,
|
2018-03-20 09:50:40 +08:00
|
|
|
'type' => $type,
|
2018-01-02 06:01:01 +08:00
|
|
|
];
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
switch ($type) {
|
2018-02-22 05:15:12 +08:00
|
|
|
default:
|
|
|
|
case AcarsType::FLIGHT_PATH:
|
|
|
|
case AcarsType::LOG:
|
|
|
|
$order_by = 'created_at';
|
|
|
|
break;
|
|
|
|
case AcarsType::ROUTE:
|
|
|
|
$order_by = 'order';
|
|
|
|
break;
|
2018-01-02 23:40:42 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 05:15:12 +08:00
|
|
|
return $this->orderBy($order_by, '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
|
2018-05-16 23:54:01 +08:00
|
|
|
* @param int $live_time Age in hours of the oldest flights to show
|
2017-12-28 06:47:22 +08:00
|
|
|
* @return Pirep
|
|
|
|
*/
|
2018-05-16 23:54:01 +08:00
|
|
|
public function getPositions($live_time = 0)
|
2017-12-28 06:47:22 +08:00
|
|
|
{
|
2018-05-16 23:54:01 +08:00
|
|
|
$q = Pirep::with(['airline', 'position', 'aircraft'])
|
|
|
|
->where(['state' => PirepState::IN_PROGRESS]);
|
|
|
|
|
|
|
|
if($live_time !== null && $live_time > 0) {
|
|
|
|
$st = Carbon::now('UTC')->subHours($live_time);
|
|
|
|
$q = $q->whereDate('created_at', '>=', $st);
|
|
|
|
}
|
|
|
|
|
|
|
|
$q = $q->orderBy('created_at', 'desc');
|
|
|
|
return $q->get();
|
2017-12-28 06:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function getAllAcarsPoints()
|
|
|
|
{
|
|
|
|
return Pirep::with('acars')->where([
|
|
|
|
'state' => PirepState::IN_PROGRESS
|
|
|
|
]);
|
|
|
|
}
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|