Esempio n. 1
0
 public function restoreFromDb($orderId)
 {
     Yii::app()->shoppingCart->clear();
     $order = Order::model()->findByPk($orderId);
     if (!$order) {
         throw new CException("No such order");
     }
     $items = $order->flightItems();
     foreach ($items as $item) {
         $flightTripElement = new FlightTripElement();
         $searchParams = @unserialize($item->searchParams);
         if ($searchParams) {
             $flightTripElement->fillFromSearchParams($searchParams);
         }
         $object = @unserialize($item->object);
         if ($object) {
             $flightTripElement->flightVoyage = $object;
         }
         Yii::app()->shoppingCart->put($flightTripElement);
     }
     $items = $order->hotelItems();
     foreach ($items as $item) {
         $hotelTripElement = new HotelTripElement();
         $searchParams = @unserialize($item->searchParams);
         if ($searchParams) {
             $hotelTripElement->fillFromSearchParams($searchParams);
         }
         /*$city = City::model()->findByPk($item->cityId);
           $hotelTripElement->city = $city;
           $hotelTripElement->checkIn = $item->checkIn;*/
         $object = @unserialize($item->object);
         if ($object) {
             $hotelTripElement->hotel = $object;
         }
         if (false && $hotelTripElement->searchParams && $hotelTripElement->searchParams['cityFull']) {
             //$hotelTripElement->searchParams->cityFull = $hotelTripElement->searchParams->cityFull->getAttributes();
         }
         Yii::app()->shoppingCart->put($hotelTripElement);
     }
 }
 public static function prepareInfoForTab(FlightTripElement $flight)
 {
     $from = City::getCityByPk($flight->departureCity);
     $to = City::getCityByPk($flight->arrivalCity);
     $tab = array();
     $tab['info'] = array('type' => 'flight', 'flights' => array());
     $tab['id'] = $flight->id . '_tab';
     $tab['groupId'] = $flight->getGroupId();
     $tab['label'] = '<b>Перелёт</b>';
     if ($flight->flightVoyage) {
         $controller = Yii::app()->controller;
         $tab['content'] = $controller->renderPartial('//tour/constructor/_chosen_flight_precompiled', array('flight' => $flight->flightVoyage->getJsonObject()), true);
         $tab['fill'] = true;
         $tab['itemOptions']['class'] = 'flight fill';
     } else {
         $tab['content'] = 'loading...';
         //VarDumper::dumpAsString($flight->getPassports(), 10, true);
         $tab['itemOptions']['class'] = 'flight unfill';
         $tab['fill'] = false;
     }
     return $tab;
 }
Esempio n. 3
0
 public function actionAdd($type, $key, $searchId = '', $searchId2 = '', $pCacheId = '')
 {
     switch ($type) {
         case FlightVoyage::TYPE:
             /** @var $flight FlightVoyage */
             $flight = FlightVoyage::getFromCache($key, $searchId);
             $flightSearchParams = @Yii::app()->pCache->get('flightSearchParams' . $pCacheId);
             if ($flight) {
                 $id = time();
                 //todo: add count of flightVoyageFlights Items
                 foreach ($flight->flights as $i => $flightElement) {
                     $item = new FlightTripElement();
                     $item->fillFromSearchParams($flightSearchParams, $i > 0);
                     $item->flightVoyage = $flight;
                     $item->groupId = $flight->getId();
                     $item->id = $id++;
                     Yii::app()->shoppingCart->put($item);
                 }
             } else {
                 throw new CHttpException(404, 'Can\'t found item inside cache');
             }
             break;
         case Hotel::TYPE:
             /** @var $hotel Hotel */
             $hotel = Hotel::getFromCache($key, $searchId, $searchId2);
             $hotelSearchParams = @Yii::app()->pCache->get('hotelSearchParams' . $pCacheId);
             if ($hotel) {
                 $item = new HotelTripElement();
                 $item->fillFromSearchParams($hotelSearchParams);
                 $item->hotel = $hotel;
                 $item->id = time();
                 Yii::app()->shoppingCart->put($item);
             } else {
                 throw new CHttpException(404, 'Can\'t found item inside cache');
             }
             break;
     }
 }
Esempio n. 4
0
 private function getAllTourVariants()
 {
     $asyncExecutor = new AsyncCurl();
     $dataProvider = new TripDataProvider();
     $items = $dataProvider->getSortedCartItems();
     $grouped = array();
     foreach ($items as $item) {
         if ($item instanceof FlightTripElement) {
             $grouped[$item->getGroupId()][] = $item;
         } else {
             $grouped[$item->getGroupId()][] = $item;
         }
     }
     foreach ($grouped as $group) {
         if ($group[0] instanceof FlightTripElement) {
             $url = FlightTripElement::getUrlToAllVariants($group);
             $asyncExecutor->add($url);
         } else {
             if ($group[0] instanceof HotelTripElement) {
                 $itemVariantsUrl = $group[0]->getUrlToAllVariants();
                 $asyncExecutor->add($itemVariantsUrl);
             }
         }
     }
     $responses = $asyncExecutor->send();
     $this->errors = array();
     $i = 0;
     foreach ($responses as $response) {
         if ($httpCode = $response->headers['http_code'] == 200) {
             $this->variants[$i] = CJSON::decode($response->body);
             $this->errors[$i] = false;
         } else {
             $this->variants[$i] = array();
             $this->errors[$i] = 'Error ' . $httpCode;
         }
         $i++;
     }
 }
Esempio n. 5
0
 public function addFlightTripElement($flight, FlightSearchParams $flightSearchParams)
 {
     $flightTripElement = new FlightTripElement();
     $key = md5(serialize($flightSearchParams));
     if (!isset($this->keys[$key])) {
         $this->keys[$key] = 0;
     }
     if ($this->keys[$key] == 1) {
         $flightTripElement->fillFromSearchParams($flightSearchParams, true);
     } else {
         $flightTripElement->fillFromSearchParams($flightSearchParams, false);
     }
     if ($flightSearchParams->isRoundTrip()) {
         $this->keys[$key] = 1;
         $flightTripElement->setGroupId($key);
     }
     $flightTripElement->flightVoyage = $flight;
     Yii::app()->shoppingCart->put($flightTripElement);
 }