<?php
namespace AppBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ApartmentsController extends FrontendController {
/*
8888o. .o88o. 8888o. .o8888 888888 8888o. 888888 8888o. 888888
88 88 88 88 88 88 88 88 88 88 88 88 88 88
8888Y' 888888 8888Y' 'Y88o. 8888 8888Y' 8888 88 88 88
88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 88 88 88 8888Y' 888888 88 88 888888 88 88 88
*/
private function GetRent( \Pimcore\Model\DataObject\YardiProperty $property ) {
// Parse the cached floorplan json...
$cache_floorplan = json_decode( $property->getCache_floorplan() );
// Return false if there is invalid json...
if( !$cache_floorplan ) return false;
// Aggregate rent values...
$Rent = array();
foreach( $cache_floorplan as $floorplan ) {
if( (int)$floorplan->MinimumRent > 0 ) $Rent[] = (int)$floorplan->MinimumRent;
if( (int)$floorplan->MaximumRent > 0 ) $Rent[] = (int)$floorplan->MaximumRent;
}
// Return false if there are no rent values...
if( empty( $Rent ) ) return false;
// Return the square footage...
return $Rent;
}
private function RentMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Rent = $this->GetRent( $property );
return is_array( $Rent ) ? min( $Rent ) : $Rent;
}
private function RentMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Rent = $this->GetRent( $property );
return is_array( $Rent ) ? max( $Rent ) : $Rent;
}
/*
8888o. .o88o. 8888o. .o8888 888888 .o8888 .o88o. 888888 888888
88 88 88 88 88 88 88 88 88 88 88 88 88
8888Y' 888888 8888Y' 'Y88o. 8888 'Y88o. 88 88 8888 88
88 88 88 88 88 88 88 88 'Y8888 88 88
88 88 88 88 88 8888Y' 888888 8888Y' 88 88 88
*/
private function GetSqft( \Pimcore\Model\DataObject\YardiProperty $property ) {
// Parse the cached floorplan json...
$cache_floorplan = json_decode( $property->getCache_floorplan() );
// Return false if there is invalid json...
if( !$cache_floorplan ) return false;
// Aggregate rent values...
$Sqft = array();
foreach( $cache_floorplan as $floorplan ) {
if( (int)$floorplan->MinimumSQFT > 0 ) $Sqft[] = (int)$floorplan->MinimumSQFT;
if( (int)$floorplan->MaximumSQFT > 0 ) $Sqft[] = (int)$floorplan->MaximumSQFT;
}
// Return false if there are no rent values...
if( empty( $Sqft ) ) return false;
// Return the square footage...
return $Sqft;
}
private function SqftMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Sqft = $this->GetSqft( $property );
return is_array( $Sqft ) ? min( $Sqft ) : $Sqft;
}
private function SqftMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Sqft = $this->GetSqft( $property );
return is_array( $Sqft ) ? max( $Sqft ) : $Sqft;
}
/*
8888o. .o88o. 8888o. .o8888 888888 8888o. 888888 8888o. .o8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88
8888Y' 888888 8888Y' 'Y88o. 8888 8888Y' 8888 88 88 'Y88o.
88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 88 88 88 8888Y' 888888 8888Y' 888888 8888Y' 8888Y'
*/
private function GetBeds( \Pimcore\Model\DataObject\YardiProperty $property ) {
// Parse the cached floorplan json...
$cache_floorplan = json_decode( $property->getCache_floorplan() );
// Return false if there is invalid json...
if( !$cache_floorplan ) return false;
// Aggregate rent values...
$Beds = array();
foreach( $cache_floorplan as $floorplan ) {
$Beds[] = (int)$floorplan->Beds;
}
// Return false if there are no rent values...
if( empty( $Beds ) ) return false;
// Return the square footage...
return $Beds;
}
private function BedsMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Beds = $this->GetBeds( $property );
return is_array( $Beds ) ? min( $Beds ) : $Beds;
}
private function BedsMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Beds = $this->GetBeds( $property );
return is_array( $Beds ) ? max( $Beds ) : $Beds;
}
/*
8888o. .o88o. 8888o. .o8888 888888 8888o. .o88o. 888888 88 88 .o8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
8888Y' 888888 8888Y' 'Y88o. 8888 8888Y' 888888 88 888888 'Y88o.
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 88 88 88 8888Y' 888888 8888Y' 88 88 88 88 88 8888Y'
*/
private function GetBaths( \Pimcore\Model\DataObject\YardiProperty $property ) {
// Parse the cached floorplan json...
$cache_floorplan = json_decode( $property->getCache_floorplan() );
// Return false if there is invalid json...
if( !$cache_floorplan ) return false;
// Aggregate rent values...
$Baths = array();
foreach( $cache_floorplan as $floorplan ) {
$Baths[] = (int)$floorplan->Baths;
}
// Return false if there are no rent values...
if( empty( $Baths ) ) return false;
// Return the square footage...
return $Baths;
}
private function BathsMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Baths = $this->GetBaths( $property );
return is_array( $Baths ) ? min( $Baths ) : $Baths;
}
private function BathsMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
$Baths = $this->GetBaths( $property );
return is_array( $Baths ) ? max( $Baths ) : $Baths;
}
/*
.o8888 .o88o. .o8888 88 88 888888 88 88 8888o. 8888o. .o88o. 888888 888888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
88 888888 88 888888 8888 88 88 8888Y' 88 88 888888 88 8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
'Y8888 88 88 'Y8888 88 88 888888 'Y88Y' 88 8888Y' 88 88 88 888888
*/
private function UpdateCaches( \Pimcore\Model\DataObject\YardiProperty $property ) {
/*
file_put_contents(
dirname( __FILE__ ).'/debug_timestamps.log',
"\nProperty Cache: ".(int)$property->getTimestamp_property()." (".strtotime( 'now -1 day' ).")".
"\nFloorplan Cache: ".(int)$property->getTimestamp_floorplan()." (".strtotime( 'now -1 day' ).")".
"\nProperty Images Cache: ".(int)$property->getTimestamp_images_property()." (".strtotime( 'now -1 hour' ).")".
"\nUnit Images Cache: ".(int)$property->getTimestamp_images_unit()." (".strtotime( 'now -1 hour' ).")".
"\nResident Portal Cache: ".(int)$property->getTimestamp_resident_portal()." (".strtotime( 'now -1 day' ).")".
"\nWalkscore Cache: ".(int)$property->getTimestamp_walkscore()." (".strtotime( 'now -1 day' ).")".
"\nFacebook Cache: ".(int)$property->getTimestamp_facebook()." (".strtotime( 'now -1 hour' ).")".
"\nTwitter Cache: ".(int)$property->getTimestamp_twitter()." (".strtotime( 'now -1 hour' ).")"
);
*/
// Property Data...
if( (int)$property->getTimestamp_property() < strtotime( 'now -1 day' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_property.log', time() );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, trim( $api_url, '/' ).'/rentcafeapi.aspx?requestType=property&type=marketingData&apiToken='.$api_key.'&propertyId='.$api_pid );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_property( $result );
$property->setTimestamp_property( time() );
// This is needed for property listing pages to work smoothly...
$property_json = json_decode( $result );
if( $property_json ) {
$property->setState( \Pimcore\File::getValidFilename( $property_json[ 0 ]->PropertyData->state ) );
$property->setCity( \Pimcore\File::getValidFilename( $property_json[ 0 ]->PropertyData->city ) );
}
}
// Floorplan Data...
if( (int)$property->getTimestamp_floorplan() < strtotime( 'now -1 day' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_floorplan.log', time() );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, trim( $api_url, '/' ).'/rentcafeapi.aspx?requestType=floorplan&apiToken='.$api_key.'&propertyId='.$api_pid );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_floorplan( $result );
$property->setTimestamp_floorplan( time() );
}
// Property Images...
if( (int)$property->getTimestamp_images_property() < strtotime( 'now -1 hour' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_images_property.log', time() );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, trim( $api_url, '/' ).'/rentcafeapi.aspx?requestType=images&type=propertyImages&apiToken='.$api_key.'&propertyId='.$api_pid );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_images_property( $result );
$property->setTimestamp_images_property( time() );
}
// Unit Images...
if( (int)$property->getTimestamp_images_unit() < strtotime( 'now -1 hour' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_images_unit.log', time() );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, trim( $api_url, '/' ).'/rentcafeapi.aspx?requestType=images&type=unitImages&apiToken='.$api_key.'&propertyId='.$api_pid );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_images_unit( $result );
$property->setTimestamp_images_unit( time() );
}
// Resident Portal...
if( (int)$property->getTimestamp_resident_portal() < strtotime( 'now -1 day' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_resident_portal.log', time() );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, trim( $api_url, '/' ).'/rentcafeapi.aspx?requestType=getRENTCafeURL&type=residentLogin&apiToken='.$api_key.'&propertyId='.$api_pid );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_resident_portal( $result );
$property->setTimestamp_resident_portal( time() );
}
// Walkscore...
if( (int)$property->getTimestamp_walkscore() < strtotime( 'now -1 day' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_walkscore.log', time() );
$cache_data = json_decode( $property->getCache_property() );
if( !empty( $cache_data ) && !$cache_data[ 0 ]->Error ) {
$property_data = $cache_data[ 0 ]->PropertyData;
$lat = $property_data->Latitude;
$lon = $property_data->Longitude;
$address = urlencode( stripslashes( $property_data->address." ".$property_data->city." ".$property_data->state." ".$property_data->zipcode ) );
$walkscore_setting = \Pimcore\Model\WebsiteSetting::getByName( 'walkscore_token' );
$walkscore_token = $walkscore_setting->getData();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, "http://api.walkscore.com/score?format=json&transit=1&address=".$address."&lat=".$lat."&lon=".$lon."&wsapikey=".$walkscore_token );
$result = curl_exec( $ch );
$result = str_replace( "\\"."\\".'"', "\\".'"', $result ); // Yardi does dumb stuff...
curl_close( $ch );
$property->setCache_walkscore( $result );
$property->setTimestamp_walkscore( time() );
}
}
// Facebook...
if( (int)$property->getTimestamp_facebook() < strtotime( 'now -1 hour' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_facebook.log', time() );
if( !empty( $property->getFacebook() ) ) {
// Load SDK
require_once dirname( __FILE__ ).'../../../../vendor/facebook/graph-sdk/src/Facebook/autoload.php';
// Get Facebook Account
$fb_account = $property->getFacebook();
// Get Facebook App ID
$fb_id_setting = \Pimcore\Model\WebsiteSetting::getByName( 'fb_app_id' );
$fb_app_id = $fb_id_setting->getData();
// Get Facebook App Secret
$fb_secret_setting = \Pimcore\Model\WebsiteSetting::getByName( 'fb_app_secret' );
$fb_app_secret = $fb_secret_setting->getData();
// Get Facebook App Token
$fb_app_setting = \Pimcore\Model\WebsiteSetting::getByName( 'fb_app_token' );
$fb_app_token = $fb_app_setting->getData();
// Get Facebook token
$fb = new \Facebook\Facebook( [
'app_id' => $fb_app_id,
'app_secret' => $fb_app_secret,
'default_graph_version' => 'v2.11',
'default_access_token' => $fb_app_token,
] );
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/'.$fb_account.'/feed',
$fb_app_token
);
} catch( Facebook\Exceptions\FacebookResponseException $e ) {
die( 'Graph returned an error: '.$e->getMessage() );
} catch( Facebook\Exceptions\FacebookSDKException $e ) {
die( 'Facebook SDK returned an error: '.$e->getMessage() );
}
$graphEdge = $response->getGraphEdge();
// file_put_contents(dirname(__FILE__)."/testing_fb_api.txt", $graphEdge);
// Assign fields
$property->setCache_facebook( $graphEdge );
$property->setTimestamp_facebook( time() );
}
}
// Twitter...
if( (int)$property->getTimestamp_twitter() < strtotime( 'now -1 hour' ) ) {
//file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_twitter.log', time() );
if( !empty( $property->getTwitter() ) ) {
// Load Class
require_once dirname(__FILE__) . '../../../../web/theme/php/twitter/twitter-api-php-master/TwitterAPIExchange.php';
// Get Twitter Account
$tw_account = $property->getTwitter();
// Get Twitter Consumer Key
$tw_key_setting = \Pimcore\Model\WebsiteSetting::getByName( 'tw_consumer_key' );
$tw_key = $tw_key_setting->getData();
// Get Twitter Consumer Secret
$tw_secret_setting = \Pimcore\Model\WebsiteSetting::getByName( 'tw_consumer_secret' );
$tw_secret = $tw_secret_setting->getData();
// Get Twitter Access Token
$tw_access_token_setting = \Pimcore\Model\WebsiteSetting::getByName( 'tw_access_token' );
$tw_access_token = $tw_access_token_setting->getData();
// Get Twitter Access Secret
$tw_access_secret_setting = \Pimcore\Model\WebsiteSetting::getByName( 'tw_access_secret' );
$tw_access_secret = $tw_access_secret_setting->getData();
// Set access tokens here.
$settings = array(
'oauth_access_token' => $tw_access_token,
'oauth_access_token_secret' => $tw_access_secret,
'consumer_key' => $tw_key,
'consumer_secret' => $tw_secret
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name='.$tw_account.'&count=10';
$requestMethod = 'GET';
// Use TwitterAPIExchange
$twitter = new \TwitterAPIExchange( $settings );
$result = $twitter->setGetfield( $getfield )
->buildOauth( $url, $requestMethod )
->performRequest();
// Assign fields
$property->setCache_twitter( $result );
$property->setTimestamp_twitter( time() );
}
}
// Save the data...
$property->save();
}
/*
.o88o. .o8888 888888 88 .o88o. 8888o. 88 88 .o8888 888888 88 8888o. .o8888 .o8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
888888 88 88 88 88 88 88 88 88 88 'Y88o. 88 88 88 88 88 88 'Y88o.
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 'Y8888 88 88 'Y88Y' 88 88 888888 88 8888Y' 88 88 88 88 'Y8888 8888Y'
*/
public function listingsAction( Request $request ) {
$labels = array(
'states' => array(
'dc' => 'District of Columbia',
'va' => 'Virginia',
'md' => 'Maryland',
'fl' => 'Florida'
),
'cities' => array(),
'properties' => array()
);
// Route params...
$state = ( empty( $request->get( 'state' ) ) ? null : $request->get( 'state' ) );
$city = ( empty( $request->get( 'city' ) ) ? null : $request->get( 'city' ) );
$name = ( empty( $request->get( 'name' ) ) ? null : $request->get( 'name' ) );
$details = ( empty( $request->get( 'details' ) ) ? null : $request->get( 'details' ) );
// Attempt finding SEO text for the listing...
$seo_hero = null;
$seo_text = null;
if( !empty( $state ) ) {
$SeoObjects = \Pimcore\Model\DataObject\VmApartmentsSeoText::getByState( $state );
if( $SeoObjects ) {
foreach( $SeoObjects as $SeoObject ) {
if( method_exists( $SeoObject, 'getState_text' ) ) {
$seo_text = $SeoObject->getState_text();
}
if( method_exists( $SeoObject, 'getHero_image' ) && $SeoObject->getHero_image() instanceof \Pimcore\Model\Asset\Image ) {
$seo_hero = $SeoObject->getHero_image()->getFullPath();
}
if( !empty( $city ) && method_exists( $SeoObject, 'getCities' ) ) {
foreach( $SeoObject->getCities() as $SeoObject_City ) {
if( !empty( $SeoObject_City[ 'city' ] ) && $SeoObject_City[ 'city' ]->getData() == $city ) {
if( !empty( $SeoObject_City[ 'city_text' ] ) ) {
$seo_text = $SeoObject_City[ 'city_text' ]->getData();
}
if( !empty( $SeoObject_City[ 'hero_image' ] ) && $SeoObject_City[ 'hero_image' ]->getData() instanceof \Pimcore\Model\Asset\Image ) {
$seo_hero = $SeoObject_City[ 'hero_image' ]->getData()->getFullPath();
}
}
}
}
}
}
}
$structure = array();
$PropertyObjects = new \Pimcore\Model\DataObject\YardiProperty\Listing();
foreach( $PropertyObjects as $PropertyObject ) {
$cache_data = json_decode( $PropertyObject->getCache_property() );
// Skip blanks...
if( empty( $cache_data[ 0 ]->PropertyData->state ) ) continue;
if( empty( $cache_data[ 0 ]->PropertyData->city ) ) continue;
// Generate the keys...
$state_key = strtolower( \Pimcore\File::getValidFilename( trim( $cache_data[ 0 ]->PropertyData->state ) ) );
$city_key = strtolower( \Pimcore\File::getValidFilename( trim( $cache_data[ 0 ]->PropertyData->city ) ) );
$property_key = $PropertyObject->getKey();
// Add to labels...
$labels[ 'cities' ][ $city_key ] = trim( $cache_data[ 0 ]->PropertyData->city );
$labels[ 'properties' ][ $PropertyObject->getKey() ] = trim( $cache_data[ 0 ]->PropertyData->name );
// Create arrays if needed...
if( !is_array( $structure[ $state_key ] ) ) $structure[ $state_key ] = array();
if( !is_array( $structure[ $state_key ][ $city_key ] ) ) $structure[ $state_key ][ $city_key ] = array();
// Organize the property into its location...
$structure[ $state_key ][ $city_key ][ $property_key ] = '/apartments/'.$state_key.'/'.$city_key.'/'.$property_key;
}
// Should we show a single property?
if( !empty( $state ) ) {
if( array_key_exists( $state, $structure ) ) {
if( !empty( $city ) ) {
if( array_key_exists( $city, $structure[ $state ] ) ) {
$debug = [];
$debug['name'] = $name;
$debug['state'] = $state;
$debug['city'] = $city;
$debug['structureCheck'] = $structure;
//$debug['structureCheckStateCity'] = $structure[ $state ][ $city ];
//$debug['propertyObjects'] = $PropertyObjects;
file_put_contents( dirname( __FILE__ ).'/debug.txt', print_r( $debug , true ) );
if( !empty( $name ) ) {
if( array_key_exists( $name, $structure[ $state ][ $city ] ) ) {
$property = \Pimcore\Model\DataObject::getByPath( '/YARDI/'.$name );
// $this->UpdateCaches( $property );
return $this->render( ':Yardi:property.html.php', [
'property' => $property,
'state' => $state,
'city' => $city,
'name' => $name,
'details' => $details
] );
} else {
// Name isn't real!
throw new NotFoundHttpException( 'Not found' );
}
}
} else {
// City isn't real!
throw new NotFoundHttpException( 'Not found' );
}
}
} else {
// State isn't real!
throw new NotFoundHttpException( 'Not found' );
}
}
$filtered_ids = array();
/*
* Apply the filtering groups to the list of properties returned...
*/
if( $request->get( 'filters' ) ) {
$filters = explode( '_', $request->get( 'filters' ) );
$group_listing = new \Pimcore\Model\DataObject\YardiGroup\Listing();
$group_listing->addConditionParam( 'o_key = ?', $filters[ 0 ] );
$group_objects = $group_listing->load();
if( !empty( $group_objects ) ) {
$group_object = $group_objects[ 0 ];
foreach( $group_object->getListings() as $i => $group_listing ) {
if( count( $filters ) >= 2 && (int)$i !== (int)$filters[ 1 ] ) continue;
$listing_properties = $group_listing[ 'listing_properties' ]->getData();
if( !empty( $listing_properties ) ) {
foreach( $listing_properties as $listing_property ) {
$filtered_ids[] = $listing_property->getId();
}
}
}
}
}
/*
* Apply keywords to the list of properties returned...
*/
$keywords = array();
if( $request->get( 'keywords' ) ) {
$keywords = trim( $request->get( 'keywords' ) );
$keywords = str_replace( ', ', ',', $keywords );
$keywords = str_replace( ' ,', ',', $keywords );
$keywords = explode( ',', trim( $keywords, ',' ) );
$keyword_ids = array();
$keyword_objects = new \Pimcore\Model\DataObject\YardiKeyword\Listing();
foreach( $keyword_objects as $keyword_object ) {
if( in_array( $keyword_object->getLabel(), $keywords ) ) {
$keyword_ids[] = $keyword_object->getId();
}
}
$property_listing = new \Pimcore\Model\DataObject\YardiProperty\Listing();
foreach( $property_listing as $property ) {
foreach( $property->getKeywords() as $property_keyword ) {
if( in_array( $property_keyword->getId(), $keyword_ids ) ) {
$filtered_ids[] = $property->getId();
}
}
}
}
// Start Fresh...
$found_properties = new \Pimcore\Model\DataObject\YardiProperty\Listing();
// Apply group and keyword filtering...
if( !empty( $filtered_ids ) ) {
// $found_properties->setCondition( 'o_id IN (?)', implode( ',', $filtered_ids ) ); // This should work, bug?
$found_properties->setCondition( 'o_id IN ('.implode( ',', $filtered_ids ).')' ); // Unprepared. Evil, but necessary.
}
// Add State and City requirements to query...
if( !empty( $state ) ) {
$found_properties->addConditionParam( 'state = ?', $state, 'AND' );
if( !empty( $city ) ) {
$found_properties->addConditionParam( 'city = ?', $city, 'AND' );
}
}
$final_list = array();
foreach( $found_properties as $found_property ) {
$qualified = true;
// Check if the rent is suitable...
if( $request->get( 'rent_min' ) || $request->get( 'rent_max' ) ) {
$RentMin = $this->RentMin( $found_property );
$RentMax = $this->RentMax( $found_property );
if( $RentMin && $RentMax ) {
if( $request->get( 'rent_min' ) && $RentMin < $request->get( 'rent_min' ) && $RentMax < $request->get( 'rent_min' ) ) $qualified = false;
if( $request->get( 'rent_max' ) && $RentMin > $request->get( 'rent_max' ) && $RentMax > $request->get( 'rent_max' ) ) $qualified = false;
} else {
$qualified = false;
}
}
// Check if the sqft is suitable...
if( $request->get( 'sqft_min' ) || $request->get( 'sqft_max' ) ) {
$SqftMin = $this->SqftMin( $found_property );
$SqftMax = $this->SqftMax( $found_property );
if( $SqftMin && $SqftMax ) {
if( $request->get( 'sqft_min' ) && $SqftMin < $request->get( 'sqft_min' ) && $SqftMax < $request->get( 'sqft_min' ) ) $qualified = false;
if( $request->get( 'sqft_max' ) && $SqftMin > $request->get( 'sqft_max' ) && $SqftMax > $request->get( 'sqft_max' ) ) $qualified = false;
} else {
$qualified = false;
}
}
// Check if the beds are suitable...
if( $request->get( 'beds' ) ) {
$BedsMin = $this->BedsMin( $found_property );
$BedsMax = $this->BedsMax( $found_property );
if( $BedsMin === false || $BedsMax === false ) {
$qualified = false;
} else {
if( (int)$BedsMin < (int)$request->get( 'beds' ) && (int)$BedsMax < (int)$request->get( 'beds' ) ) $qualified = false;
}
}
// Check if the baths are suitable...
if( $request->get( 'baths' ) ) {
$BathsMin = $this->BathsMin( $found_property );
$BathsMax = $this->BathsMax( $found_property );
if( $BathsMin === false || $BathsMax === false ) {
$qualified = false;
} else {
if( (int)$BathsMin < (int)$request->get( 'baths' ) && (int)$BathsMax < (int)$request->get( 'baths' ) ) $qualified = false;
}
}
// Add the property if it remains qualified...
if( $qualified ) $final_list[] = $found_property;
}
// Show the listings template instead...
if( !empty( $state ) && !array_key_exists( $state, $structure ) ) $state = null;
if( !empty( $city ) && !array_key_exists( $city, $structure[ $state ] ) ) $city = null;
return $this->render( ':Yardi:listings.html.php', [
'seo_hero' => $seo_hero,
'seo_text' => $seo_text,
'state' => $state,
'city' => $city,
'labels' => $labels,
'structure' => $structure,
'found_properties' => $final_list
] );
}
/*
.o88o. .o8888 888888 88 .o88o. 8888o. 8888o. 8888o. .o88o. 8888o. 888888 8888o. 888888 88 88
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
888888 88 88 88 88 88 88 88 8888Y' 8888Y' 88 88 8888Y' 8888 8888Y' 88 'Y8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 'Y8888 88 88 'Y88Y' 88 88 88 88 88 'Y88Y' 88 888888 88 88 88 8888Y'
*/
public function propertyAction( Request $request ) {
$property = \Pimcore\Model\DataObject::getByPath( '/YARDI/'.$request->get( 'property' ) );
if( !$property instanceof \Pimcore\Model\DataObject\YardiProperty ) {
die( 'Property does not exist!' );
// throw new NotFoundHttpException( 'Not found' );
}
}
/*
.o88o. .o8888 888888 88 .o88o. 8888o. .o88o. 88 .o88o. 88 88
88 88 88 88 88 88 88 88 88 88 88 88 88 88 '8..8'
888888 88 88 88 88 88 88 88 888888 88 888888 '88'
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 .8''8.
88 88 'Y8888 88 88 'Y88Y' 88 88 88 88 'Y88Y' 88 88 88 88
*/
public function ajaxAction( Request $request ) {
// Property-specific domain for API req.
$propDomain = $request->get( 'propDomain' );
// Grab posted values.
$url = array(
'requestType' => 'lead',
'firstName' => $request->get( 'firstName' ),
'lastName' => $request->get( 'lastName' ),
'email' => $request->get( 'email' ),
'phone' => preg_replace( '/\D+/', '', $request->get( 'phone' ) ),
'message' => $request->get( 'message' ),
'propertyId' => $request->get( 'propId' ),
'username' => 'dev@grafik.com',
'password' => 'vanmetreapi',
'source' => 'Property Page Form',
'secondarySource' => 'Property Page Form',
'addr1' => $request->get( 'address1' ),
'addr2' => $request->get( 'address2' ),
'city' => $request->get( 'city' ),
'state' => $request->get( 'state' ),
'ZIPCode' => $request->get( 'zip' )
);
// Grab the goods!
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, $propDomain."/rentcafeapi.aspx?".http_build_query($url) );
$result = curl_exec( $ch );
curl_close( $ch );
$json = json_decode( $result );
// Respond!
header( 'Content-Type: application/json' );
die( $json ? $json : json_encode( array( 'message' => $result ) ) );
}
/*
.o88o. .o8888 888888 88 .o88o. 8888o. .o8888 888888 .o88o. 8888o. .o8888 88 88 8888o. .o88o. 888888 .o88o.
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
888888 88 88 88 88 88 88 88 'Y88o. 8888 888888 8888Y' 88 888888 88 88 888888 88 888888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
88 88 'Y8888 88 88 'Y88Y' 88 88 8888Y' 888888 88 88 88 88 'Y8888 88 88 8888Y' 88 88 88 88 88
*/
public function searchdataAction( Request $request ) {
// Abbreviations...
$states_abbr = array(
'dc'=>'District of Columbia'
, 'al' => 'Alabama' , 'hi' => 'Hawaii' , 'ma' => 'Massachusetts' , 'nm' => 'New Mexico' , 'sd' => 'South Dakota'
, 'ak' => 'Alaska' , 'id' => 'Idaho' , 'mi' => 'Michigan' , 'ny' => 'New York' , 'tn' => 'Tennessee'
, 'az' => 'Arizona' , 'il' => 'Illinois' , 'mn' => 'Minnesota' , 'nc' => 'North Carolina' , 'tx' => 'Texas'
, 'ar' => 'Arkansas' , 'in' => 'Indiana' , 'ms' => 'Mississippi' , 'nd' => 'North Dakota' , 'ut' => 'Utah'
, 'ca' => 'California' , 'ia' => 'Iowa' , 'mo' => 'Missouri' , 'oh' => 'Ohio' , 'vt' => 'Vermont'
, 'co' => 'Colorado' , 'ks' => 'Kansas' , 'mt' => 'Montana' , 'ok' => 'Oklahoma' , 'va' => 'Virginia'
, 'ct' => 'Connecticut' , 'ky' => 'Kentucky' , 'ne' => 'Nebraska' , 'or' => 'Oregon' , 'wa' => 'Washington'
, 'de' => 'Delaware' , 'la' => 'Louisiana' , 'nv' => 'Nevada' , 'pa' => 'Pennsylvania' , 'wv' => 'West Virginia'
, 'fl' => 'Florida' , 'me' => 'Maine' , 'nh' => 'New Hampshire' , 'ri' => 'Rhode Island' , 'wi' => 'Wisconsin'
, 'ga' => 'Georgia' , 'md' => 'Maryland' , 'nj' => 'New Jersey' , 'sc' => 'South Carolina' , 'wy' => 'Wyoming'
);
// COMMUNITY NAMES
$Autocomplete = array();
$AutocompleteMap = array();
// STATE OR CITY
$SelectState = array();
$SelectCity = array();
// ITERATE YARDI PROPERTIES
$YardiProperties = new \Pimcore\Model\DataObject\YardiProperty\Listing();
foreach( $YardiProperties as $YardiProperty ) {
$PropertyData = json_decode( $YardiProperty->getCache_property() );
if( $PropertyData ) {
// COMMUNITY NAMES
$Autocomplete[] = $PropertyData[ 0 ]->PropertyData->name;
$AutocompleteMap[] = array(
'name' => $PropertyData[ 0 ]->PropertyData->name,
'url' => $this->generateUrl( 'Properties S_C_N', [
'state' => $YardiProperty->getState(),
'city' => $YardiProperty->getCity(),
'name' => $YardiProperty->getKey()
] )
);
// STATE OR CITY
$SelectState[ $YardiProperty->getState() ] = array(
'label' => $states_abbr[ $YardiProperty->getState() ],
'url' => $this->generateUrl( 'Properties S', [
'state' => $YardiProperty->getState()
] )
);
$SelectCity[ $YardiProperty->getCity() ] = array(
'label' => $PropertyData[ 0 ]->PropertyData->city,
'state' => $YardiProperty->getState(),
'url' => $this->generateUrl( 'Properties S_C', [
'state' => $YardiProperty->getState(),
'city' => $YardiProperty->getCity()
] )
);
}
}
// GROUP
$SelectGroup = array();
// ITERATE YARDI GROUP
$YardiGroups = new \Pimcore\Model\DataObject\YardiGroup\Listing();
foreach( $YardiGroups as $YardiGroup ) {
$SelectGroup[ $YardiGroup->getKey() ] = array(
'name' => $YardiGroup->getName(),
'listings' => array()
);
foreach( $YardiGroup->getListings() as $YardiGroupListing ) {
$SelectGroup[ $YardiGroup->getKey() ][ 'listings' ][] = array(
'title' => $YardiGroupListing[ 'listing_title' ]->getData()
);
}
}
// KEYWORD
$SelectKeyword = array();
// ITERATE YARDI KEYWORD
$YardiKeywords = new \Pimcore\Model\DataObject\YardiKeyword\Listing();
foreach( $YardiKeywords as $YardiKeyword ) {
$SelectKeyword[ $YardiKeyword->getKey() ] = array(
'id' => $YardiKeyword->getId(),
'label' => $YardiKeyword->getLabel()
);
}
$QueryParams = array();
$QueryParamsRaw = explode( '&', parse_url( $_SERVER[ 'HTTP_REFERER' ], PHP_URL_QUERY ) );
foreach( $QueryParamsRaw as $pair ) {
$pair_parts = explode( '=', $pair );
$QueryParams[ $pair_parts[ 0 ] ] = urldecode( $pair_parts[ 1 ] );
}
$QueryPath = parse_url( $_SERVER[ 'HTTP_REFERER' ], PHP_URL_PATH );
// Respond
header('Content-Type: application/json');
die( json_encode( array(
'BaseUrl' => $this->generateUrl( 'Properties' ),
'RefererUrl' => $_SERVER[ 'HTTP_REFERER' ],
'CityStateData' => array(
'SelectState' => $SelectState,
'SelectCity' => $SelectCity
),
'CommunityData' => array(
'Autocomplete' => $Autocomplete,
'AutocompleteMap' => $AutocompleteMap
),
'GroupingData' => $SelectGroup,
'KeywordData' => $SelectKeyword,
'QueryParams' => $QueryParams,
'QueryPath' => $QueryPath
) ) );
}
/*
.o88o. .o8888 888888 88 .o88o. 8888o. 888888 .o88o. 88 88 .o88o. 8888o. 88 888888 888888 .o8888
88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
888888 88 88 88 88 88 88 88 8888 888888 88 88 88 88 8888Y' 88 88 8888 'Y88o.
88 88 88 88 88 88 88 88 88 88 88 88 88 .8' 88 88 88 88 88 88 88 88
88 88 'Y8888 88 88 'Y88Y' 88 88 88 88 88 888' 'Y88Y' 88 88 88 88 888888 8888Y'
*/
public function favoritesAction( Request $request ) {
$found_properties = array();
if( !empty( $_COOKIE[ 'favorite-properties' ] ) ) {
$favorite_ids = explode( ',', $_COOKIE[ 'favorite-properties' ] );
foreach( $favorite_ids as $favorite_id ) {
$property = \Pimcore\Model\DataObject\YardiProperty::getById( (int)$favorite_id );
if( $property instanceof \Pimcore\Model\DataObject\YardiProperty ) {
$found_properties[] = $property;
}
}
}
return $this->render( ':Yardi:listings.html.php', [
'route' => $request->get( '_route' ),
'found_properties' => $found_properties
] );
}
}