Beispiel #1
0
 /**
  * Find {@link Todo} by identifier.
  * @return Todo Todo or <i>null</i> if not found
  */
 public function findById($id)
 {
     $row = $this->query('SELECT * FROM flight_bookings WHERE id = ' . (int) $id)->fetch();
     if (!$row) {
         return null;
     }
     $flightBooking = new FlightBooking();
     FlightBookingMapper::map($flightBooking, $row);
     return $flightBooking;
 }
 /**
  * @return PDOStatement
  */
 public function find($status = null)
 {
     $result = array();
     $sql = 'SELECT id, first_name, no_of_passengers, last_name, flight_date FROM flight_bookings WHERE ' . 'status = "' . $status . '";';
     foreach ($this->query($sql) as $row) {
         $flightBooking = new FlightBooking();
         FlightBookingMapper::map($flightBooking, $row);
         $result[$flightBooking->getId()] = $flightBooking;
     }
     return $result;
 }
    $flightBooking = Utils::getFlightBookingByGetId();
} else {
    // set defaults
    $flightBooking = new FlightBooking();
    //$flightBooking->setPriority(Todo::PRIORITY_MEDIUM);
    //$dueOn = new DateTime("+1 day");
    //$dueOn->setTime(0, 0, 0);
    //$flightBooking->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    //Utils::redirect('detail', array('id' => $flightBooking->getId()));
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['todo']
    //pretending to have values in $_POST
    //    $data = array('first_name' => 'Mary', 'no_of_passengers' => 4);
    $data = array('first_name' => $_POST['flight_booking']['first_name'], 'no_of_passengers' => $_POST['flight_booking']['no_of_passengers'], 'last_name' => $_POST['flight_booking']['last_name'], 'flight_date' => $_POST['flight_booking']['flight_date']);
    // map
    FlightBookingMapper::map($flightBooking, $data);
    // validate
    $errors = FlightBookingValidator::validate($flightBooking);
    // validate
    if (empty($errors)) {
        // save
        $dao = new FlightBookingDao();
        $flightBooking = $dao->save($flightBooking);
        Flash::addFlash('Success Booking :)');
        // redirect
        Utils::redirect('home');
    }
}