Convert aircraft active to more detailed status #134
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Enums\AircraftStatus;
|
||||
use App\Support\ICAO;
|
||||
|
||||
class Aircraft extends BaseModel
|
||||
@@ -16,7 +17,8 @@ class Aircraft extends BaseModel
|
||||
'registration',
|
||||
'hex_code',
|
||||
'zfw',
|
||||
'active',
|
||||
'status',
|
||||
'state',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -27,7 +29,8 @@ class Aircraft extends BaseModel
|
||||
protected $casts = [
|
||||
'subfleet_id' => 'integer',
|
||||
'zfw' => 'float',
|
||||
'active' => 'boolean',
|
||||
'status' => 'integer',
|
||||
'state' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -57,6 +60,11 @@ class Aircraft extends BaseModel
|
||||
});
|
||||
}
|
||||
|
||||
public function getActiveAttribute()
|
||||
{
|
||||
return $this->status === AircraftStatus::ACTIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* foreign keys
|
||||
*/
|
||||
|
||||
24
app/Models/Enums/AircraftStatus.php
Normal file
24
app/Models/Enums/AircraftStatus.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Enums;
|
||||
|
||||
/**
|
||||
* Class AircraftState
|
||||
* @package App\Models\Enums
|
||||
*/
|
||||
class AircraftStatus extends EnumBase
|
||||
{
|
||||
public const STORED = 0;
|
||||
public const ACTIVE = 1;
|
||||
public const RETIRED = 2;
|
||||
public const SCRAPPED = 3;
|
||||
public const WRITTEN_OFF = 4;
|
||||
|
||||
public static $labels = [
|
||||
AircraftStatus::STORED => 'Stored',
|
||||
AircraftStatus::ACTIVE => 'Active',
|
||||
AircraftStatus::RETIRED => 'Retired',
|
||||
AircraftStatus::SCRAPPED => 'Scrapped',
|
||||
AircraftStatus::WRITTEN_OFF => 'Written Off',
|
||||
];
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Enums\AircraftStatus;
|
||||
|
||||
/**
|
||||
* Class Subfleet
|
||||
* @package App\Models
|
||||
@@ -42,8 +44,8 @@ class Subfleet extends BaseModel
|
||||
];
|
||||
|
||||
/**
|
||||
* Modify some fields on the fly. Make sure the subfleet
|
||||
* names don't have spaces in them.
|
||||
* Modify some fields on the fly. Make sure the subfleet names don't
|
||||
* have spaces in them, so the csv import/export can use the types
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
@@ -51,7 +53,8 @@ class Subfleet extends BaseModel
|
||||
|
||||
static::creating(function ($model) {
|
||||
if (filled($model->type)) {
|
||||
$model->type = str_replace(' ', '_', $model->type);
|
||||
$model->type = str_replace(' ', '-', $model->type);
|
||||
$model->type = str_replace(',', '', $model->type);
|
||||
}
|
||||
|
||||
if(!filled($model->ground_handling_multiplier)) {
|
||||
@@ -61,7 +64,8 @@ class Subfleet extends BaseModel
|
||||
|
||||
static::updating(function ($model) {
|
||||
if (filled($model->type)) {
|
||||
$model->type = str_replace(' ', '_', $model->type);
|
||||
$model->type = str_replace(' ', '-', $model->type);
|
||||
$model->type = str_replace(',', '', $model->type);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -72,7 +76,8 @@ class Subfleet extends BaseModel
|
||||
|
||||
public function aircraft()
|
||||
{
|
||||
return $this->hasMany(Aircraft::class, 'subfleet_id');
|
||||
return $this->hasMany(Aircraft::class, 'subfleet_id')
|
||||
->where('status', AircraftStatus::ACTIVE);
|
||||
}
|
||||
|
||||
public function airline()
|
||||
|
||||
Reference in New Issue
Block a user