Ejemplo n.º 1
0
 public static function getAirportByPk($id)
 {
     if (isset(Airport::$airports[$id])) {
         return Airport::$airports[$id];
     } else {
         $airport = Airport::model()->findByPk($id);
         if ($airport) {
             $city = $airport->city;
             Airport::$airports[$airport->id] = $airport;
             Airport::$codeIdMap[$airport->code] = $airport->id;
             return Airport::$airports[$id];
         } else {
             throw new CException(Yii::t('application', 'City with id {id} not found', array('{id}' => $id)));
         }
     }
 }
Ejemplo n.º 2
0
 public function addRoundTripToCache($row, $url)
 {
     $price = ceil($row->ReturnPrice);
     $codesFrom = explode('*', $row->OutboundWebsiteFlightCode);
     $codesTo = explode('*', $row->InboundWebsiteFlightCode);
     if (sizeof($codesFrom) > 1 && sizeof($codesTo) > 1) {
         $airline = $codesFrom[2];
         $depAirportDate = $codesFrom[1];
         $arrAirportDate = end($codesFrom);
         $fromAirp = Airport::model()->findByAttributes(array('code' => substr($depAirportDate, 0, 3)));
         if (!$fromAirp) {
             echo "Airport {$depAirportDate} not defined \n";
             return false;
         }
         $toAirp = Airport::model()->findByAttributes(array('code' => substr($arrAirportDate, 0, 3)));
         if (!$toAirp) {
             echo "Airport {$arrAirportDate} not defined \n";
             return false;
         }
         $from = $fromAirp->cityId;
         $to = $toAirp->cityId;
     } else {
         $airline = '';
         $from = $this->intRouters[$url][0];
         $to = $this->intRouters[$url][1];
         if (!$from || !$to) {
             echo "Cities not defined \n";
             return false;
         }
     }
     $timeFrom = strtotime($row->OutboundDepartureDate);
     $timeBack = strtotime($row->InboundDepartureDate);
     if ($timeFrom == 0 || $timeBack == 0) {
         echo "Time does not determined\n";
         return false;
     }
     $dateFrom = date('Y-m-d', $timeFrom);
     $dateBack = date('Y-m-d', $timeBack);
     $flightCache = FlightCache::model()->findByAttributes(array('from' => $from, 'to' => $to, 'dateFrom' => $dateFrom, 'dateBack' => $dateBack));
     if (!$flightCache) {
         echo "Creating record {$from} - {$to} - {$from} at {$dateFrom} <-> {$dateBack}. It is {$price}\n";
         $flightCache = new FlightCache();
     } else {
         if ($flightCache->priceBestPrice > $price) {
             echo "Updating record {$from} - {$to} - {$from} at {$dateFrom} <-> {$dateBack}. It was {$flightCache->priceBestPrice} become {$price}\n";
         } else {
             return true;
         }
     }
     $flightCache->from = $from;
     $flightCache->to = $to;
     $flightCache->dateFrom = $dateFrom;
     $flightCache->dateBack = $dateBack;
     $flightCache->priceBestPrice = $price;
     $flightCache->transportBestPrice = $airline;
     $flightCache->validatorBestPrice = $airline;
     return $flightCache->save();
 }