예제 #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);
     }
 }
예제 #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");
     }
 }
예제 #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);
 }
예제 #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;
 }
예제 #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;
 }
예제 #6
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;
 }
예제 #7
0
 /**
  * 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;
 }