Convert aircraft active to more detailed status #134

This commit is contained in:
Nabeel Shahzad
2018-02-23 16:37:10 -06:00
parent 709aec83e2
commit 910c0e0eab
9 changed files with 91 additions and 34 deletions

View File

@@ -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
*/

View 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',
];
}

View File

@@ -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()