Fix flight duplicate detection in add/edit/import; fix active checkbox
This commit is contained in:
@@ -100,6 +100,43 @@ class FlightService extends Service
|
||||
return $flight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this flight has a duplicate already
|
||||
* @param Flight $flight
|
||||
* @return bool
|
||||
*/
|
||||
public function isFlightDuplicate(Flight $flight)
|
||||
{
|
||||
$where = [
|
||||
['id', '<>', $flight->id],
|
||||
'airline_id' => $flight->airline_id,
|
||||
'flight_number' => $flight->flight_number,
|
||||
];
|
||||
|
||||
$found_flights = $this->flightRepo->findWhere($where);
|
||||
if($found_flights->count() === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find within all the flights with the same flight number
|
||||
// Return any flights that have the same route code and leg
|
||||
// If this list is > 0, then this has a duplicate
|
||||
$found_flights = $found_flights->filter(function($value, $key) use ($flight) {
|
||||
if($flight->route_code === $value->route_code
|
||||
&& $flight->route_leg === $value->route_leg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if($found_flights->count() === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a flight, and all the user bids, etc associated with it
|
||||
* @param Flight $flight
|
||||
|
||||
@@ -75,6 +75,19 @@ class FlightImporter extends ImportExport
|
||||
// Get the airline ID from the ICAO code
|
||||
$airline = $this->getAirline($row['airline']);
|
||||
|
||||
// Check if the imported flight is a duplicate
|
||||
$temp_flight = new Flight([
|
||||
'airline_id' => $airline->id,
|
||||
'flight_number' => $row['flight_number'],
|
||||
'route_code' => $row['route_code'],
|
||||
'route_leg' => $row['route_leg'],
|
||||
]);
|
||||
|
||||
if($this->flightSvc->isFlightDuplicate($temp_flight)) {
|
||||
$this->errorLog('Error in row '.$index.': Duplicate flight number detected');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to find this flight
|
||||
$flight = Flight::firstOrNew([
|
||||
'airline_id' => $airline->id,
|
||||
|
||||
Reference in New Issue
Block a user