src/AppBundle/Controller/ApartmentsController.php line 561

Open in your IDE?
  1. <?php
  2.     namespace AppBundle\Controller;
  3.     use Pimcore\Controller\FrontendController;
  4.     use Symfony\Component\HttpFoundation\Request;
  5.     use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6.     class ApartmentsController extends FrontendController {
  7.         /*
  8.         8888o. .o88o. 8888o. .o8888 888888    8888o. 888888 8888o. 888888
  9.         88  88 88  88 88  88 88     88        88  88 88     88  88   88  
  10.         8888Y' 888888 8888Y' 'Y88o. 8888      8888Y' 8888   88  88   88  
  11.         88     88  88 88  88     88 88        88  88 88     88  88   88  
  12.         88     88  88 88  88 8888Y' 888888    88  88 888888 88  88   88  
  13.         */
  14.         private function GetRent( \Pimcore\Model\DataObject\YardiProperty $property ) {
  15.             // Parse the cached floorplan json...
  16.             $cache_floorplan json_decode$property->getCache_floorplan() );
  17.             // Return false if there is invalid json...
  18.             if( !$cache_floorplan ) return false;
  19.             // Aggregate rent values...
  20.             $Rent = array();
  21.             foreach( $cache_floorplan as $floorplan ) {
  22.                 if( (int)$floorplan->MinimumRent $Rent[] = (int)$floorplan->MinimumRent;
  23.                 if( (int)$floorplan->MaximumRent $Rent[] = (int)$floorplan->MaximumRent;
  24.             }
  25.             // Return false if there are no rent values...
  26.             if( empty( $Rent ) ) return false;
  27.             // Return the square footage...
  28.             return $Rent;
  29.         }
  30.         private function RentMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
  31.             $Rent $this->GetRent$property );
  32.             return is_array$Rent ) ? min$Rent ) : $Rent;
  33.         }
  34.         private function RentMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
  35.             $Rent $this->GetRent$property );
  36.             return is_array$Rent ) ? max$Rent ) : $Rent;
  37.         }
  38.         /*
  39.         8888o. .o88o. 8888o. .o8888 888888    .o8888 .o88o. 888888 888888
  40.         88  88 88  88 88  88 88     88        88     88  88 88       88  
  41.         8888Y' 888888 8888Y' 'Y88o. 8888      'Y88o. 88  88 8888     88  
  42.         88     88  88 88  88     88 88            88 'Y8888 88       88  
  43.         88     88  88 88  88 8888Y' 888888    8888Y'     88 88       88  
  44.         */
  45.         private function GetSqft( \Pimcore\Model\DataObject\YardiProperty $property ) {
  46.             // Parse the cached floorplan json...
  47.             $cache_floorplan json_decode$property->getCache_floorplan() );
  48.             // Return false if there is invalid json...
  49.             if( !$cache_floorplan ) return false;
  50.             // Aggregate rent values...
  51.             $Sqft = array();
  52.             foreach( $cache_floorplan as $floorplan ) {
  53.                 if( (int)$floorplan->MinimumSQFT $Sqft[] = (int)$floorplan->MinimumSQFT;
  54.                 if( (int)$floorplan->MaximumSQFT $Sqft[] = (int)$floorplan->MaximumSQFT;
  55.             }
  56.             // Return false if there are no rent values...
  57.             if( empty( $Sqft ) ) return false;
  58.             // Return the square footage...
  59.             return $Sqft;
  60.         }
  61.         private function SqftMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
  62.             $Sqft $this->GetSqft$property );
  63.             return is_array$Sqft ) ? min$Sqft ) : $Sqft;
  64.         }
  65.         private function SqftMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
  66.             $Sqft $this->GetSqft$property );
  67.             return is_array$Sqft ) ? max$Sqft ) : $Sqft;
  68.         }
  69.         /*
  70.         8888o. .o88o. 8888o. .o8888 888888    8888o. 888888 8888o. .o8888
  71.         88  88 88  88 88  88 88     88        88  88 88     88  88 88    
  72.         8888Y' 888888 8888Y' 'Y88o. 8888      8888Y' 8888   88  88 'Y88o.
  73.         88     88  88 88  88     88 88        88  88 88     88  88     88
  74.         88     88  88 88  88 8888Y' 888888    8888Y' 888888 8888Y' 8888Y'
  75.         */
  76.         private function GetBeds( \Pimcore\Model\DataObject\YardiProperty $property ) {
  77.             // Parse the cached floorplan json...
  78.             $cache_floorplan json_decode$property->getCache_floorplan() );
  79.             // Return false if there is invalid json...
  80.             if( !$cache_floorplan ) return false;
  81.             // Aggregate rent values...
  82.             $Beds = array();
  83.             foreach( $cache_floorplan as $floorplan ) {
  84.                 $Beds[] = (int)$floorplan->Beds;
  85.             }
  86.             // Return false if there are no rent values...
  87.             if( empty( $Beds ) ) return false;
  88.             // Return the square footage...
  89.             return $Beds;
  90.         }
  91.         private function BedsMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
  92.             $Beds $this->GetBeds$property );
  93.             return is_array$Beds ) ? min$Beds ) : $Beds;
  94.         }
  95.         private function BedsMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
  96.             $Beds $this->GetBeds$property );
  97.             return is_array$Beds ) ? max$Beds ) : $Beds;
  98.         }
  99.         /*
  100.         8888o. .o88o. 8888o. .o8888 888888    8888o. .o88o. 888888 88  88 .o8888
  101.         88  88 88  88 88  88 88     88        88  88 88  88   88   88  88 88    
  102.         8888Y' 888888 8888Y' 'Y88o. 8888      8888Y' 888888   88   888888 'Y88o.
  103.         88     88  88 88  88     88 88        88  88 88  88   88   88  88     88
  104.         88     88  88 88  88 8888Y' 888888    8888Y' 88  88   88   88  88 8888Y'
  105.         */
  106.         private function GetBaths( \Pimcore\Model\DataObject\YardiProperty $property ) {
  107.             // Parse the cached floorplan json...
  108.             $cache_floorplan json_decode$property->getCache_floorplan() );
  109.             // Return false if there is invalid json...
  110.             if( !$cache_floorplan ) return false;
  111.             // Aggregate rent values...
  112.             $Baths = array();
  113.             foreach( $cache_floorplan as $floorplan ) {
  114.                 $Baths[] = (int)$floorplan->Baths;
  115.             }
  116.             // Return false if there are no rent values...
  117.             if( empty( $Baths ) ) return false;
  118.             // Return the square footage...
  119.             return $Baths;
  120.         }
  121.         private function BathsMin( \Pimcore\Model\DataObject\YardiProperty $property ) {
  122.             $Baths $this->GetBaths$property );
  123.             return is_array$Baths ) ? min$Baths ) : $Baths;
  124.         }
  125.         private function BathsMax( \Pimcore\Model\DataObject\YardiProperty $property ) {
  126.             $Baths $this->GetBaths$property );
  127.             return is_array$Baths ) ? max$Baths ) : $Baths;
  128.         }
  129.         /*
  130.         .o8888 .o88o. .o8888 88  88 888888    88  88 8888o. 8888o. .o88o. 888888 888888
  131.         88     88  88 88     88  88 88        88  88 88  88 88  88 88  88   88   88    
  132.         88     888888 88     888888 8888      88  88 8888Y' 88  88 888888   88   8888  
  133.         88     88  88 88     88  88 88        88  88 88     88  88 88  88   88   88    
  134.         'Y8888 88  88 'Y8888 88  88 888888    'Y88Y' 88     8888Y' 88  88   88   888888
  135.         */
  136.         private function UpdateCaches( \Pimcore\Model\DataObject\YardiProperty $property ) {
  137.             /*
  138.             file_put_contents(
  139.                 dirname( __FILE__ ).'/debug_timestamps.log',
  140.                 "\nProperty Cache: ".(int)$property->getTimestamp_property()." (".strtotime( 'now -1 day' ).")".
  141.                 "\nFloorplan Cache: ".(int)$property->getTimestamp_floorplan()." (".strtotime( 'now -1 day' ).")".
  142.                 "\nProperty Images Cache: ".(int)$property->getTimestamp_images_property()." (".strtotime( 'now -1 hour' ).")".
  143.                 "\nUnit Images Cache: ".(int)$property->getTimestamp_images_unit()." (".strtotime( 'now -1 hour' ).")".
  144.                 "\nResident Portal Cache: ".(int)$property->getTimestamp_resident_portal()." (".strtotime( 'now -1 day' ).")".
  145.                 "\nWalkscore Cache: ".(int)$property->getTimestamp_walkscore()." (".strtotime( 'now -1 day' ).")".
  146.                 "\nFacebook Cache: ".(int)$property->getTimestamp_facebook()." (".strtotime( 'now -1 hour' ).")".
  147.                 "\nTwitter Cache: ".(int)$property->getTimestamp_twitter()." (".strtotime( 'now -1 hour' ).")"
  148.             );
  149.             */
  150.             // Property Data...
  151.             if( (int)$property->getTimestamp_property() < strtotime'now -1 day' ) ) {
  152.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_property.log', time() );
  153.                 $ch curl_init();
  154.                 curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  155.                 curl_setopt$chCURLOPT_URLtrim$api_url'/' ).'/rentcafeapi.aspx?requestType=property&type=marketingData&apiToken='.$api_key.'&propertyId='.$api_pid );
  156.                 $result curl_exec$ch );
  157.                 $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  158.                 curl_close$ch );
  159.                 $property->setCache_property$result );
  160.                 $property->setTimestamp_propertytime() );
  161.                 // This is needed for property listing pages to work smoothly...
  162.                 $property_json json_decode$result );
  163.                 if( $property_json ) {
  164.                     $property->setState( \Pimcore\File::getValidFilename$property_json]->PropertyData->state ) );
  165.                     $property->setCity( \Pimcore\File::getValidFilename$property_json]->PropertyData->city ) );
  166.                 }
  167.             }
  168.             // Floorplan Data...
  169.             if( (int)$property->getTimestamp_floorplan() < strtotime'now -1 day' ) ) {
  170.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_floorplan.log', time() );
  171.                 $ch curl_init();
  172.                 curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  173.                 curl_setopt$chCURLOPT_URLtrim$api_url'/' ).'/rentcafeapi.aspx?requestType=floorplan&apiToken='.$api_key.'&propertyId='.$api_pid );
  174.                 $result curl_exec$ch );
  175.                 $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  176.                 curl_close$ch );
  177.                 $property->setCache_floorplan$result );
  178.                 $property->setTimestamp_floorplantime() );
  179.             }
  180.             // Property Images...
  181.             if( (int)$property->getTimestamp_images_property() < strtotime'now -1 hour' ) ) {
  182.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_images_property.log', time() );
  183.                 $ch curl_init();
  184.                 curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  185.                 curl_setopt$chCURLOPT_URLtrim$api_url'/' ).'/rentcafeapi.aspx?requestType=images&type=propertyImages&apiToken='.$api_key.'&propertyId='.$api_pid );
  186.                 $result curl_exec$ch );
  187.                 $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  188.                 curl_close$ch );
  189.                 $property->setCache_images_property$result );
  190.                 $property->setTimestamp_images_propertytime() );
  191.             }
  192.             // Unit Images...
  193.             if( (int)$property->getTimestamp_images_unit() < strtotime'now -1 hour' ) ) {
  194.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_images_unit.log', time() );
  195.                 $ch curl_init();
  196.                 curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  197.                 curl_setopt$chCURLOPT_URLtrim$api_url'/' ).'/rentcafeapi.aspx?requestType=images&type=unitImages&apiToken='.$api_key.'&propertyId='.$api_pid );
  198.                 $result curl_exec$ch );
  199.                 $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  200.                 curl_close$ch );
  201.                 $property->setCache_images_unit$result );
  202.                 $property->setTimestamp_images_unittime() );
  203.             }
  204.             // Resident Portal...
  205.             if( (int)$property->getTimestamp_resident_portal() < strtotime'now -1 day' ) ) {
  206.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_resident_portal.log', time() );
  207.                 $ch curl_init();
  208.                 curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  209.                 curl_setopt$chCURLOPT_URLtrim$api_url'/' ).'/rentcafeapi.aspx?requestType=getRENTCafeURL&type=residentLogin&apiToken='.$api_key.'&propertyId='.$api_pid );
  210.                 $result curl_exec$ch );
  211.                 $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  212.                 curl_close$ch );
  213.                 $property->setCache_resident_portal$result );
  214.                 $property->setTimestamp_resident_portaltime() );
  215.             }
  216.             // Walkscore...
  217.             if( (int)$property->getTimestamp_walkscore() < strtotime'now -1 day' ) ) {
  218.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_walkscore.log', time() );
  219.                 $cache_data json_decode$property->getCache_property() );
  220.                 if( !empty( $cache_data ) && !$cache_data]->Error ) {
  221.                     $property_data $cache_data]->PropertyData;
  222.                     $lat $property_data->Latitude;
  223.                     $lon $property_data->Longitude;
  224.                     $address urlencodestripslashes$property_data->address." ".$property_data->city." ".$property_data->state." ".$property_data->zipcode ) );
  225.                     $walkscore_setting = \Pimcore\Model\WebsiteSetting::getByName'walkscore_token' );
  226.                     $walkscore_token $walkscore_setting->getData();
  227.                     $ch curl_init();
  228.                     curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  229.                     curl_setopt$chCURLOPT_URL"http://api.walkscore.com/score?format=json&transit=1&address=".$address."&lat=".$lat."&lon=".$lon."&wsapikey=".$walkscore_token );
  230.                     $result curl_exec$ch );
  231.                     $result str_replace"\\"."\\".'"'"\\".'"'$result ); // Yardi does dumb stuff...
  232.                     curl_close$ch );
  233.                     $property->setCache_walkscore$result );
  234.                     $property->setTimestamp_walkscoretime() );
  235.                 }
  236.             }
  237.             // Facebook...
  238.             if( (int)$property->getTimestamp_facebook() < strtotime'now -1 hour' ) ) {
  239.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_facebook.log', time() );
  240.                 if( !empty( $property->getFacebook() ) ) {
  241.                     // Load SDK
  242.                     require_once dirname__FILE__ ).'../../../../vendor/facebook/graph-sdk/src/Facebook/autoload.php';
  243.                     // Get Facebook Account
  244.                     $fb_account $property->getFacebook();
  245.                     // Get Facebook App ID
  246.                     $fb_id_setting = \Pimcore\Model\WebsiteSetting::getByName'fb_app_id' );
  247.                     $fb_app_id $fb_id_setting->getData();
  248.                     // Get Facebook App Secret
  249.                     $fb_secret_setting = \Pimcore\Model\WebsiteSetting::getByName'fb_app_secret' );
  250.                     $fb_app_secret $fb_secret_setting->getData();
  251.                     // Get Facebook App Token
  252.                     $fb_app_setting = \Pimcore\Model\WebsiteSetting::getByName'fb_app_token' );
  253.                     $fb_app_token $fb_app_setting->getData();
  254.                     // Get Facebook token
  255.                     $fb = new \Facebook\Facebook( [
  256.                         'app_id'                => $fb_app_id,
  257.                         'app_secret'            => $fb_app_secret,
  258.                         'default_graph_version'    => 'v2.11',
  259.                         'default_access_token'    => $fb_app_token,
  260.                     ] );
  261.                     /* PHP SDK v5.0.0 */
  262.                     /* make the API call */
  263.                     try {
  264.                         // Returns a `Facebook\FacebookResponse` object
  265.                         $response $fb->get(
  266.                             '/'.$fb_account.'/feed',
  267.                             $fb_app_token
  268.                         );
  269.                     } catch( Facebook\Exceptions\FacebookResponseException $e ) {
  270.                         die( 'Graph returned an error: '.$e->getMessage() );
  271.                     } catch( Facebook\Exceptions\FacebookSDKException $e ) {
  272.                         die( 'Facebook SDK returned an error: '.$e->getMessage() );
  273.                     }
  274.                     $graphEdge $response->getGraphEdge();
  275.                     // file_put_contents(dirname(__FILE__)."/testing_fb_api.txt", $graphEdge);
  276.                     // Assign fields
  277.                     $property->setCache_facebook$graphEdge );
  278.                     $property->setTimestamp_facebooktime() );
  279.                 }
  280.             }
  281.             // Twitter...
  282.             if( (int)$property->getTimestamp_twitter() < strtotime'now -1 hour' ) ) {
  283.                 //file_put_contents( dirname( __FILE__ ).'/debug_getTimestamp_twitter.log', time() );
  284.                 if( !empty( $property->getTwitter() ) ) {
  285.                     // Load Class
  286.                     require_once dirname(__FILE__) . '../../../../web/theme/php/twitter/twitter-api-php-master/TwitterAPIExchange.php';
  287.                     // Get Twitter Account
  288.                     $tw_account $property->getTwitter();
  289.                     // Get Twitter Consumer Key
  290.                     $tw_key_setting = \Pimcore\Model\WebsiteSetting::getByName'tw_consumer_key' );
  291.                     $tw_key $tw_key_setting->getData();
  292.                     // Get Twitter Consumer Secret
  293.                     $tw_secret_setting = \Pimcore\Model\WebsiteSetting::getByName'tw_consumer_secret' );
  294.                     $tw_secret $tw_secret_setting->getData();
  295.                     // Get Twitter Access Token
  296.                     $tw_access_token_setting = \Pimcore\Model\WebsiteSetting::getByName'tw_access_token' );
  297.                     $tw_access_token $tw_access_token_setting->getData();
  298.                     // Get Twitter Access Secret
  299.                     $tw_access_secret_setting = \Pimcore\Model\WebsiteSetting::getByName'tw_access_secret' );
  300.                     $tw_access_secret $tw_access_secret_setting->getData();
  301.                     // Set access tokens here.
  302.                     $settings = array(
  303.                         'oauth_access_token'        => $tw_access_token,
  304.                         'oauth_access_token_secret'    => $tw_access_secret,
  305.                         'consumer_key'                => $tw_key,
  306.                         'consumer_secret'            => $tw_secret
  307.                     );
  308.                     $url 'https://api.twitter.com/1.1/statuses/user_timeline.json';
  309.                     $getfield '?screen_name='.$tw_account.'&count=10';
  310.                     $requestMethod 'GET';
  311.                     // Use TwitterAPIExchange
  312.                     $twitter = new \TwitterAPIExchange$settings );
  313.                     $result $twitter->setGetfield$getfield )
  314.                                 ->buildOauth$url$requestMethod )
  315.                                 ->performRequest();
  316.                     // Assign fields
  317.                     $property->setCache_twitter$result );
  318.                     $property->setTimestamp_twittertime() );
  319.                 }
  320.             }
  321.             // Save the data...
  322.             $property->save();
  323.         }
  324.         /*
  325.         .o88o. .o8888 888888 88 .o88o. 8888o.    88     88 .o8888 888888 88 8888o. .o8888 .o8888
  326.         88  88 88       88   88 88  88 88  88    88     88 88       88   88 88  88 88     88    
  327.         888888 88       88   88 88  88 88  88    88     88 'Y88o.   88   88 88  88 88  88 'Y88o.
  328.         88  88 88       88   88 88  88 88  88    88     88     88   88   88 88  88 88  88     88
  329.         88  88 'Y8888   88   88 'Y88Y' 88  88    888888 88 8888Y'   88   88 88  88 'Y8888 8888Y'
  330.         */
  331.         public function listingsActionRequest $request ) {
  332.             $labels = array(
  333.                 'states'        => array(
  334.                     'dc'            => 'District of Columbia',
  335.                     'va'            => 'Virginia',
  336.                     'md'            => 'Maryland',
  337.                     'fl'            => 'Florida'
  338.                 ),
  339.                 'cities'        => array(),
  340.                 'properties'    => array()
  341.             );
  342.             // Route params...
  343.             $state = ( empty( $request->get'state' ) ) ? null $request->get'state' ) );
  344.             $city = ( empty( $request->get'city' ) ) ? null $request->get'city' ) );
  345.             $name = ( empty( $request->get'name' ) ) ? null $request->get'name' ) );
  346.             $details = ( empty( $request->get'details' ) ) ? null $request->get'details' ) );
  347.             // Attempt finding SEO text for the listing...
  348.             $seo_hero null;
  349.             $seo_text null;
  350.             if( !empty( $state ) ) {
  351.                 $SeoObjects = \Pimcore\Model\DataObject\VmApartmentsSeoText::getByState$state );
  352.                 if( $SeoObjects ) {
  353.                     foreach( $SeoObjects as $SeoObject ) {
  354.                         if( method_exists$SeoObject'getState_text' ) ) {
  355.                             $seo_text $SeoObject->getState_text();
  356.                         }
  357.                         if( method_exists$SeoObject'getHero_image' ) && $SeoObject->getHero_image() instanceof \Pimcore\Model\Asset\Image ) {
  358.                             $seo_hero $SeoObject->getHero_image()->getFullPath();
  359.                         }
  360.                         if( !empty( $city ) && method_exists$SeoObject'getCities' ) ) {
  361.                             foreach( $SeoObject->getCities() as $SeoObject_City ) {
  362.                                 if( !empty( $SeoObject_City'city' ] ) && $SeoObject_City'city' ]->getData() == $city ) {
  363.                                     if( !empty( $SeoObject_City'city_text' ] ) ) {
  364.                                         $seo_text $SeoObject_City'city_text' ]->getData();
  365.                                     }
  366.                                     if( !empty( $SeoObject_City'hero_image' ] ) && $SeoObject_City'hero_image' ]->getData() instanceof \Pimcore\Model\Asset\Image ) {
  367.                                         $seo_hero $SeoObject_City'hero_image' ]->getData()->getFullPath();
  368.                                     }
  369.                                 }
  370.                             }
  371.                         }
  372.                     }
  373.                 }
  374.             }
  375.             $structure = array();
  376.             $PropertyObjects = new \Pimcore\Model\DataObject\YardiProperty\Listing();
  377.             foreach( $PropertyObjects as $PropertyObject ) {
  378.                 $cache_data json_decode$PropertyObject->getCache_property() );
  379.                 // Skip blanks...
  380.                 if( empty( $cache_data]->PropertyData->state ) ) continue;
  381.                 if( empty( $cache_data]->PropertyData->city ) ) continue;
  382.                 // Generate the keys...
  383.                 $state_key strtolower( \Pimcore\File::getValidFilenametrim$cache_data]->PropertyData->state ) ) );
  384.                 $city_key strtolower( \Pimcore\File::getValidFilenametrim$cache_data]->PropertyData->city ) ) );
  385.                 $property_key $PropertyObject->getKey();
  386.                 // Add to labels...
  387.                 $labels'cities' ][ $city_key ] = trim$cache_data]->PropertyData->city );
  388.                 $labels'properties' ][ $PropertyObject->getKey() ] = trim$cache_data]->PropertyData->name );
  389.                 // Create arrays if needed...
  390.                 if( !is_array$structure$state_key ] ) ) $structure$state_key ] = array();
  391.                 if( !is_array$structure$state_key ][ $city_key ] ) ) $structure$state_key ][ $city_key ] = array();
  392.                 // Organize the property into its location...
  393.                 $structure$state_key ][ $city_key ][ $property_key ] = '/apartments/'.$state_key.'/'.$city_key.'/'.$property_key;
  394.             }
  395.             // Should we show a single property?
  396.             if( !empty( $state ) ) {
  397.                 if( array_key_exists$state$structure ) ) {
  398.                     if( !empty( $city ) ) {
  399.                         if( array_key_exists$city$structure$state ] ) ) {
  400.                             $debug = [];
  401.                             $debug['name'] = $name;
  402.                             $debug['state'] = $state;
  403.                             $debug['city'] = $city;
  404.                             $debug['structureCheck'] = $structure;
  405.                             //$debug['structureCheckStateCity'] = $structure[ $state ][ $city ];
  406.                             //$debug['propertyObjects'] = $PropertyObjects;
  407.                             file_put_contentsdirname__FILE__ ).'/debug.txt'print_r$debug true ) );
  408.                             if( !empty( $name ) ) {
  409.                                 if( array_key_exists$name$structure$state ][ $city ] ) ) {
  410.                                     $property = \Pimcore\Model\DataObject::getByPath'/YARDI/'.$name );
  411.                                     // $this->UpdateCaches( $property );
  412.                                     return $this->render':Yardi:property.html.php', [
  413.                                         'property' => $property,
  414.                                         'state' => $state,
  415.                                         'city' => $city,
  416.                                         'name' => $name,
  417.                                         'details' => $details
  418.                                     ] );
  419.                                 } else {
  420.                                     // Name isn't real!
  421.                                     throw new NotFoundHttpException'Not found' );
  422.                                 }
  423.                             }
  424.                         } else {
  425.                             // City isn't real!
  426.                             throw new NotFoundHttpException'Not found' );
  427.                         }
  428.                     }
  429.                 } else {
  430.                     // State isn't real!
  431.                     throw new NotFoundHttpException'Not found' );
  432.                 }
  433.             }
  434.             $filtered_ids = array();
  435.             /*
  436.              * Apply the filtering groups to the list of properties returned...
  437.              */
  438.             if( $request->get'filters' ) ) {
  439.                 $filters explode'_'$request->get'filters' ) );
  440.                 $group_listing = new \Pimcore\Model\DataObject\YardiGroup\Listing();
  441.                 $group_listing->addConditionParam'o_key = ?'$filters] );
  442.                 $group_objects $group_listing->load();
  443.                 if( !empty( $group_objects ) ) {
  444.                     $group_object $group_objects];
  445.                     foreach( $group_object->getListings() as $i => $group_listing ) {
  446.                         if( count$filters ) >= && (int)$i !== (int)$filters] ) continue;
  447.                         $listing_properties $group_listing'listing_properties' ]->getData();
  448.                         if( !empty( $listing_properties ) ) {
  449.                             foreach( $listing_properties as $listing_property ) {
  450.                                 $filtered_ids[] = $listing_property->getId();
  451.                             }
  452.                         }
  453.                     }
  454.                 }
  455.             }
  456.             /*
  457.              * Apply keywords to the list of properties returned...
  458.              */
  459.             $keywords = array();
  460.             if( $request->get'keywords' ) ) {
  461.                 $keywords trim$request->get'keywords' ) );
  462.                 $keywords str_replace', '','$keywords );
  463.                 $keywords str_replace' ,'','$keywords );
  464.                 $keywords explode','trim$keywords',' ) );
  465.                 $keyword_ids = array();
  466.                 $keyword_objects = new \Pimcore\Model\DataObject\YardiKeyword\Listing();
  467.                 foreach( $keyword_objects as $keyword_object ) {
  468.                     if( in_array$keyword_object->getLabel(), $keywords ) ) {
  469.                         $keyword_ids[] = $keyword_object->getId();
  470.                     }
  471.                 }
  472.                 $property_listing = new \Pimcore\Model\DataObject\YardiProperty\Listing();
  473.                 foreach( $property_listing as $property ) {
  474.                     foreach( $property->getKeywords() as $property_keyword ) {
  475.                         if( in_array$property_keyword->getId(), $keyword_ids ) ) {
  476.                             $filtered_ids[] = $property->getId();
  477.                         }
  478.                     }
  479.                 }
  480.             }
  481.             // Start Fresh...
  482.             $found_properties = new \Pimcore\Model\DataObject\YardiProperty\Listing();
  483.             // Apply group and keyword filtering...
  484.             if( !empty( $filtered_ids ) ) {
  485.                 // $found_properties->setCondition( 'o_id IN (?)', implode( ',', $filtered_ids ) ); // This should work, bug?
  486.                 $found_properties->setCondition'o_id IN ('.implode','$filtered_ids ).')' ); // Unprepared. Evil, but necessary.
  487.             }
  488.             // Add State and City requirements to query...
  489.             if( !empty( $state ) ) {
  490.                 $found_properties->addConditionParam'state = ?'$state'AND' );
  491.                 if( !empty( $city ) ) {
  492.                     $found_properties->addConditionParam'city = ?'$city'AND' );
  493.                 }
  494.             }
  495.             $final_list = array();
  496.             foreach( $found_properties as $found_property ) {
  497.                 $qualified true;
  498.                 // Check if the rent is suitable...
  499.                 if( $request->get'rent_min' ) || $request->get'rent_max' ) ) {
  500.                     $RentMin $this->RentMin$found_property );
  501.                     $RentMax $this->RentMax$found_property );
  502.                     if( $RentMin && $RentMax ) {
  503.                         if( $request->get'rent_min' ) && $RentMin $request->get'rent_min' ) && $RentMax $request->get'rent_min' ) ) $qualified false;
  504.                         if( $request->get'rent_max' ) && $RentMin $request->get'rent_max' ) && $RentMax $request->get'rent_max' ) ) $qualified false;
  505.                     } else {
  506.                         $qualified false;
  507.                     }
  508.                 }
  509.                 // Check if the sqft is suitable...
  510.                 if( $request->get'sqft_min' ) || $request->get'sqft_max' ) ) {
  511.                     $SqftMin $this->SqftMin$found_property );
  512.                     $SqftMax $this->SqftMax$found_property );
  513.                     if( $SqftMin && $SqftMax ) {
  514.                         if( $request->get'sqft_min' ) && $SqftMin $request->get'sqft_min' ) && $SqftMax $request->get'sqft_min' ) ) $qualified false;
  515.                         if( $request->get'sqft_max' ) && $SqftMin $request->get'sqft_max' ) && $SqftMax $request->get'sqft_max' ) ) $qualified false;
  516.                     } else {
  517.                         $qualified false;
  518.                     }
  519.                 }
  520.                 // Check if the beds are suitable...
  521.                 if( $request->get'beds' ) ) {
  522.                     $BedsMin $this->BedsMin$found_property );
  523.                     $BedsMax $this->BedsMax$found_property );
  524.                     if( $BedsMin === false || $BedsMax === false ) {
  525.                         $qualified false;
  526.                     } else {
  527.                         if( (int)$BedsMin < (int)$request->get'beds' ) && (int)$BedsMax < (int)$request->get'beds' ) ) $qualified false;
  528.                     }
  529.                 }
  530.                 // Check if the baths are suitable...
  531.                 if( $request->get'baths' ) ) {
  532.                     $BathsMin $this->BathsMin$found_property );
  533.                     $BathsMax $this->BathsMax$found_property );
  534.                     if( $BathsMin === false || $BathsMax === false ) {
  535.                         $qualified false;
  536.                     } else {
  537.                         if( (int)$BathsMin < (int)$request->get'baths' ) && (int)$BathsMax < (int)$request->get'baths' ) ) $qualified false;
  538.                     }
  539.                 }
  540.                 // Add the property if it remains qualified...
  541.                 if( $qualified $final_list[] = $found_property;
  542.             }
  543.             // Show the listings template instead...
  544.             if( !empty( $state ) && !array_key_exists$state$structure ) ) $state null;
  545.             if( !empty( $city ) && !array_key_exists$city$structure$state ] ) ) $city null;
  546.             return $this->render':Yardi:listings.html.php', [
  547.                 'seo_hero' => $seo_hero,
  548.                 'seo_text' => $seo_text,
  549.                 'state' => $state,
  550.                 'city' => $city,
  551.                 'labels' => $labels,
  552.                 'structure' => $structure,
  553.                 'found_properties' => $final_list
  554.             ] );
  555.         }
  556.         /*
  557.         .o88o. .o8888 888888 88 .o88o. 8888o.    8888o. 8888o. .o88o. 8888o. 888888 8888o. 888888 88  88
  558.         88  88 88       88   88 88  88 88  88    88  88 88  88 88  88 88  88 88     88  88   88   88  88
  559.         888888 88       88   88 88  88 88  88    8888Y' 8888Y' 88  88 8888Y' 8888   8888Y'   88   'Y8888
  560.         88  88 88       88   88 88  88 88  88    88     88  88 88  88 88     88     88  88   88       88
  561.         88  88 'Y8888   88   88 'Y88Y' 88  88    88     88  88 'Y88Y' 88     888888 88  88   88   8888Y'
  562.         */
  563.         public function propertyActionRequest $request ) {
  564.             $property = \Pimcore\Model\DataObject::getByPath'/YARDI/'.$request->get'property' ) );
  565.             if( !$property instanceof \Pimcore\Model\DataObject\YardiProperty ) {
  566.                 die( 'Property does not exist!' );
  567.                 // throw new NotFoundHttpException( 'Not found' );
  568.             }
  569.             
  570.         }
  571.         /*
  572.         .o88o. .o8888 888888 88 .o88o. 8888o.    .o88o.     88 .o88o. 88  88
  573.         88  88 88       88   88 88  88 88  88    88  88     88 88  88 '8..8'
  574.         888888 88       88   88 88  88 88  88    888888     88 888888  '88' 
  575.         88  88 88       88   88 88  88 88  88    88  88 88  88 88  88 .8''8.
  576.         88  88 'Y8888   88   88 'Y88Y' 88  88    88  88 'Y88Y' 88  88 88  88
  577.         */
  578.         public function ajaxActionRequest $request ) {
  579.             // Property-specific domain for API req.
  580.             $propDomain $request->get'propDomain' );
  581.             // Grab posted values.     
  582.             $url = array(
  583.                 'requestType'        => 'lead',
  584.                 'firstName'            => $request->get'firstName' ),
  585.                 'lastName'            => $request->get'lastName' ),
  586.                 'email'                => $request->get'email' ),
  587.                 'phone'                => preg_replace'/\D+/'''$request->get'phone' ) ),
  588.                 'message'            => $request->get'message' ),
  589.                 'propertyId'        => $request->get'propId' ),
  590.                 'username'            => 'dev@grafik.com',
  591.                 'password'            => 'vanmetreapi',
  592.                 'source'            => 'Property Page Form',
  593.                 'secondarySource'    => 'Property Page Form',
  594.                 'addr1'                => $request->get'address1' ),
  595.                 'addr2'                => $request->get'address2' ),
  596.                 'city'                => $request->get'city' ),
  597.                 'state'                => $request->get'state' ),
  598.                 'ZIPCode'            => $request->get'zip' )
  599.             );
  600.             // Grab the goods!
  601.             $ch curl_init();
  602.             curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
  603.             curl_setopt$chCURLOPT_URL$propDomain."/rentcafeapi.aspx?".http_build_query($url) );
  604.             $result curl_exec$ch );
  605.             curl_close$ch );
  606.             $json json_decode$result );
  607.             // Respond!
  608.             header'Content-Type: application/json' );
  609.             die( $json $json json_encode( array( 'message' => $result ) ) );
  610.         }
  611.         /*
  612.         .o88o. .o8888 888888 88 .o88o. 8888o.    .o8888 888888 .o88o. 8888o. .o8888 88  88 8888o. .o88o. 888888 .o88o.
  613.         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
  614.         888888 88       88   88 88  88 88  88    'Y88o. 8888   888888 8888Y' 88     888888 88  88 888888   88   888888
  615.         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
  616.         88  88 'Y8888   88   88 'Y88Y' 88  88    8888Y' 888888 88  88 88  88 'Y8888 88  88 8888Y' 88  88   88   88  88
  617.         */
  618.         public function searchdataActionRequest $request ) {
  619.             // Abbreviations...
  620.             $states_abbr = array(
  621.                 'dc'=>'District of Columbia'
  622.                 'al' => 'Alabama'            'hi' => 'Hawaii'            'ma' => 'Massachusetts'    'nm' => 'New Mexico'        'sd' => 'South Dakota'
  623.                 'ak' => 'Alaska'            'id' => 'Idaho'            'mi' => 'Michigan'        'ny' => 'New York'        'tn' => 'Tennessee'
  624.                 'az' => 'Arizona'            'il' => 'Illinois'        'mn' => 'Minnesota'        'nc' => 'North Carolina'    'tx' => 'Texas'
  625.                 'ar' => 'Arkansas'        'in' => 'Indiana'            'ms' => 'Mississippi'        'nd' => 'North Dakota'    'ut' => 'Utah'
  626.                 'ca' => 'California'        'ia' => 'Iowa'            'mo' => 'Missouri'        'oh' => 'Ohio'            'vt' => 'Vermont'
  627.                 'co' => 'Colorado'        'ks' => 'Kansas'            'mt' => 'Montana'            'ok' => 'Oklahoma'        'va' => 'Virginia'
  628.                 'ct' => 'Connecticut'        'ky' => 'Kentucky'        'ne' => 'Nebraska'        'or' => 'Oregon'            'wa' => 'Washington'
  629.                 'de' => 'Delaware'        'la' => 'Louisiana'        'nv' => 'Nevada'            'pa' => 'Pennsylvania'    'wv' => 'West Virginia'
  630.                 'fl' => 'Florida'            'me' => 'Maine'            'nh' => 'New Hampshire'    'ri' => 'Rhode Island'    'wi' => 'Wisconsin'
  631.                 'ga' => 'Georgia'            'md' => 'Maryland'        'nj' => 'New Jersey'        'sc' => 'South Carolina'    'wy' => 'Wyoming'
  632.             );
  633.             // COMMUNITY NAMES
  634.             $Autocomplete = array();
  635.             $AutocompleteMap = array();
  636.             // STATE OR CITY
  637.             $SelectState = array();
  638.             $SelectCity = array();
  639.             // ITERATE YARDI PROPERTIES
  640.             $YardiProperties = new \Pimcore\Model\DataObject\YardiProperty\Listing();
  641.             foreach( $YardiProperties as $YardiProperty ) {
  642.                 $PropertyData json_decode$YardiProperty->getCache_property() );
  643.                 if( $PropertyData ) {
  644.                     // COMMUNITY NAMES
  645.                     $Autocomplete[] = $PropertyData]->PropertyData->name;
  646.                     $AutocompleteMap[] = array(
  647.                         'name' => $PropertyData]->PropertyData->name,
  648.                         'url' => $this->generateUrl'Properties S_C_N', [
  649.                             'state' => $YardiProperty->getState(),
  650.                             'city' => $YardiProperty->getCity(),
  651.                             'name' => $YardiProperty->getKey()
  652.                         ] )
  653.                     );
  654.                     // STATE OR CITY
  655.                     $SelectState$YardiProperty->getState() ] = array(
  656.                         'label' => $states_abbr$YardiProperty->getState() ],
  657.                         'url' => $this->generateUrl'Properties S', [
  658.                             'state' => $YardiProperty->getState()
  659.                         ] )
  660.                     );
  661.                     $SelectCity$YardiProperty->getCity() ] = array(
  662.                         'label' => $PropertyData]->PropertyData->city,
  663.                         'state' => $YardiProperty->getState(),
  664.                         'url' => $this->generateUrl'Properties S_C', [
  665.                             'state' => $YardiProperty->getState(),
  666.                             'city' => $YardiProperty->getCity()
  667.                         ] )
  668.                     );
  669.                 }
  670.             }
  671.             // GROUP
  672.             $SelectGroup = array();
  673.             // ITERATE YARDI GROUP
  674.             $YardiGroups = new \Pimcore\Model\DataObject\YardiGroup\Listing();
  675.             foreach( $YardiGroups as $YardiGroup ) {
  676.                 $SelectGroup$YardiGroup->getKey() ] = array(
  677.                     'name' => $YardiGroup->getName(),
  678.                     'listings' => array()
  679.                 );
  680.                 foreach( $YardiGroup->getListings() as $YardiGroupListing ) {
  681.                     $SelectGroup$YardiGroup->getKey() ][ 'listings' ][] = array(
  682.                         'title' => $YardiGroupListing'listing_title' ]->getData()
  683.                     );
  684.                 }
  685.             }
  686.             // KEYWORD
  687.             $SelectKeyword = array();
  688.             // ITERATE YARDI KEYWORD
  689.             $YardiKeywords = new \Pimcore\Model\DataObject\YardiKeyword\Listing();
  690.             foreach( $YardiKeywords as $YardiKeyword ) {
  691.                 $SelectKeyword$YardiKeyword->getKey() ] = array(
  692.                     'id' => $YardiKeyword->getId(),
  693.                     'label' => $YardiKeyword->getLabel()
  694.                 );
  695.             }
  696.             $QueryParams = array();
  697.             $QueryParamsRaw explode'&'parse_url$_SERVER'HTTP_REFERER' ], PHP_URL_QUERY ) );
  698.             foreach( $QueryParamsRaw as $pair ) {
  699.                 $pair_parts explode'='$pair );
  700.                 $QueryParams$pair_parts] ] = urldecode$pair_parts] );
  701.             }
  702.             $QueryPath parse_url$_SERVER'HTTP_REFERER' ], PHP_URL_PATH );
  703.             // Respond
  704.             header('Content-Type: application/json');
  705.             die( json_encode( array(
  706.                 'BaseUrl' => $this->generateUrl'Properties' ),
  707.                 'RefererUrl' => $_SERVER'HTTP_REFERER' ],
  708.                 'CityStateData' => array(
  709.                     'SelectState' => $SelectState,
  710.                     'SelectCity' => $SelectCity
  711.                 ),
  712.                 'CommunityData' => array(
  713.                     'Autocomplete' => $Autocomplete,
  714.                     'AutocompleteMap' => $AutocompleteMap
  715.                 ),
  716.                 'GroupingData' => $SelectGroup,
  717.                 'KeywordData' => $SelectKeyword,
  718.                 'QueryParams' => $QueryParams,
  719.                 'QueryPath' => $QueryPath
  720.             ) ) );
  721.         }
  722.         /*
  723.         .o88o. .o8888 888888 88 .o88o. 8888o.    888888 .o88o. 88  88 .o88o. 8888o. 88 888888 888888 .o8888
  724.         88  88 88       88   88 88  88 88  88    88     88  88 88  88 88  88 88  88 88   88   88     88    
  725.         888888 88       88   88 88  88 88  88    8888   888888 88  88 88  88 8888Y' 88   88   8888   'Y88o.
  726.         88  88 88       88   88 88  88 88  88    88     88  88 88 .8' 88  88 88  88 88   88   88         88
  727.         88  88 'Y8888   88   88 'Y88Y' 88  88    88     88  88 888'   'Y88Y' 88  88 88   88   888888 8888Y'
  728.         */
  729.         public function favoritesActionRequest $request ) {
  730.             $found_properties = array();
  731.             if( !empty( $_COOKIE'favorite-properties' ] ) ) {
  732.                 $favorite_ids explode','$_COOKIE'favorite-properties' ] );
  733.                 foreach( $favorite_ids as $favorite_id ) {
  734.                     $property = \Pimcore\Model\DataObject\YardiProperty::getById( (int)$favorite_id );
  735.                     if( $property instanceof \Pimcore\Model\DataObject\YardiProperty ) {
  736.                         $found_properties[] = $property;
  737.                     }
  738.                 }
  739.             }
  740.             return $this->render':Yardi:listings.html.php', [
  741.                 'route' => $request->get'_route' ),
  742.                 'found_properties' => $found_properties
  743.             ] );
  744.         }
  745.     }