MOON
Server: Apache
System: Linux 3-228-103-98.cprapid.com 3.10.0-1160.62.1.el7.x86_64 #1 SMP Tue Apr 5 16:57:59 UTC 2022 x86_64
User: api (1001)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /home/api/public_html/nashville/get-search-results-count.php
<?php
//ini_set( "display_errors", true );
//ini_set( "display_startup_errors", true );
require( "php/config.php" );

$oRes = new Result( "SearchResultsCount" );
$oSearch = new Search();
$oSearch->returnCount( true );
$oSearch->setActive( true );

foreach ( $_GET as $k => $v )
{
    if ( in_array( strtolower( $k ), array( 'listingagencycode' ) ) )
        $oSearch->setVal( $k, 'RTC' . $v );
    else
        $oSearch->setVal( $k, $v );
}

if ( isset( $_GET['DrivingTime'] ) && is_numeric( $_GET['DrivingTime'] ) && 
    isset( $_GET['StartLocation'] ) && ( strlen( $_GET['StartLocation'] ) > 1 ) )
{
    $oRes->aPassThrough = array( "Duration", "DurationValue" );
    $oRes->aSearchReturnFields[] = "Duration";
    $oRes->aSearchReturnFields[] = "DurationValue";
}

$aResult = $oSearch->doQuery();

if ( isset( $_GET['DrivingTime'] ) && is_numeric( $_GET['DrivingTime'] ) && 
    isset( $aResult['Data'] ) && is_array( $aResult['Data'] ) )
{
    uasort( $aResult['Data'], "sortDist" );
    $aResult['Data'] = array_slice( $aResult['Data'], 0, 25 );
    $destinations = "";
    foreach ( $aResult['Data'] as $oD )
        $destinations .= $oD['Latitude'] . "," . $oD['Longitude'] . "|";
    $destinations = substr( $destinations, 0, -1 );

    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . $_GET['StartLocation'] .
        "&destinations=" . $destinations . "&key=" . GOOGLEAPIKEY;

    $c = curl_init( $url );
    curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
    $j = curl_exec( $c );
    curl_close( $c );
    $oResult = json_decode( $j );

    if ( $oResult->status == "OK" )
    {
        foreach ( $oResult->rows[0]->elements as $kDest => $oDest )
        {
            if ( $oDest->duration->value > ( $_GET['DrivingTime'] * 60 ) )
                unset( $aResult['Data'][$kDest] );
            else
            {
                $aResult['Data'][$kDest]['Duration'] = $oDest->duration->text;
                $aResult['Data'][$kDest]['DurationValue'] = $oDest->duration->value;
            }
        }
    }
    $aResult['Data'] = array_values( $aResult['Data'] );
    $aResult['RecordsReturned'] = count( $aResult['Data'] );
}

if ( isset( $aResult["TotalRecords"] ) )
	$oRes->addData( $aResult["TotalRecords"], "TotalRecords" );
$oRes->addData( $oSearch->aSQLStatements, "sql" );
$oMLS->finish( "nashville", "search-results-count", json_encode( $_GET ) );
print $oRes->getJSON();