Select Flight

<<Back to Main Menu

Description:
Searches the flight database and prints out the results. Also searches for flights on ryanair.com if requested.

Accessible by:
All users

Accessed from:
Flight Search Form

Input parameters:
Return/Single
From
To
outDay
outMonth
outYear
inDay
inMonth
inYear
adults
children
class
Max Stopover

Output
Flight Search Form if there are errors.
Select Flight Form form with radio buttons to select the flights the user wants to book.
Each flight has a link to View Flight for managers.

Pseudo Code:
get/create session
get params from the form
if (params are in correct format) {
   save search params in the 'searches' table
   call searchFlight function for outgoing flight
   if ('Return/Single' param == 'Return') {
      call searchFlight function for return flight
   }
}
else {
   display Flight Search Form with error message.
}




function searchFlight(from, to, date, adults, children, class, stopover) {
   check database to see if there's an active Route that fits the criteria
   if (there is such a Route) {
      get all flights flying on that route on 'date'
      if (there are such flights) {
         for each such flight {
            display flight with radio button to book it
         }
      }
      else {
         find the next flight after the required date and next flight before required date but after today's date
         if ((there is flight after desired date) OR (there is a flight before the desired date)) {
            display these flights with a message pointing out the data discrepancy
         }
         else {
            print a message that no results were found
         }
      }
   }
   else {
      check database to see if there's a Complex Route that fits the criteria
      if (there is such a Complex Route) {
         for each such Complex Route {
            for each Route Part {
               if (operator=='ryanair') {
                  get flight data for 'date' from ryanair.com and save for later
                  //best to do this as few times as possible as it is a slow process
               }
            }
            get the Route Parts for the Complex Route
            if ('operator' of the first part == 'AerWeb') {
               get Flights flying on that Route on 'date' and 'date+1' //in case of overnight stopovers
            }
            else {
               use Ryanair flights on 'date' as the first Flights
            }
            if (operator of the second Route Part == 'AerWeb') {
               for each first Flight {
                  get the earliest Flight that departs at least one hour and at most 'stopover' after the first Flight arrives (second Flight)
                  if (there is no such flight) {
                     don't continue searching along this path
                  }
               }            
            }
            else if (operator of the second Route Part == 'Ryanair') {
               for each first Flight {
                  get the earliest Ryanair Flight that departs at least one hour and at most 'stopover' after the first Flight arrives (second Flight)
                  if (there is no such flight) {
                     don't continue searching along this path
                  }
               }
            }
            if (there is a third part to the Complex Route) {
               for each second flight {
                  if (operator of the third Route Part == 'AerWeb') {
                     for each second Flight {
                        get the earliest Flight that departs at least one hour and at most 'stopover' after the second Flight arrives (third Flight)
                        if (there is no such flight) {
                           don't continue searching along this path
                        }
                     }            
                  }
                  else if (operator of the third Route Part == 'Ryanair') {
                     for each second Flight {
                        get the earliest Ryanair Flight that departs at least one hour and at most 'stopover' after the second Flight arrives (third Flight)
                        if (there is no such flight) {
                           don't continue searching along this path
                        }
                     }
                  }
               }
            }
            if (we have found any suitable Flight combinations) {
               sort the list by the length of time from the departure of the first flight to the arrival of the second (taking timezones into account)
               while (the next shortest combination available hasn't enough seats on it) {
                  display the combination with a message that there aren't enough seats
               }
               display the next combination with a radio button to book it
            }
            else {
               display message that no results were found
            }
         }
      }
      else {
         display message that no results were found
      }
   }
}