File: /home/api/public_html/nashville/get-office-listings.php
<?php
//ini_set( "display_errors", true );
//ini_set( "display_startup_errors", true );
ini_set( "memory_limit", "128M" );
require( "php/config.php" );
$aOfficeIDs = false;
$bSold = false;
$bActive = true;
$iLimit = false;
$oRes = new Result( "SearchResults" );
$oSearch = new Search();
$oSearch->setActive( true );
foreach ( $_GET as $k => $v )
{
switch( strtolower( $k ) )
{
case "officeid":
if ( preg_match( "@^[[:alnum:],]+$@", $v ) === 1 )
{
$aOfficeIDs = explode( ",", $v );
// array_walk( $aOfficeIDs, function( &$oO ) { $oO = 'RTC' . $oO; } );
}
break;
case "active":
if ( $v === "1" )
$bActive = true;
break;
case "https":
if ( strtolower( $v ) == "on" )
$oRes->bHttps = true;
break;
case "sold":
if ( $v === "1" )
{
$oRes->aSearchReturnFields[] = "ClosedDate";
$oRes->aSearchReturnFields[] = "SalePrice";
$oSearch->setVal( 'propertystatus', 'off-market' );
$oSearch->setVal( "sortby", "SalePrice" );
}
break;
case "closeddate":
if ( preg_match( "@^[\d]{4}-[\d]{2}-[\d]{2}$@", $v ) === 1 )
$oSearch->setVal( 'closeddate', $v );
break;
case "limit":
if ( is_numeric( $v ) )
$oRes->setLimit( $v );
break;
}
}
if ( is_array( $aOfficeIDs ) && ( count( $aOfficeIDs ) > 0 ) )
$oSearch->setVal( "ListingAgencyCode", $aOfficeIDs );
$aResultData = [];
$aResult = $oSearch->doQuery();
if ( isset( $aResult["Data"] ) )
{
foreach ( $aResult["Data"] as $oRD )
$aResultData[$oRD["MlsNumber"]] = $oRD;
}
if ( is_array( $aOfficeIDs ) && ( count( $aOfficeIDs ) > 0 ) )
{
unset( $oSearch->aSearchVals["ListingAgencyCode"] );
$oSearch->setVal( "SellingAgencyCode", $aOfficeIDs );
}
$aResult = $oSearch->doQuery();
if ( isset( $aResult["Data"] ) )
{
foreach ( $aResult["Data"] as $oRD )
$aResultData[$oRD["MlsNumber"]] = $oRD;
}
$oRes->addData( array_values( $aResultData ), "Data" );
$oMLS->finish( "nashville", "office-listingst", json_encode( $_GET ) );
print $oRes->getJSON();