public function stageEnterCredentials()
 {
     $valid = true;
     $booking = new BookingForm();
     if (isset($_POST['BookingForm'])) {
         $booking->attributes = $_POST['BookingForm'];
         $valid = $booking->validate() && $valid;
     } else {
         $valid = false;
     }
     $passport = new AviaPassportForm();
     if (isset($_POST['PassportForm'])) {
         $passport->attributes = $_POST['PassportForm'];
         $valid = $valid && $passport->validate();
     }
     if ($valid) {
         //saving data to objects
         $bookingAr = new Booking();
         $bookingAr->email = $booking->contactEmail;
         $bookingAr->phone = $booking->contactPhone;
         if (!Yii::app()->user->isGuest) {
             $bookingAr->userId = Yii::app()->user->id;
         }
         $bookingPassports = array();
         $bookingPassport = new BookingPassport();
         $bookingPassport->birthday = $passport->birthday;
         $bookingPassport->firstName = $passport->firstName;
         $bookingPassport->lastName = $passport->lastName;
         $bookingPassport->countryId = $passport->countryId;
         $bookingPassport->number = $passport->number;
         $bookingPassport->series = $passport->series;
         $bookingPassport->genderId = $passport->genderId;
         $bookingPassport->documentTypeId = $passport->documentTypeId;
         $bookingPassports[] = $bookingPassport;
         $bookingAr->bookingPassports = $bookingPassports;
         $bookingAr->flightId = Yii::app()->flightBooker->current->flightVoyage->flightKey;
         if ($bookingAr->save()) {
             Yii::app()->flightBooker->current->bookingId = $bookingAr->id;
             Yii::app()->flightBooker->status('booking');
             $this->refresh();
         } else {
             $this->render('enterCredentials', array('passport' => $passport, 'booking' => $booking));
         }
     } else {
         $this->render('enterCredentials', array('passport' => $passport, 'booking' => $booking));
     }
 }
 public function httpPostMethod(Http $http, array $formFields)
 {
     /*
      * Méthode appelée en cas de requête HTTP POST
      *
      * L'argument $http est un objet permettant de faire des redirections etc.
      * L'argument $formFields contient l'équivalent de $_POST en PHP natif.
      */
     /*$date = new DateModel();
     		var_dump($date->testDate($formFields['dateResa'])); //0 FAUX - 1 VRAI REJEX */
     try {
         $userSession = new UserSession();
         if ($userSession->isAuthenticated()) {
             $dateTime = date_create($formFields['dateResa'] . ' ' . $formFields['timeResa']);
             if ($dateTime == false) {
                 throw new InvalidArgumentException(BookingModel::$dateException);
             }
             $now = new DateTime("now");
             $resaDate = date_format($dateTime, 'Y-m-d');
             $resaTime = date_format($dateTime, 'H:i:s');
             //var_dump($formFields);
             if (!empty($formFields['dateResa']) && !empty($formFields['timeResa']) && !empty($formFields['NumberOfSeats']) && $dateTime > $now && ctype_digit($formFields['NumberOfSeats'])) {
                 $userId = $userSession->getId();
                 $booking = new BookingModel();
                 $resultat = $booking->register($userId, $resaDate, $resaTime, $formFields['NumberOfSeats']);
                 $flashBag = new FlashBag();
                 $flashBag->add("Votre réservation numero {$resultat} du {$resaDate} à {$resaTime} pour " . $formFields['NumberOfSeats'] . " est bien pris en compte");
                 $http->redirectTo('/');
             } elseif ($dateTime < $now) {
                 throw new InvalidArgumentException(BookingModel::$PasseDateException);
             } else {
                 throw new InvalidArgumentException(BookingModel::$FieldsException);
             }
         } else {
             $http->redirectTo('/');
         }
     } catch (InvalidArgumentException $event) {
         //var_dump($event);
         $form = new BookingForm();
         $form->bind($formFields);
         $form->setErrorMessage($event->getMessage());
         return ['_form' => $form];
     }
 }
 public function executeAjxCheckBooking(sfWebRequest $request)
 {
     // To use url_for() helper ...
     // $this->getContext()->getConfiguration()->loadHelpers('Url');
     $app = Doctrine_Core::getTable('Apartment')->find($request->getPostParameter('apid'));
     $booking = new Booking();
     $booking->date_from = $request->getPostParameter('start_date');
     $booking->date_to = date("Y-m-d", strtotime($request->getPostParameter('start_date')) + 86400 * ($request->getParameter('days') + 1));
     $booking->CheckBookingPossibility($app, $request->getPostParameter('pax'));
     if ($request->isXmlHttpRequest()) {
         if ($this->getUser()->isAuthenticated() && is_object($booking)) {
             /* Forward to action */
             $this->forward('booking', 'NewBooking');
         } else {
             $form = new BookingForm();
             $form->PublicBookingForm($app);
             $callback_url = 'http://localhost/symfonybooking/web/frontend_dev.php/en/apartment/' . $app->getId();
             return $this->renderPartial('booking/booking_form', array('form' => $form, 'sign_in' => true, 'callback' => $callback_url));
         }
     } else {
         return sfView::NONE;
         /* Log this !*/
     }
 }
 public function execute()
 {
     $valid = false;
     //collecting booking info for whole ticket
     $booking = new BookingForm();
     if (isset($_POST['BookingForm'])) {
         $valid = true;
         $booking->attributes = $_POST['BookingForm'];
         $valid = $valid && $booking->validate();
     }
     //collecting adults passport data
     $adults = Yii::app()->flightBooker->getCurrent()->FlightVoyage->adultPassengerInfo;
     $adultPassports = array();
     if ($adults) {
         $countAdults = $adults->count;
         for ($i = 0; $i < $countAdults; $i++) {
             $adultPassports[] = new FlightAdultPassportForm();
         }
         $isOk = $this->collect('FlightAdultPassportForm', $adultPassports);
         $valid = $valid && $isOk;
     }
     //collecting child passport data
     $children = Yii::app()->flightBooker->getCurrent()->FlightVoyage->childPassengerInfo;
     $childrenPassports = array();
     if ($children) {
         $countChildren = $children->count;
         for ($i = 0; $i < $countChildren; $i++) {
             $childrenPassports[] = new FlightChildPassportForm();
         }
         $isOk = $this->collect('FlightChildPassportForm', $childrenPassports);
         $valid = $valid && $isOk;
     }
     //collecting infant passport data
     $infant = Yii::app()->flightBooker->getCurrent()->FlightVoyage->infantPassengerInfo;
     $infantPassports = array();
     if ($infant) {
         $infantChildren = $infant->count;
         for ($i = 0; $i < $infantChildren; $i++) {
             $infantPassports[] = new FlightInfantPassportForm();
         }
         $isOk = $this->collect('FlightInfantPassportForm', $infantPassports);
         $valid = $valid && $isOk;
     }
     if ($valid) {
         //saving data to objects
         //TODO: link to OrderBooking object
         $flightBookerComponent = Yii::app()->flightBooker;
         $flightBookerComponent->book();
         $flightBookerId = $flightBookerComponent->getCurrent()->primaryKey;
         $bookingAr = new OrderBooking();
         $bookingAr->populate($booking);
         if (!Yii::app()->user->isGuest) {
             $bookingAr->userId = Yii::app()->user->id;
         }
         $bookingPassports = array();
         $allPassports = array_merge($adultPassports, $childrenPassports, $infantPassports);
         foreach ($allPassports as $passport) {
             $bookingPassport = new FlightBookingPassport();
             $bookingPassport->populate($passport, $flightBookerId);
             if (!$bookingPassport->save()) {
                 VarDumper::dump($bookingPassport->getErrors());
             } else {
                 $bookingPassports[] = $bookingPassport;
             }
         }
         if ($bookingAr->save()) {
             Yii::app()->flightBooker->getCurrent()->orderBookingId = $bookingAr->id;
             Yii::app()->flightBooker->status('booking');
         } else {
             VarDumper::dump($bookingAr->getErrors());
             $this->getController()->render('flightBooker.views.enterCredentials', array('passport' => $passport, 'booking' => $booking));
         }
     } else {
         $this->getController()->render('flightBooker.views.enterCredentials', array('adultPassports' => $adultPassports, 'childrenPassports' => $childrenPassports, 'infantPassports' => $infantPassports, 'booking' => $booking));
     }
 }