Esempio n. 1
0
 function view($id = null)
 {
     //$this->layout = 'map_only';
     //$this->Property->recursive = 1;
     $property = $this->Property->read(null, $id);
     if (empty($property)) {
         /*
         			$this->Session->setFlash('Invalid Property Id');
         			$this->redirect('index');
         */
         //	$this->cakeError('error404',array(array('url'=> $this->params['url']['url'])));
     } else {
         App::import('Helper', 'Text');
         App::import('Helper', 'Number');
         $text = new TextHelper();
         $number = new NumberHelper();
         $city = $this->City->find('first', array('conditions' => array('City.name' => array($property['Property']['City']))));
         //debug($city);
         // image setup
         // primary image
         // load agent record for extra data
         $this->MemberAgent->recursive = -1;
         $agent = $this->MemberAgent->find('first', array('conditions' => array('MemberAgent.Agent_Email_Address' => $property['Property']['Agent_Email_Address']), 'fields' => 'MemberAgent.Agent_License'));
         $property['Property']['Agent_License'] = $agent['MemberAgent']['Agent_License'];
         $co_agent = $this->MemberAgent->find('first', array('conditions' => array('MemberAgent.Agent_Email_Address' => $property['Property']['Co_Agent_Email_Address']), 'fields' => 'MemberAgent.Agent_License'));
         $property['Property']['Co_Agent_License'] = $co_agent['MemberAgent']['Agent_License'];
         /* 						debug($agent); */
         if (!empty($property['Property']['Primary_Picture_Url'])) {
             // main image exists
             $image_attributes = null;
             // first try to get image attributes from local cache
             $cached_image = WWW_ROOT . 'img_cache_fullsize/' . md5(base64_encode($property['Property']['Primary_Picture_Url']));
             if (is_file($cached_image)) {
                 $image_size = @getimagesize($cached_image);
             } else {
                 // otherwise try to get image size from remote site
                 $image_size = @getimagesize($property['Property']['Primary_Picture_Url']);
             }
             if (!empty($image_size)) {
                 $image_attributes = array('height' => $image_size[1], 'width' => $image_size[0], 'alt' => 'Primary Image', 'title' => 'Primary Image');
             } else {
                 $image_attributes = null;
             }
             $primary_image['source'] = $property['Property']['Primary_Picture_Url'];
             //$primary_image['source'] = '/listings/fullsize_image/'.base64_encode($property['Property']['Primary_Picture_Url']);
             $primary_image['attributes'] = $image_attributes;
         } else {
             // main images does not exist
             $primary_image['source'] = $html->image('/img/mls-no-image.gif');
             // the "no image" thumb
             $primary_image['attributes'] = array('height' => 90, 'width' => 125);
         }
         // find any secondary images
         //	$secondary_images = $this->_extra_images($property['Property']['Primary_Picture_Url'], $property['Property']['ML_Number_Display']);
         //	$secondary_images = $this->_extra_images($property['Property']['ML_Number_Display'], $property['Property']['Pictures_Count']);
         $secondary_images = $property['Property']['Pictures_Count'];
         // finished image setup
         $neighbors = $this->Property->find('neighbors', array('fields' => array('Property.ML_Number_Display')));
         // get most recent DB update time
         $db_updated = $this->UpdateLog->find('all', array('order' => 'modified DESC', 'limit' => 1, 'fields' => 'modified'));
         /*
         $allowed_fields = array(
         	// add all the fields we want to show here
         	'Search_Price_Display',
         	'Street_Full_Address',
         	'County',
         	'Bedrooms',
         	'Bathrooms_Display',
         	'ML_Number_Display',
         	'Acres',
         	'City',
         	'State',
         	'Street_Name',
         	'Street_Number',
         	'Street_Suffix',
         	'Zip_Code',
         	'Agent_Email_Address',
         	'Agent_Name',
         	'Bathrooms_Display',
         	'Bedrooms',
         	'County',
         	'Cross_Street',
         	'Full_Bathrooms',
         	'Half_Bathrooms',
         	'RESI_HOA_Code',
         	'RESI_HOA_Amount',
         	'RESI_HOA_Desc',
         	'Property_Agent_Email',
         	'Lot_Size_-_Sq_Ft',
         	'Lot_Size_-_Acres',
         	'Lot_Size_Source',
         	'Marketing_Remarks',
         	'Office_Broker_ID',
         	'Office_Full_Name_and_Phones',
         	'Office_Long_Name',
         	'Office_Short_Name',
         	'Office_Phone_1',
         	'Property_Subtype_1_Display',
         	'Property_Type',
         	'Search_Price_Display',
         	'Square_Footage',
         	'Status',
         	'Street_Direction',
         	'Street_Full_Address',
         	'Total_Bathrooms',
         	'RESI_Total_Rooms',
         	'Virtual_Tour_URL',
         	'Year_Built',
         	'Agent_Nickname',
         	'Lot_Size',
         	'MLS',
         	'RESI_Unit_Blk_Lot',
         	'Transaction_Type',
         	'RESI_Senior_Code',
         	'RESI_Senior_Desc',
         	'Property_Date',
         	'RESI_On_Market_Date',
         	'Agent_Phones',
         	'Agent_Phone_1',
         	'Reciprocal_Member_Name',
         	'Reciprocal_Member_Phone',
         	'Reciprocal_Office_Name',
         	'Co_Agent_Email_Address',
         	'Co_Agent_Fax_Phone',
         	'Co_Agent_Full_Name',
         	'Co_Agent_Phone_Type_1',
         	'Co_Agent_Web_Page_Address',
         	'Co_Office_Full_Name_and_Phones',
         	'RESI_2nd_Unit_on_Lot_Code',
         	'RESI_2nd_Unit_on_Lot_Desc',
         	'Property_Type',
         	'Agent_Web_Page_Address'
         );
         */
         $item = $property['Property'];
         // co-listing agent info cleanup
         if (stristr($item['Co_Agent_Full_Name'], '(ID:')) {
             $item['Co_Agent_Full_Name'] = explode('(ID:', $item['Co_Agent_Full_Name']);
             $item['Co_Agent_Full_Name'] = $item['Co_Agent_Full_Name'][0];
         }
         if (stristr($item['Co_Office_Full_Name_and_Phones'], 'Phone:')) {
             $item['Co_Office_Full_Name_and_Phones'] = explode('Phone:', $item['Co_Office_Full_Name_and_Phones']);
             $item['Co_Office_Full_Name_and_Phones'] = $item['Co_Office_Full_Name_and_Phones'][0];
         }
         $code = $item['Property_Type'];
         /* 			die($code); */
         $address_display_field = $code . '_Address_on_Internet_Desc';
         $this->set('address_display_field', $address_display_field);
         if (!isset($item[$address_display_field]) || strtolower($item[$address_display_field]) == 'full') {
             /*
             			if(strtolower($item['RESI_Address_on_Internet_Desc']) == 'full'){
             */
             $address_display = $item['Street_Number'] . ' ' . $item['Street_Name'] . ' ' . $item['Street_Suffix'];
             $this->pageTitle = $item['Street_Full_Address'];
         } else {
             /* 				$address_display = '<i>(Full Address Not Shown)</i>'; */
             $address_display = null;
             $this->pageTitle = $item['City'] . ', ' . $item['County'] . ' ' . $item['Zip_Code'];
         }
         $property_type = $item['Property_Type'];
         // find co-listing agent details
         $this->MemberAgent->recursive = -1;
         $co_agent_id = null;
         $co_agent = $this->MemberAgent->find('first', array('conditions' => array('MemberAgent.Agent_Email_Address' => $item['Co_Agent_Email_Address']), 'fields' => 'MemberAgent.Agent_MLS_ID'));
         /* 			debug($co_agent); */
         if (!empty($co_agent)) {
             $co_agent_id = $co_agent['MemberAgent']['Agent_MLS_ID'];
         }
         $this->MemberOffice->recursive = -1;
         $member_office = $this->MemberOffice->find('first', array('conditions' => array('MemberOffice.Office_MLS_ID' => $property['Property']['Office_ID'])));
         $this->set('member_office', $member_office);
         /* 			debug($member_office); */
         $this->set('co_agent_id', $co_agent_id);
         $grouping = array('Summary' => array('Status' => $item['Status'], 'MLS Number' => $item['ML_Number_Display'], 'Price' => '$' . $item['Search_Price_Display'], 'Property Type' => $item['Property_Subtype_1_Display'], 'Transaction Type' => $this->transaction_types[$item['Transaction_Type']], 'Number of Units' => @$item[$property_type . '___of_Units']), 'Property_Details' => array('Address' => $address_display, 'City' => $item['City'], 'Zip' => $item['Zip_Code'], 'County' => $item['County'], 'Bedrooms' => $item['Bedrooms'], 'Bathrooms' => $item['Bathrooms_Display'], 'Square Footage (approx.)' => $number->format($item['Square_Footage']), 'Building Sq. Ft. (approx.)' => $number->format($item['Lot_Size_Sq_Ft']), 'Lot Size - Acres (approx.)' => $item['Acres'], '2nd Unit on Lot' => @$item[$property_type . '_2nd_Unit_on_Lot_Desc'], 'HOA' => @$item[$property_type . '_HOA_Desc'], 'Senior Community' => @$item[$property_type . '_Senior_Desc'], 'Pool (Y/N)' => @$item[$property_type . '_Pool_Desc'], 'Year Built' => $item['Year_Built']), 'Contact_Information' => array('Listing Agent' => $item['Agent_Name'], 'Listing Agent Phone' => $item['Agent_Phone_1'], 'Listing Agent Email' => $item['Agent_Email_Address'], 'Agent Web Page Address' => $item['Agent_Web_Page_Address'], 'Listing Office' => $item['Office_Long_Name'], 'Listing Office Phone' => $item['Agent_Phone_1'], 'Co-Listing Agent' => $item['Co_Agent_Full_Name'], 'Co-Listing Agent Email' => $item['Co_Agent_Email_Address'], 'Co-Lisitng Agent Phone' => $item['Co_Office_Fax_Phone']));
         /*
         // GEOCODING STUFF
         
         $this->params['map'] = true;
         $address = $property['Property']['Street_Full_Address'];		
         $this->Coordinate->recursive = -1;
         $coordinate_finder =  array('conditions' => array('Coordinate.ML_Number_Display' => $property['Property']['ML_Number_Display']));
         $coordinates = $this->Coordinate->find('first', $coordinate_finder);
         if(empty($coordinates)){
         	$geo_data = $this->Geocoder->getLatLng($address, $this->google_map_API_key); 
         	$coordinate['Coordinate']['id'] = $coordinates['Coordinate']['id'];
         	$coordinate['Coordinate']['ML_Number_Display']  = $property['Property']['ML_Number_Display'];
         	$coordinate['Coordinate']['latitude'] = $geo_data['lat'];
         	$coordinate['Coordinate']['longitude'] = $geo_data['lng'];
         	$this->Coordinate->create();
         	$this->Coordinate->save($coordinate);
         	//$this->Session->setFlash('Coordinate data saved for property '.$property['Property']['ML_Number_Display']);
         	$coordinates = $this->Coordinate->find('first', $coordinate_finder);
         }
         
         	$coordinates['Coordinate']['address'] = $property['Property']['Street_Full_Address'];
         
         $this->params['coordinates'] = $coordinates; 
         // END GEOCODING STUFF
         */
         //	die(debug($grouping));
         $this->set('property', $property);
         $this->set('primary_image', $primary_image);
         $this->set('secondary_images', $secondary_images);
         $this->set('neighbors', $neighbors);
         $this->set('db_updated', $db_updated);
         // $this->set('allowed_fields', $allowed_fields);
         $this->set('grouping', $grouping);
         $this->set('city', $city);
         // $this->set('coordinates', $coordinates);
     }
 }