public static function validate(FlightBooking $flightBooking) { $errors = array(); if (!trim($flightBooking->getFirstName())) { $errors[] = new Error('first_name', 'First name cannot be empty.'); } return $errors; }
public static function validate(FlightBooking $flightBooking) { $errors = array(); if (!trim($flightBooking->getTitle())) { $errors[] = new Error('title', 'Title cannot be empty.'); } return $errors; }
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']); } }
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); } } }
private function getParams(FlightBooking $flightBooking) { $params = array(':id' => $flightBooking->getId(), ':first_name' => $flightBooking->getFirstName(), ':no_of_passengers' => $flightBooking->getNoOfPassengers(), ':status' => $flightBooking->getStatus()); // if ($flightBooking->getId()) { // // unset created date, this one is never updated // unset($params[':created_on']); // } return $params; }
private static function isValidStatus($status) { return in_array($status, FlightBooking::allStatuses()); }
private function getParams(FlightBooking $flightBooking) { $params = array(':id' => $flightBooking->getId(), ':first_name' => $flightBooking->getFirstName(), ':last_name' => $flightBooking->getLastName()); // if ($flightBooking->getId()) { // // unset created date, this one is never updated // unset($params[':created_on']); // } return $params; }
<?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