コード例 #1
0
ファイル: cheap.php プロジェクト: akochnov/fts
 * Created by PhpStorm.
 * User: Alexey
 * Date: 03.09.2015
 * Time: 16:24
 */
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['origin']) && isset($_GET['destination']) && isset($_GET['date']) && isset($_GET['compare'])) {
    require_once "../as/aviasales.php";
    $origin = getCityCode($_GET['origin']);
    $destination = $_GET['destination'] ? getCityCode($_GET['destination']) : false;
    $date = $_GET['date'] ? $_GET['date'] : false;
    echo '<head>';
    echo '<link rel="stylesheet" type="text/css" href="../as/css/style.css">';
    echo '</head>';
    $compare = isset($_GET['compare']) ? (100 - $_GET['compare']) / 100 : 0.85;
    echo 'Highlighted <span class="highlighted">' . (1 - $compare) * 100 . '%+</span> below average<br><br>';
    $results = getCheap($origin, $destination, $date);
    //$average = getAverage($origin, $destination, $date);
    //echo print_r($cheap);
    if (array_key_exists('success', $results) && $results['success'] == 1 && array_key_exists('data', $results)) {
        echo '<table><tr><th>Direction</th><th>Airline</th><th>Date Departure</th><th>Date Return</th><th>Price Rub</th><th>Average Price</th></tr>';
        foreach ($results['data'] as $direction => $flights) {
            $color = false;
            foreach ($flights as $flight) {
                $departureDate = substr($flight['departure_at'], 0, 7);
                $returnDate = substr($flight['return_at'], 0, 7);
                $average = getAverage($origin, $direction, $departureDate);
                if ($color) {
                    echo '<tr class="colored">';
                } else {
                    echo '<tr>';
                }
コード例 #2
0
ファイル: weekends.php プロジェクト: akochnov/fts
foreach ($origins as $origin) {
    foreach ($destinations as $destination) {
        foreach ($weekends as $weekend) {
            foreach (array('Friday', 'Saturday') as $day) {
                //Get IATA codes
                $originIata = getCityCode($origin);
                $destIata = getCityCode($destination['destination_name']);
                if ($originIata && $destIata) {
                    //Define average rate for dest/month
                    $curMonth = date('Y-m', strtotime($weekend['Friday']));
                    if ($month != $curMonth) {
                        $month = $curMonth;
                        $calendar = getCalendar($originIata, $destIata, $curMonth);
                        $average = round(getAverageFromCalendar($calendar));
                    }
                    $cheap = getCheap($originIata, $destIata, $weekend[$day], $weekend['Sunday']);
                    if (array_key_exists('success', $cheap) && true == $cheap['success'] && array_key_exists('data', $cheap) && array_key_exists($destIata, $cheap['data'])) {
                        //loop through variants
                        foreach ($cheap['data'][$destIata] as $variant) {
                            $departure_at = date('Y-m-d H:i', strtotime($variant['departure_at']));
                            $return_at = date('Y-m-d H:i', strtotime($variant['return_at']));
                            $expires_at = $variant['expires_at'];
                            $airline = $variant['airline'];
                            $flight_number = $variant['flight_number'];
                            $price = $variant['price'];
                            $dest = $destination['destination_name'];
                            //Count trip duration
                            $day1 = new DateTime($weekend[$day]);
                            $day2 = new DateTime($return_at);
                            $days = $day2->diff($day1)->d;
                            $link = getSearchLink($originIata, $destIata, $weekend[$day], $weekend['Sunday']);