예제 #1
0
 /**
  * @param $params
  * @param bool $async
  * @return array|int|mixed
  */
 public function hotelSearch($params, $async = false)
 {
     $this->synchronize();
     $time = time() + $this->differenceTimestamp;
     $getData = array('login' => Yii::app()->params['HotelBook']['login'], 'time' => $time, 'checksum' => $this->getChecksum($time));
     self::$lastRequestMethod = 'HotelSearch';
     self::$lastRequestDescription = '';
     self::$lastRequestCity = City::getCityByHotelbookId($params['cityId']);
     self::$lastRequestDescription = self::$lastRequestCity->code . ' ';
     self::$lastRequestCityHaveCoordinates = self::$lastRequestCity->latitude !== null && self::$lastRequestCity->longitude !== null;
     foreach ($params['rooms'] as $room) {
         self::$lastRequestDescription .= (self::$lastRequestDescription ? ' & ' : '') . self::$roomSizeIdNamesMap[$room['roomSizeId']] . ($room['cots'] ? $room['cots'] . 'COTS' : '') . ($room['child'] ? 'CHLD' . $room['ChildAge'] . 'AGE' : '') . (isset($room['roomNumber']) ? $room['roomNumber'] > 1 ? 'x' . $room['roomNumber'] : '' : '');
     }
     if ($async) {
         $asyncParams = array('function' => array($this, 'processHotelSearchResponse'), 'params' => array($params['checkIn'], $params['duration']));
         //$asyncParams = array();
         return $this->request(Yii::app()->params['HotelBook']['uri'] . 'hotel_search', $getData, array('request' => $this->prepareHotelSearchRequest($params)), $asyncParams);
     } else {
         $path = Yii::getPathOfAlias('application.runtime');
         file_put_contents($path . '/request_' . date('Y-m-d_H_i_s') . '.txt', $this->prepareHotelSearchRequest($params));
         $hotelsXml = $this->request(Yii::app()->params['HotelBook']['uri'] . 'hotel_search', $getData, array('request' => $this->prepareHotelSearchRequest($params)));
         //CTextHighlighter::registerCssFile();
         file_put_contents($path . '/response_' . date('Y-m-d_H_i_s') . '.txt', $hotelsXml);
         //echo $hotelsXml;
         //die();
         //VarDumper::xmlDump($hotelsXml);
         //die();
         return (array) $this->processHotelSearchResponse($hotelsXml, $params['checkIn'], $params['duration']);
     }
 }