public static function getOptimalPrice($fromCityId, $toCityId, $date, $returnDate = false, $forceUpdate = false) { $flightForm = new FlightForm(); $flightForm->adultCount = 1; $flightForm->childCount = 0; $flightForm->infantCount = 0; $route = new RouteForm(); $route->departureCityId = $fromCityId; $route->arrivalCityId = $toCityId; $route->departureDate = $date; if ($returnDate) { $route->isRoundTrip = true; $route->backDate = $returnDate; } $flightForm->routes[] = $route; $flightSearchParams = self::buildSearchParams($flightForm); $fs = new FlightSearch(); $fs->status = 1; $fs->requestId = '1'; $fs->data = '{}'; $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('`from`' => $fromCityId, '`to`' => $toCityId)); $criteria->addCondition('`dateFrom` = STR_TO_DATE("' . $date . '", "%d.%m.%Y")'); if ($returnDate) { $criteria->addCondition('`dateBack` = STR_TO_DATE("' . $returnDate . '", "%d.%m.%Y")'); } else { $criteria->addCondition('`dateBack` = "0000-00-00"'); } if ($forceUpdate) { $result = $fs->sendRequest($flightSearchParams); } else { $result = FlightCache::model()->find($criteria); } if ($result) { $return = (int) $result->priceBestPriceTime; if ($return == 0) { $return = (int) $result->priceBestPrice; } return $return; } else { throw new CException('Can\'t get best pricetime'); } }
private function doFlightSearch($flightSearchParams) { $fs = new FlightSearch(); $this->results = $fs->sendRequest($flightSearchParams, false); $cacheId = $this->storeToCache($flightSearchParams); $results = $this->inject($this->results->getJsonObject(), $cacheId); return $results; }