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

@@ -3,6 +3,7 @@
namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Enums\Days;
use App\Models\Enums\FlightType;
use App\Models\Flight;
@@ -39,6 +40,7 @@ class FlightExporter extends ImportExport
$ret['airline'] = $ret['airline']->icao;
$ret['distance'] = $ret['distance']->toNumber();
$ret['days'] = $this->getDays($flight);
$ret['flight_type'] = FlightType::convertToCode($ret['flight_type']);
$ret['fares'] = $this->getFares($flight);
@@ -48,6 +50,46 @@ class FlightExporter extends ImportExport
return $ret;
}
/**
* Return the days string
* @param Flight $flight
* @return string
*/
protected function getDays(Flight &$flight)
{
$days_str = '';
if($flight->on_day(Days::MONDAY)) {
$days_str .= '1';
}
if ($flight->on_day(Days::TUESDAY)) {
$days_str .= '2';
}
if ($flight->on_day(Days::WEDNESDAY)) {
$days_str .= '3';
}
if ($flight->on_day(Days::THURSDAY)) {
$days_str .= '4';
}
if ($flight->on_day(Days::FRIDAY)) {
$days_str .= '5';
}
if ($flight->on_day(Days::SATURDAY)) {
$days_str .= '6';
}
if ($flight->on_day(Days::SUNDAY)) {
$days_str .= '7';
}
return $days_str;
}
/**
* Return any custom fares that have been made to this flight
* @param Flight $flight

View File

@@ -4,6 +4,7 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Airport;
use App\Models\Enums\Days;
use App\Models\Enums\FlightType;
use App\Models\Fare;
use App\Models\Flight;
@@ -83,6 +84,7 @@ class FlightImporter extends ImportExport
], $row);
// Airport atttributes
$flight->setAttribute('days', $this->setDays($row['days']));
$flight->setAttribute('dpt_airport_id', $row['dpt_airport']);
$flight->setAttribute('arr_airport_id', $row['arr_airport']);
if ($row['alt_airport']) {
@@ -116,6 +118,49 @@ class FlightImporter extends ImportExport
return true;
}
/**
* Return the mask of the days
* @param $day_str
* @return int|mixed
*/
protected function setDays($day_str)
{
if(!$day_str) {
return 0;
}
$days = [];
if(strpos($day_str, '1') !== false) {
$days[] = Days::MONDAY;
}
if (strpos($day_str, '2') !== false) {
$days[] = Days::TUESDAY;
}
if (strpos($day_str, '3') !== false) {
$days[] = Days::WEDNESDAY;
}
if (strpos($day_str, '4') !== false) {
$days[] = Days::THURSDAY;
}
if (strpos($day_str, '5') !== false) {
$days[] = Days::FRIDAY;
}
if (strpos($day_str, '6') !== false) {
$days[] = Days::SATURDAY;
}
if (strpos($day_str, '7') !== false) {
$days[] = Days::SUNDAY;
}
return Days::getDaysMask($days);
}
/**
* Process the airport
* @param $airport