Esempio n. 1
0
 public function run($key)
 {
     $parts = explode('_', $key);
     $searchKey = $parts[0];
     $searchId = $parts[1];
     $flightBooker = FlightBooker::model()->findByAttributes(array('flightVoyageId' => 'flight_voyage_' . $key));
     if ($flightBooker) {
         $flightVoyage = $flightBooker->flightVoyage;
         Yii::app()->flightBooker->flightVoyage = $flightVoyage;
     } else {
         $flightVoyage = FlightVoyage::getFromCache($searchKey, $searchId);
         if ($flightVoyage) {
             Yii::app()->flightBooker->flightVoyage = $flightVoyage;
         }
     }
     if (!$flightVoyage) {
         throw new CHttpException(500, 'Your request expired');
     }
     Yii::app()->flightBooker->book();
     $status = Yii::app()->flightBooker->current->swGetStatus()->getId();
     $actionName = 'stage' . ucfirst($status);
     if ($action = $this->getController()->createAction($actionName)) {
         $action->execute();
     } else {
         Yii::app()->flightBooker->{$actionName}();
     }
 }
 public function actionBuy($key)
 {
     //oleg: why?
     die;
     $parts = explode('_', $key);
     $searchKey = $parts[0];
     $searchId = $parts[1];
     $flightVoyage = FlightVoyage::getFromCache($searchKey, $searchId);
     Yii::app()->flightBooker->flightVoyage = $flightVoyage;
     if (Yii::app()->flightBooker->getCurrent() == null) {
         Yii::app()->flightBooker->book();
     }
     $status = Yii::app()->flightBooker->current->swGetStatus()->getId();
     $action = 'stage' . ucfirst($status);
     if (method_exists($this, $action)) {
         $this->{$action}();
     } else {
         Yii::app()->flightBooker->{$action}();
     }
 }
Esempio n. 3
0
 public function actionFillCartElement($cartElementId, $type, $key, $searchId = '', $searchId2 = '', $pCacheId = '')
 {
     $dataProvider = new TripDataProvider();
     $allPositions = $dataProvider->getSortedCartItems();
     $needPosition = null;
     foreach ($allPositions as $item) {
         if ($item->getId() == $cartElementId) {
             $needPosition = $item;
             break;
         }
     }
     if ($needPosition) {
         switch ($type) {
             case FlightVoyage::TYPE:
                 $needPositions = array();
                 $groupId = $needPosition->getGroupId();
                 foreach ($allPositions as $item) {
                     if ($item->getGroupId()) {
                         if ($item->getGroupId() == $groupId) {
                             $needPositions[] = $item;
                         }
                     }
                 }
                 /** @var $flight FlightVoyage */
                 $flight = FlightVoyage::getFromCache($searchId, $key);
                 if ($flight) {
                     //updating all cartElements
                     foreach ($needPositions as $item) {
                         $flightSearchParams = @Yii::app()->pCache->get('flightSearchParams' . $pCacheId);
                         $item->fillFromSearchParams($flightSearchParams);
                         $item->flightVoyage = $flight;
                         Yii::app()->shoppingCart->update($item, 1);
                     }
                     $json = CJSON::encode($flight->getJsonObject());
                     if (isset($_GET['callback'])) {
                         echo $_GET['callback'] . ' (' . $json . ');';
                     } else {
                         echo $json;
                     }
                 } else {
                     throw new CHttpException(404, 'Can\'t found item inside cache key:' . $key . ' searchId:' . $searchId);
                 }
                 break;
             case Hotel::TYPE:
                 /** @var $hotel Hotel */
                 $hotel = Hotel::getFromCache($searchId, null, $key);
                 if ($hotel) {
                     $hotelSearchParams = @Yii::app()->pCache->get('hotelSearchParams' . $pCacheId);
                     $needPosition->fillFromSearchParams($hotelSearchParams);
                     $needPosition->hotel = $hotel;
                     Yii::app()->shoppingCart->update($needPosition, 1);
                     $json = CJSON::encode($hotel->getJsonObject());
                     if (isset($_GET['callback'])) {
                         echo $_GET['callback'] . ' (' . $json . ');';
                     } else {
                         echo $json;
                     }
                 } else {
                     throw new CHttpException(404, 'Can\'t found item inside cache');
                 }
                 break;
         }
     }
 }