Ejemplo n.º 1
0
 public static function map(FlightBooking $flightBooking, array $properties)
 {
     if (array_key_exists('id', $properties)) {
         $flightBooking->setId($properties['id']);
     }
     if (array_key_exists('first_name', $properties)) {
         $flightBooking->setFirstName($properties['first_name']);
     }
     if (array_key_exists('no_of_passengers', $properties)) {
         $flightBooking->setNoOfPassengers($properties['no_of_passengers']);
     }
     if (array_key_exists('date', $properties)) {
         $formattedDate = $properties['date'];
         $date = self::createDateTime($formattedDate);
         if ($date) {
             $flightBooking->setDate($date);
         }
     }
 }
Ejemplo n.º 2
0
<?php

$errors = array();
$flightBooking = null;
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $flightBooking = Utils::getFlightBookingByGetId();
} else {
    // set defaults
    $flightBooking = new FlightBooking();
    $flightBooking->setDate(new DateTime());
    //$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'], 'last_name' => $_POST['flight_booking']['last_name']);
    // map
    FlightBookingMapper::map($flightBooking, $data);
    // validate
    $errors = FlightBookingValidator::validate($flightBooking);
    // validate
    if (empty($errors)) {
        // save