Esempio n. 1
0
 public function getId()
 {
     if ($this->flightVoyage) {
         return $this->flightVoyage->getId();
     }
     return $this->_id;
 }
Esempio n. 2
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}();
     }
 }
 public function book()
 {
     //if we don't have a flight OR we moved to another flight
     if ($this->getCurrent() == null || $this->getCurrent()->flightVoyage->id != $this->flightVoyage->getId()) {
         //if we don't have a flight AND we moved to another flight
         if ($this->getCurrent() != null and $this->getCurrent()->flightVoyage->id != $this->flightVoyage->getId()) {
             $this->flightBooker = FlightBooker::model()->findByAttributes(array('flightVoyageId' => $this->flightVoyage->getId()));
             if (!$this->flightBooker) {
                 $this->flightBooker = new FlightBooker();
                 $this->flightBooker->flightVoyageId = $this->flightVoyage->getId();
                 $this->flightBooker->flightVoyage = $this->flightVoyage;
                 $this->flightBooker->status = 'enterCredentials';
                 $this->flightBooker->setFlightBookerComponent($this);
                 if (!$this->flightBooker->save()) {
                     VarDumper::dump($this->flightBooker->getErrors());
                 }
             }
             $this->flightBooker->setFlightBookerComponent($this);
         }
         if ($this->flightBooker == null) {
             Yii::trace('New flightBooker to db', 'FlightBookerComponent.book');
             $this->flightBooker = new FlightBooker();
             $this->flightBooker->flightVoyageId = $this->flightVoyage->getId();
             $this->flightBooker->flightVoyage = $this->flightVoyage;
             $this->flightBooker->status = 'enterCredentials';
             $this->flightBooker->setFlightBookerComponent($this);
             if (!$this->flightBooker->save()) {
                 VarDumper::dump($this->flightBooker->getErrors());
             }
         }
     }
     Yii::trace(CVarDumper::dumpAsString($this->flightBooker->getErrors()), 'FlightBookerComponent.book');
     if (!$this->flightBooker->id) {
         $this->flightBooker->id = $this->flightBooker->primaryKey;
     }
     Yii::app()->user->setState('flightVoyageId', $this->flightBooker->flightVoyage->id);
 }
Esempio n. 5
0
 /**
  *
  * Set data from FlightVoyage object
  * @param FlightVoyage $flightVoyage
  * @throws CException
  */
 public function setFromFlightVoyage(FlightVoyage $flightVoyage, $suffix)
 {
     if ($flightVoyage instanceof FlightVoyage) {
         $priceAttribute = "price" . $suffix;
         $transportAttribute = "transport" . $suffix;
         $validatorAttribute = "validator" . $suffix;
         $durationAttribute = "duration" . $suffix;
         $this->{$priceAttribute} = $flightVoyage->price;
         $this->{$transportAttribute} = $flightVoyage->getTransportAirlines();
         $this->{$validatorAttribute} = $flightVoyage->valAirline->code;
         $this->{$durationAttribute} = $flightVoyage->getFullDuration();
     } else {
         throw new CException(Yii::t('application', 'Required param type FlightVoyage'));
     }
 }
Esempio n. 6
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;
         }
     }
 }
Esempio n. 7
0
 public function actionUpdateEvent()
 {
     print_r($_POST);
     $event = Event::model()->findByPk($_POST['eventId']);
     if (isset($_POST['startCity'])) {
         $startCity = City::getCityByCode($_POST['startCity']);
     }
     foreach ($event->tours as $tour) {
         if ($tour->startCityId == $startCity->id) {
             echo "find startCity";
             break;
         } else {
             echo "cid : " . $tour->startCityId;
         }
         $tour = null;
     }
     if ($tour) {
         //print_r($tour);
     }
     if ($tour->order) {
         //print_r($tour->order);
     }
     $items = $_POST['items'];
     $priceSum = 0;
     foreach ($items as $item) {
         if ($item['type'] == 'hotel') {
             $item['data']['cityId'] = City::getCityByCode($item['data']['cityCode'])->hotelbookId;
             $item['data']['rubPrice'] = $item['data']['discountPrice'];
             $item['data']['comparePrice'] = $item['data']['discountPrice'];
             $priceSum += $item['data']['discountPrice'];
             $hotel = new Hotel($item['data']);
             //print_r($hotel->getJsonObject());
             $cityId = $hotel->city->id;
             /** var OrderHotel $hotelItem */
             foreach ($tour->order->hotelItems as $hotelItem) {
                 //$hotelItem = new OrderHotel();
                 if ($hotelItem->cityId == $cityId || $hotelItem->checkIn == $hotel->checkIn) {
                     $hotelItem->object = serialize($hotel);
                     $hotelItem->isNewRecord = false;
                     echo "update " . $hotelItem->id . " orderHotel" . $hotel->checkIn . serialize($hotel);
                     $hotelItem->save();
                 }
                 //print_r($hotelItem);
             }
         } else {
             $flight = new FlightVoyage($item['data']);
             $priceSum += $flight->price;
             //print_r($flight);
             foreach ($flight->flights as $flightKey => $fl) {
                 foreach ($tour->order->flightItems as $flightItem) {
                     if ($flightItem->departureCity == $flight->getDepartureCity($flightKey)->id && $flightItem->arrivalCity == $flight->getArrivalCity($flightKey)->id && $flightItem->departureDate == date('Y-m-d', strtotime($flight->getDepartureDate($flightKey)))) {
                         $flightItem->object = serialize($flight);
                         $flightItem->isNewRecord = false;
                         echo "update " . $flightItem->id . " flight\n";
                         $flightItem->save();
                         break;
                     } else {
                         echo "notUpdate " . $flightItem->id . " flight " . $flightItem->departureCity . '|' . $flight->getDepartureCity()->id . '|' . $flightItem->arrivalCity . '|' . $flight->getArrivalCity()->id . '|' . $flightItem->departureDate . '|' . $flight->getDepartureDate() . "\n";
                         //print_r($flight->getJsonObject());die();
                     }
                 }
             }
         }
     }
     if ($priceSum) {
         $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $event->id, 'cityId' => $startCity->id));
         if ($eventPrice) {
             $eventPrice->bestPrice = $priceSum;
             $eventPrice->save();
         }
     }
 }