Пример #1
0
 public function actionIndex($isTab = false)
 {
     Yii::import('site.common.modules.hotel.models.*');
     $hotelForm = new HotelForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'hotel-form') {
         echo CActiveForm::validate($hotelForm);
         Yii::app()->end();
     }
     if (isset($_POST['HotelForm'])) {
         $hotelForm->attributes = $_POST['HotelForm'];
         $rooms = array();
         if (isset($_POST['HotelRoomForm'])) {
             foreach ($_POST['HotelRoomForm'] as $i => $info) {
                 $room = new HotelRoomForm();
                 $room->attributes = $info;
                 if ($room->validate()) {
                     $rooms[] = $room;
                 }
             }
         }
         $hotelForm->rooms = $rooms;
         if ($hotelForm->validate()) {
             $hotelSearchParams = new HotelSearchParams();
             $hotelSearchParams->checkIn = date('Y-m-d', strtotime($hotelForm->fromDate));
             $hotelSearchParams->city = City::getCityByPk($hotelForm->cityId);
             $hotelSearchParams->duration = $hotelForm->duration;
             foreach ($hotelForm->rooms as $room) {
                 if ($room->childCount == 1) {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, $room->childAge);
                 } else {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, false);
                 }
             }
             $HotelClient = new HotelBookClient();
             $resultSearch = $HotelClient->fullHotelSearch($hotelSearchParams);
             Yii::app()->hotelsRating->injectRating($resultSearch->hotels, $hotelSearchParams->city);
             $cacheId = substr(md5(uniqid('', true)), 0, 10);
             Yii::app()->cache->set('hotelResult' . $cacheId, $resultSearch, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelSearchParams' . $cacheId, $hotelSearchParams, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelForm' . $cacheId, $hotelForm, appParams('hotel_search_cache_time'));
             Yii::app()->user->setState('hotel.cacheId', $cacheId);
             //die();
             $this->redirect('/booking/hotel/result/cacheId/' . $cacheId);
         } else {
             $this->render('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         }
     } else {
         if ($isTab) {
             $this->renderPartial('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         } else {
             $this->render('index', array('items' => $this->generateItems(), 'hotelForm' => $hotelForm, 'autosearch' => false, 'cityName' => '', 'duration' => 1));
         }
     }
 }
Пример #2
0
 public function run()
 {
     Yii::import('site.common.modules.hotel.models.*');
     $hotelForm = new HotelForm();
     if (isset($_REQUEST['HotelForm'])) {
         $hotelForm->attributes = $_REQUEST['HotelForm'];
         $rooms = array();
         if (isset($_REQUEST['HotelRoomForm'])) {
             foreach ($_REQUEST['HotelRoomForm'] as $i => $info) {
                 $room = new HotelRoomForm();
                 $room->attributes = $info;
                 if ($room->validate()) {
                     $rooms[] = $room;
                 }
             }
         }
         $hotelForm->rooms = $rooms;
         if ($hotelForm->validate()) {
             $hotelSearchParams = new HotelSearchParams();
             $hotelSearchParams->checkIn = date('Y-m-d', strtotime($hotelForm->fromDate));
             $hotelSearchParams->city = City::getCityByPk($hotelForm->cityId);
             $hotelSearchParams->duration = $hotelForm->duration;
             foreach ($hotelForm->rooms as $room) {
                 if ($room->childCount == 1) {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, $room->childAge);
                 } else {
                     $hotelSearchParams->addRoom($room->adultCount, $room->cots, false);
                 }
             }
             $HotelClient = new HotelBookClient();
             $pCacheId = md5(serialize($hotelSearchParams));
             Yii::app()->pCache->set('hotelSearchParams' . $pCacheId, $hotelSearchParams, appParams('hotel_search_cache_time'));
             $resultSearch = $HotelClient->fullHotelSearch($hotelSearchParams);
             Yii::app()->hotelsRating->injectRating($resultSearch->hotels, $hotelSearchParams->city);
             $cacheId = substr(md5(uniqid('', true)), 0, 10);
             Yii::app()->cache->set('hotelResult' . $cacheId, $resultSearch, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelSearchParams' . $cacheId, $hotelSearchParams, appParams('hotel_search_cache_time'));
             Yii::app()->cache->set('hotelForm' . $cacheId, $hotelForm, appParams('hotel_search_cache_time'));
             if ($resultSearch['hotels']) {
                 $hotelStack = new HotelStack($resultSearch);
                 $results = $hotelStack->groupBy('hotelId')->groupBy('roomSizeId')->groupBy('rubPrice')->sortBy('rubPrice', 2)->getJsonObject();
                 echo json_encode(array('pCacheId' => $pCacheId, 'cacheId' => $cacheId, 'hotels' => $results));
             } else {
                 echo json_encode(array('cacheId' => $cacheId, 'hotels' => array()));
             }
         } else {
             //invalid form
             throw new CHttpException(500, CHtml::errorSummary($hotelForm));
         }
         Yii::app()->end();
     } else {
         throw new CHttpException(404);
     }
 }
Пример #3
0
 public function run($isTab = false)
 {
     /*        if ($res = Yii::app()->user->getState('trip.tour.form'))
                 $model = @unserialize($res);
             else*/
     $model = new TourBuilderForm();
     if (isset($_GET['eventId'])) {
         $model->eventId = $_GET['eventId'];
     }
     if (isset($_POST['TourBuilderForm'])) {
         unset($model);
         $model = new TourBuilderForm();
         $model->attributes = $_POST['TourBuilderForm'];
         $model->trips = array();
         $model->rooms = array();
         if (isset($_POST['TripForm'])) {
             $validTrips = true;
             $validRooms = true;
             $validStartCity = true;
             foreach ($_POST['TripForm'] as $i => $attributes) {
                 $trip = new TripForm();
                 $trip->attributes = $attributes;
                 $validTrips = $validTrips and $trip->validate();
                 if ($validTrips) {
                     $model->trips[] = $trip;
                 }
             }
             foreach ($_POST['HotelRoomForm'] as $i => $attributes) {
                 $room = new HotelRoomForm();
                 $room->attributes = $attributes;
                 $validRooms = $validRooms and $room->validate();
                 if ($validRooms) {
                     $model->rooms[] = $room;
                 }
             }
             $model->startCities = array();
             foreach ($_POST['EventStartCityForm'] as $i => $attributes) {
                 $startCity = new EventStartCityForm();
                 $startCity->attributes = $attributes;
                 $validStartCity = $validStartCity and $startCity->validate();
                 if ($validStartCity) {
                     $model->startCities[] = $startCity;
                 }
             }
             if ($validTrips and $validRooms and $model->validate()) {
                 Yii::app()->user->setState('trip.tour.form', serialize($model));
                 Yii::app()->shoppingCart->clear();
                 if ($model->isLinkedToEvent) {
                     Yii::app()->user->setState('tourForm', $model);
                     Yii::app()->user->setState('startCities', $model->startCities);
                     Yii::app()->user->setState('startCitiesIndex', 0);
                     $this->controller->redirect($this->controller->createUrl('showEventTrip'));
                 } else {
                     ConstructorBuilder::buildAndPutToCart($model);
                     $this->controller->redirect($this->controller->createUrl('showTrip'));
                 }
             }
         }
     }
     if ($isTab) {
         $this->controller->renderPartial('create', array('model' => $model));
     } else {
         $this->controller->render('create', array('model' => $model));
     }
 }