Esempio n. 1
0
 public function restoreOrderBookingFromDb($orderBookingId)
 {
     $orderBooking = OrderBooking::model()->findByPk($orderBookingId);
     if (!$orderBooking) {
         throw new CException("No such order");
     }
     $flights = $orderBooking->flightBookers;
     $hotels = $orderBooking->hotelBookers;
     Yii::app()->{$this->shoppingCartComponent}->clear();
     foreach ($flights as $flight) {
         $flightVoyage = unserialize($flight->flightVoyageInfo);
         $searchParams = @unserialize($flight->searchParams);
         $flightTripElement = new FlightTripElement();
         $flightTripElement->flightVoyage = $flightVoyage;
         $flightTripElement->flightBookerId = $flight->id;
         if ($searchParams) {
             $flightTripElement->fillFromSearchParams($searchParams);
         }
         Yii::app()->{$this->shoppingCartComponent}->put($flightTripElement);
     }
     foreach ($hotels as $hotel) {
         $hotelInfo = unserialize($hotel->hotelInfo);
         $searchParams = @unserialize($hotel->searchParams);
         $hotelTripElement = new HotelTripElement();
         $hotelTripElement->hotel = $hotelInfo;
         $hotelTripElement->hotelBookerId = $hotel->id;
         if ($searchParams) {
             $hotelTripElement->fillFromSearchParams($searchParams);
         }
         Yii::app()->{$this->shoppingCartComponent}->put($hotelTripElement);
     }
 }
Esempio n. 2
0
 public function forFlightItem($item)
 {
     $flightBooker = FlightBooker::model()->findByPk($item->flightBookerId);
     $flightPassports = FlightBookingPassport::model()->findAllByAttributes(array('flightBookingId' => $item->flightBookerId));
     if ($flightBooker) {
         if (!$this->orderBookingId) {
             $this->orderBookingId = $flightBooker->orderBookingId;
             $this->orderBooking = OrderBooking::model()->findByPk($this->orderBookingId);
         }
         $pdfFileName = $this->controller->renderPdf('ticketAvia', array('type' => 'avia', 'ticket' => $flightBooker->flightVoyage, 'bookingId' => $this->orderBooking->readableId, 'pnr' => $flightBooker->pnr, 'flightPassports' => $flightPassports));
         return array('realName' => $pdfFileName, 'visibleName' => "avia_{$flightBooker->flightVoyage->departureCity->code}_{$flightBooker->flightVoyage->arrivalCity->code}_" . date('Ymd', strtotime($flightBooker->flightVoyage->departureDate)) . ".pdf");
     }
 }
Esempio n. 3
0
 public function actionStatus($id)
 {
     $secretKey = $id;
     $this->layout = 'static';
     $orderBooking = OrderBooking::model()->findByAttributes(array('secretKey' => $secretKey));
     if (!$orderBooking) {
         throw new CHttpException(404, 'Page not found');
     }
     $statuses = array();
     foreach ($orderBooking->flightBookers as $flightBooker) {
         $flightVoyage = $flightBooker->getFlightVoyage();
         $id = $flightVoyage->getId();
         $statuses[$id] = $this->normalizeStatus($flightBooker->status);
     }
     foreach ($orderBooking->hotelBookers as $hotelBooker) {
         $hotel = $hotelBooker->getHotel();
         $id = $hotel->getId();
         $statuses[$id] = $this->normalizeStatus($hotelBooker->status);
     }
     echo json_encode($statuses);
 }
Esempio n. 4
0
 protected function updateOrderBookingInfo()
 {
     if (!self::$bookingContactInfo) {
         $orderBookingId = Yii::app()->user->getState('orderBookingId');
         $orderBooking = OrderBooking::model()->findByPk($orderBookingId);
         if (!$orderBooking) {
             throw new CHttpException(500, "Your order is gone away");
         }
         self::$bookingContactInfo = $orderBooking;
         self::$bookingContactInfo->attributes = $this->getBookingContactFormData();
         $user = Yii::app()->user->getUserWithEmail(self::$bookingContactInfo->email);
         self::$bookingContactInfo->userId = $user->id;
         if (!self::$bookingContactInfo->save()) {
             $errMsg = 'Saving of order booking fails: ' . CVarDumper::dumpAsString($this->bookingContactInfo->errors);
             $this->logAndThrowException($errMsg, 'OrderComponent.updateOrderBookingInfo');
         }
         if (appParams('autoAssignCurrentOrders')) {
             $criteria = new CDbCriteria();
             $criteria->addColumnCondition(array('email' => self::$bookingContactInfo->email));
             OrderBooking::model()->updateAll(array('userId' => $user->id), $criteria);
         }
     }
     return self::$bookingContactInfo;
 }
Esempio n. 5
0
 public function getOrderBooking()
 {
     $orderBookingId = Yii::app()->user->getState('orderBookingId');
     if (!$orderBookingId) {
         $orderBookingId = $this->currentOrderId;
     }
     if ($orderBookingId) {
         return OrderBooking::model()->findByPk($orderBookingId);
     }
     return false;
 }
 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));
     }
 }
Esempio n. 7
0
 public function execute()
 {
     $valid = false;
     $rooms = Yii::app()->hotelBooker->getCurrent()->hotel->rooms;
     $form = new HotelPassportForm();
     foreach ($rooms as $room) {
         $form->addRoom($room->adults, $room->childCount);
     }
     if (isset($_POST['BookingForm'])) {
         $valid = true;
         $form->bookingForm->attributes = $_POST['BookingForm'];
         $valid = $valid & $form->bookingForm->validate();
     }
     if (isset($_POST['HotelAdultPassportForm'])) {
         foreach ($_POST['HotelAdultPassportForm'] as $i => $adults) {
             foreach ($adults as $j => $adultInfo) {
                 $form->roomsPassports[$i]->adultsPassports[$j]->attributes = $adultInfo;
                 $valid = $valid & $form->roomsPassports[$i]->adultsPassports[$j]->validate();
             }
         }
     }
     if (isset($_POST['HotelChildPassportForm'])) {
         foreach ($_POST['HotelChildPassportForm'] as $i => $children) {
             foreach ($children as $j => $childrenInfo) {
                 $form->roomsPassports[$i]->childrenPassports[$j]->attributes = $childrenInfo;
                 $valid = $valid & $form->roomsPassports[$i]->childrenPassports[$j]->validate();
             }
         }
     }
     if ($valid) {
         /** @var HotelBookerComponent $hotelBookerComponent  */
         $hotelBookerComponent = Yii::app()->hotelBooker;
         $hotelBookerComponent->book();
         $hotelBookerId = $hotelBookerComponent->getHotelBookerId();
         //saving booking data
         /** @var BookingForm  */
         $bookingForm = $form->bookingForm;
         $bookingModel = new OrderBooking();
         $bookingModel->email = $bookingForm->contactEmail;
         $bookingModel->phone = $bookingForm->contactPhone;
         $bookingModel->timestamp = new CDbExpression('NOW()');
         $validSaving = $bookingModel->save();
         $errors = array();
         if ($validSaving) {
             $hotelBookerComponent->getCurrent()->orderBookingId = $bookingModel->id;
             $hotelBookerComponent->getCurrent()->save();
         } else {
             $errors = CMap::mergeArray($errors, $bookingModel->errors);
             Yii::trace(CVarDumper::dumpAsString($bookingModel->errors), 'HotelBooker.EnterCredentials.bookingModel');
         }
         foreach ($form->roomsPassports as $i => $roomPassport) {
             foreach ($roomPassport->adultsPassports as $adultInfo) {
                 $hotelPassport = new HotelBookingPassport();
                 $hotelPassport->scenario = 'adult';
                 $hotelPassport->attributes = $adultInfo->attributes;
                 $hotelPassport->hotelBookingId = $hotelBookerId;
                 $hotelPassport->roomKey = $i;
                 $validSaving = $validSaving and $hotelPassport->save();
                 $errors = CMap::mergeArray($errors, $hotelPassport->errors);
                 Yii::trace(CVarDumper::dumpAsString($hotelPassport->errors), 'HotelBooker.EnterCredentials.adultPassport');
             }
             foreach ($roomPassport->childrenPassports as $childInfo) {
                 $hotelPassport = new HotelBookingPassport();
                 $hotelPassport->scenario = 'child';
                 $hotelPassport->attributes = $childInfo->attributes;
                 $hotelPassport->hotelBookingId = $hotelBookerId;
                 $hotelPassport->roomKey = $i;
                 $validSaving = $validSaving and $hotelPassport->save();
                 $errors = CMap::mergeArray($errors, $hotelPassport->errors);
                 Yii::trace(CVarDumper::dumpAsString($hotelPassport->errors), 'HotelBooker.EnterCredentials.childPassport');
             }
         }
         if ($validSaving) {
             $hotelBookerComponent->status('analyzing');
         } else {
             throw new CHttpException(500, 'Couldn\'t save passport records to db');
         }
     }
     $this->getController()->render('hotelBooker.views.enterCredentials', array('model' => $form));
 }
Esempio n. 8
0
 private function createNewOrderBooking()
 {
     if (is_numeric(Yii::app()->user->getState('todayOrderId'))) {
         return Yii::app()->user->getState('todayOrderId');
     }
     $orderBooking = new OrderBooking();
     $orderBooking->secretKey = md5(microtime() . time() . appParams('salt'));
     $orderBooking->save();
     $todayOrderId = OrderBooking::model()->count(array('condition' => "DATE(`timestamp`) = CURDATE()"));
     $readableNumber = OrderBooking::buildReadableNumber($todayOrderId);
     $orderBooking->saveAttributes(array('readableId' => $readableNumber));
     Yii::app()->user->setState('orderBookingId', $orderBooking->id);
     Yii::app()->user->setState('todayOrderId', $readableNumber);
     Yii::app()->user->setState('secretKey', $orderBooking->secretKey);
     return $readableNumber;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = OrderBooking::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }