2017-12-13 01:49:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2018-05-03 04:14:18 +08:00
|
|
|
use App\Models\Enums\PirepStatus;
|
2017-12-13 01:49:35 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
class Pirep extends Response
|
2017-12-13 01:49:35 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
2018-08-27 00:40:04 +08:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2017-12-13 01:49:35 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
2019-07-16 03:14:40 +08:00
|
|
|
$res = parent::toArray($request);
|
|
|
|
$res['ident'] = $this->ident;
|
2018-01-05 11:21:51 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$this->checkUnitFields($res, [
|
|
|
|
'distance',
|
|
|
|
'fuel_used',
|
|
|
|
'planned_distance',
|
|
|
|
]);
|
2018-02-11 12:04:30 +08:00
|
|
|
|
2018-02-12 10:38:56 +08:00
|
|
|
/*
|
|
|
|
* Relationship fields
|
|
|
|
*/
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
if ($this->block_on_time) {
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['block_on_time'] = $this->block_on_time->toIso8601ZuluString();
|
2018-08-27 00:40:04 +08:00
|
|
|
}
|
2018-05-02 11:52:31 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
if ($this->block_off_time) {
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['block_off_time'] = $this->block_off_time->toIso8601ZuluString();
|
2018-08-27 00:40:04 +08:00
|
|
|
}
|
2018-05-02 11:52:31 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['status_text'] = PirepStatus::label($this->status);
|
2018-05-03 04:14:18 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['airline'] = new Airline($this->airline);
|
|
|
|
$res['dpt_airport'] = new Airport($this->dpt_airport);
|
|
|
|
$res['arr_airport'] = new Airport($this->arr_airport);
|
2018-05-03 04:14:18 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['position'] = new Acars($this->position);
|
|
|
|
$res['comments'] = PirepComment::collection($this->comments);
|
|
|
|
$res['user'] = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'id' => $this->user->id,
|
|
|
|
'name' => $this->user->name,
|
2018-01-29 01:12:13 +08:00
|
|
|
'home_airport_id' => $this->user->home_airport_id,
|
|
|
|
'curr_airport_id' => $this->user->curr_airport_id,
|
|
|
|
];
|
2018-01-05 11:21:51 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// format to kvp
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['fields'] = new PirepFieldCollection($this->fields);
|
2018-02-07 03:59:40 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
return $res;
|
2017-12-13 01:49:35 +08:00
|
|
|
}
|
|
|
|
}
|