Add days of week to flights table; add to import/export for flights

This commit is contained in:
Nabeel Shahzad
2018-03-22 21:21:35 -05:00
parent 8b53ca2fdc
commit 7105e82922
17 changed files with 310 additions and 21 deletions

View File

@@ -25,10 +25,10 @@ class AircraftStatus extends Enum
];
public static $codes = [
'S' => AircraftStatus::STORED,
'A' => AircraftStatus::ACTIVE,
'R' => AircraftStatus::RETIRED,
'C' => AircraftStatus::SCRAPPED,
'W' => AircraftStatus::WRITTEN_OFF,
AircraftStatus::STORED => 'S',
AircraftStatus::ACTIVE => 'A' ,
AircraftStatus::RETIRED => 'R',
AircraftStatus::SCRAPPED => 'C',
AircraftStatus::WRITTEN_OFF => 'W',
];
}

View File

@@ -6,6 +6,7 @@ use App\Interfaces\Enum;
/**
* Class Days
* Start on Monday - ISO8601
* @package App\Models\Enums
*/
class Days extends Enum
@@ -18,7 +19,7 @@ class Days extends Enum
public const SATURDAY = 1 << 5;
public const SUNDAY = 1 << 6;
protected static $labels = [
public static $labels = [
Days::MONDAY => 'system.days.mon',
Days::TUESDAY => 'system.days.tues',
Days::WEDNESDAY => 'system.days.wed',
@@ -27,4 +28,40 @@ class Days extends Enum
Days::SATURDAY => 'system.days.sat',
Days::SUNDAY => 'system.days.sun',
];
public static $codes = [
'M' => Days::MONDAY,
'T' => Days::TUESDAY,
'W' => Days::WEDNESDAY,
'Th' => Days::THURSDAY,
'F' => Days::FRIDAY,
'S' => Days::SATURDAY,
'Su' => Days::SUNDAY,
];
/**
* Create the masked value for the days of week
* @param array $days
* @return int|mixed
*/
public static function getDaysMask(array $days)
{
$mask = 0;
foreach($days as $day) {
$mask |= $day;
}
return $mask;
}
/**
* See if the given mask has a day
* @param $mask
* @param $day
* @return bool
*/
public static function in($mask, $day): bool
{
return ($mask & $day) === $day;
}
}

View File

@@ -21,8 +21,8 @@ class ExpenseType extends Enum
];
protected static $codes = [
'F' => ExpenseType::FLIGHT,
'D' => ExpenseType::DAILY,
'M' => ExpenseType::MONTHLY,
ExpenseType::FLIGHT => 'F',
ExpenseType::DAILY =>'D',
ExpenseType::MONTHLY => 'M',
];
}

View File

@@ -21,8 +21,8 @@ class FlightType extends Enum
];
protected static $codes = [
'P' => FlightType::PASSENGER,
'C' => FlightType::CARGO,
'H' => FlightType::CHARTER,
FlightType::PASSENGER => 'P',
FlightType::CARGO => 'C',
FlightType::CHARTER => 'H',
];
}

View File

@@ -14,7 +14,7 @@ class FuelType extends Enum
public const JET_A = 1;
public const MOGAS = 2;
protected static $labels = [
public static $labels = [
FuelType::LOW_LEAD => '100LL',
FuelType::JET_A => 'JET A',
FuelType::MOGAS => 'MOGAS',

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\Days;
use App\Models\Traits\HashIdTrait;
use App\Support\Units\Distance;
use Illuminate\Support\Collection;
@@ -18,6 +19,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
* @property Collection field_values
* @property Collection fares
* @property Collection subfleets
* @property integer days
*/
class Flight extends Model
{
@@ -40,6 +42,7 @@ class Flight extends Model
'alt_airport_id',
'dpt_time',
'arr_time',
'days',
'level',
'distance',
'flight_time',
@@ -52,6 +55,7 @@ class Flight extends Model
protected $casts = [
'flight_number' => 'integer',
'days' => 'integer',
'level' => 'integer',
'distance' => 'float',
'flight_time' => 'integer',
@@ -70,6 +74,22 @@ class Flight extends Model
'level' => 'nullable',
];
/**
* Return all of the flights on any given day(s) of the week
* Search using bitmasks
* @param Days[] $days List of the enumerated values
* @return Flight
*/
public static function findByDays(array $days)
{
$flights = Flight::where('active', true);
foreach($days as $day) {
$flights = $flights->where('days', '&', $day);
}
return $flights;
}
/**
* Get the flight ident, e.,g JBU1900
*/
@@ -125,6 +145,15 @@ class Flight extends Model
}
}
/**
* @param $day
* @return bool
*/
public function on_day($day): bool
{
return ($this->days & $day) === $day;
}
/**
* Return a custom field value
* @param $field_name