0 )
{
}
else
{
// Must be post object
$id = $id->ID;
}
$this->get_property( $id );
}
}
/**
* Gets a property from the database.
*
* @access public
* @param int $id (default: 0)
* @return bool
*/
public function get_property( $id = 0 ) {
if ( ! $id ) {
return false;
}
if ( $result = get_post( $id ) ) {
$this->populate( $result );
return true;
}
return false;
}
/**
* __isset function.
*
* @access public
* @param mixed $key
* @return bool
*/
public function __isset( $key ) {
if ( ! $this->id ) {
return false;
}
return metadata_exists( 'post', $this->id, $key );
}
/**
* __get function.
*
* @access public
* @param mixed $key
* @return mixed
*/
public function __get( $key ) {
if ( 'property_type' == $key )
{
return $this->get_property_type();
}
if ( 'availability' == $key )
{
return $this->get_availability();
}
if ( 'location' == $key )
{
return $this->get_location();
}
if ( 'price_qualifier' == $key )
{
return $this->get_price_qualifier();
}
if ( 'tenure' == $key )
{
return $this->get_tenure();
}
if ( 'sale_by' == $key )
{
return $this->get_sale_by();
}
if ( 'furnished' == $key )
{
return $this->get_furnished();
}
if ( 'parking' == $key )
{
return $this->get_parking();
}
if ( 'outside_space' == $key )
{
return $this->get_outside_space();
}
if ( 'marketing_flag' == $key )
{
return $this->get_marketing_flag();
}
if ( 'imported_id' == $key )
{
return $this->get_imported_id();
}
if ( 'office_name' == $key )
{
return $this->get_office_name();
}
if ( 'office_address' == $key )
{
return $this->get_office_address();
}
if ( 'office_telephone_number' == $key )
{
return $this->get_office_telephone_number();
}
if ( 'office_email_address' == $key )
{
return $this->get_office_email_address();
}
// Get values or default if not set
$value = get_post_meta( $this->id, $key, true );
if ($value == '')
{
$value = get_post_meta( $this->id, '_' . $key, true );
}
return $value;
}
/**
* Populates a property from the loaded post data.
*
* @access public
* @param mixed $result
* @return void
*/
public function populate( $result ) {
// Standard post data
$this->id = $result->ID;
$this->post_title = $result->post_title;
$this->post_status = $result->post_status;
$this->post_excerpt = $result->post_excerpt;
}
/**
* get_gallery_attachment_ids function.
*
* @access public
* @return array
*/
public function get_gallery_attachment_ids()
{
$photos = $this->photos;
if ( is_array($photos) )
{
$photos = array_filter( $photos );
}
else
{
$photos = array();
}
return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this );
}
/**
* Gets the first photo
*
* @access public
* @param string $size
* @return string
*/
public function get_main_photo_src( $size = 'thumbnail' ) {
$return = false;
if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
{
$photos = $this->_photo_urls;
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
{
$return = $photos[0]['url'];
}
}
else
{
$photos = $this->_photos;
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
{
$image_attributes = wp_get_attachment_image_src( $photos[0], $size );
if( $image_attributes )
{
$return = $image_attributes[0];
}
}
}
return $return;
}
/**
* get_floorplan_attachment_ids function.
*
* @access public
* @return array
*/
public function get_floorplan_attachment_ids()
{
$floorplans = $this->_floorplans;
if ( is_array($floorplans) )
{
$floorplans = array_filter( $floorplans );
}
else
{
$floorplans = array();
}
return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this );
}
/**
* get_brochure_attachment_ids function.
*
* @access public
* @return array
*/
public function get_brochure_attachment_ids()
{
$brochures = $this->_brochures;
if ( is_array($brochures) )
{
$brochures = array_filter( $brochures );
}
else
{
$brochures = array();
}
return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this );
}
/**
* get_epc_attachment_ids function.
*
* @access public
* @return array
*/
public function get_epc_attachment_ids()
{
$epcs = $this->_epcs;
if ( is_array($epcs) )
{
$epcs = array_filter( $epcs );
}
else
{
$epcs = array();
}
return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
}
/**
* get_virtual_tours function.
*
* @access public
* @return array
*/
public function get_virtual_tours()
{
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
$virtual_tours = array();
for ($i = 0; $i < $num_property_virtual_tours; ++$i)
{
$label = get_post_meta($this->id, '_virtual_tour_label_' . $i, TRUE);
$virtual_tours[] = array(
'url' => get_post_meta($this->id, '_virtual_tour_' . $i, TRUE),
'label' => ( $label != '' ? $label : __( 'Virtual Tour', 'propertyhive' ) ),
);
}
return apply_filters( 'propertyhive_property_virtual_tours', array_filter( $virtual_tours ), $this );
}
/**
* get_virtual_tour_urls function.
* deprecated
*
* @access public
* @return array
*/
public function get_virtual_tour_urls()
{
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
$virtual_tour_urls = array();
for ($i = 0; $i < $num_property_virtual_tours; ++$i)
{
$virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE);
}
return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this );
}
/**
* Get the formatted price based on department. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_price( ) {
$return = '';
$currency = array();
$prefix = '';
$suffix = '';
if ( $this->_department == 'commercial' )
{
if (
!is_admin() &&
$this->_for_sale == 'yes' && $this->_price_poa == 'yes' &&
$this->_to_rent == 'yes' && $this->_rent_poa == 'yes'
)
{
$return = __( 'POA', 'propertyhive' );
}
else
{
$price = '';
// Price Details
$price .= $this->get_formatted_commercial_price();
// Rent Details
$rent = $this->get_formatted_commercial_rent();
if ( $price != '' && $rent != '' )
{
$price .= '
';
}
$price .= $rent;
$return = $price;
}
}
else
{
if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
{
$return = __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( !is_admin() )
{
if ( isset($_GET['currency']) )
{
if ( $_GET['currency'] != '' )
{
$requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$_GET['currency']]) )
{
$currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
}
}
}
else
{
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
if ( $default_currency != '' )
{
$requested_currency = $ph_countries->get_currency( $default_currency );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$default_currency]) )
{
$currency['exchange_rate'] = $exchange_rates[$default_currency];
}
}
}
}
}
elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
{
$currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
}
else
{
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
if ( $default_currency != '' )
{
$requested_currency = $ph_countries->get_currency( $default_currency );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$default_currency]) )
{
$currency['exchange_rate'] = $exchange_rates[$default_currency];
}
}
}
}
}
if ( empty($currency) )
{
if ($this->_currency != '')
{
$currency = $ph_countries->get_currency( $this->_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
switch ($this->_department)
{
case "residential-sales":
{
$price = $this->_price;
if ( isset($currency['exchange_rate']) && $price != '' )
{
$price = $this->_price_actual * $currency['exchange_rate'];
}
$return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix : '-' );
break;
}
case "residential-lettings":
{
$price = $this->_rent;
if ( isset($currency['exchange_rate']) && $price != '' )
{
$price = $this->_price_actual * $currency['exchange_rate'];
switch ( $this->_rent_frequency )
{
case "pw": { $price = ($price * 12) / 52; break; }
case "pq": { $price = ($price * 12) / 4; break; }
case "pa": { $price = ($price * 12); break; }
}
}
$return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
break;
}
}
}
}
return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
}
/**
* Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_commercial_price( ) {
$price = '';
if ( $this->_for_sale == 'yes' )
{
if ( !is_admin() && $this->_price_poa == 'yes' )
{
$price .= __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( $this->_commercial_price_currency != '' )
{
$currency = $ph_countries->get_currency( $this->_commercial_price_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
if ( $this->_price_from != '' )
{
$explode_price = explode(".", $this->_price_from);
if ( count($explode_price) == 2 )
{
$price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
}
else
{
$price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
}
}
if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
{
if ( $price != '' )
{
$price .= ' - ';
}
$explode_price = explode(".", $this->_price_to);
if ( count($explode_price) == 2 )
{
$price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
}
else
{
$price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
}
}
if ( $price != '' )
{
$price_units = get_commercial_price_units( );
$price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
}
}
}
return $price;
}
/**
* Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_commercial_rent( ) {
$rent = '';
if ( $this->_to_rent == 'yes' )
{
if ( !is_admin() && $this->_rent_poa == 'yes' )
{
$rent .= __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( $this->_commercial_rent_currency != '' )
{
$currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
if ( $this->_rent_from != '' )
{
$explode_rent = explode(".", $this->_rent_from);
if ( count($explode_rent) == 2 )
{
$rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
}
else
{
$rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
}
}
if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
{
if ( $rent != '' )
{
$rent .= ' - ';
}
$explode_rent = explode(".", $this->_rent_to);
if ( count($explode_rent) == 2 )
{
$rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
}
else
{
$rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
}
}
if ( $rent != '' )
{
$price_units = get_commercial_price_units( );
$rent .= ' ' . ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units );
}
}
}
return $rent;
}
public function get_formatted_floor_area( ) {
$area = '';
if ( $this->_floor_area_from != '' )
{
$explode_area = explode(".", $this->_floor_area_from);
if ( count($explode_area) == 2 )
{
$area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format($this->_floor_area_from, 0);
}
}
if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
{
if ( $area != '' )
{
$area .= ' - ';
}
$explode_area = explode(".", $this->_floor_area_to);
if ( count($explode_area) == 2 )
{
$area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format($this->_floor_area_to, 0);
}
}
if ( $area != '' )
{
$area_units = get_area_units( );
$area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
}
return $area;
}
public function get_formatted_site_area( ) {
$area = '';
if ( $this->_site_area_from != '' )
{
$explode_area = explode(".", $this->_site_area_from);
if ( count($explode_area) == 2 )
{
$area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format($this->_site_area_from, 0);
}
}
if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
{
if ( $area != '' )
{
$area .= ' - ';
}
$explode_area = explode(".", $this->_site_area_to);
if ( count($explode_area) == 2 )
{
$area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format($this->_site_area_to, 0);
}
}
if ( $area != '' )
{
$area_units = get_area_units( );
$area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
}
return $area;
}
/**
* Get the formatted deposit
*
* @access public
* @return string
*/
public function get_formatted_deposit( )
{
if ( $this->_deposit == '' )
{
return '';
}
$ph_countries = new PH_Countries();
$currency = $ph_countries->get_currency( $this->_currency );
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
return $prefix . number_format($this->_deposit, 0) . $suffix;
}
/**
* Get the available date, or 'Now' if date is in past
*
* @access public
* @return string
*/
public function get_available_date( )
{
if (strtotime($this->_available_date))
{
return date( get_option( 'date_format' ), strtotime($this->_available_date) );
}
else
{
return __( 'Now', 'propertyhive' );
}
}
/**
* Get the full description by constructing the rooms or commercial description (dependant on department)
*
* @access public
* @return string
*/
public function get_formatted_description( ) {
if ( $this->_department == 'commercial' )
{
return $this->get_formatted_descriptions(); // Haven't called this commercial_descriptions as we might use generic descriptions for other area going forward
}
else
{
return $this->get_formatted_rooms();
}
}
/**
* Get the full description by constructing the rooms
*
* @access public
* @return string
*/
public function get_formatted_rooms( ) {
$rooms = $this->_rooms;
$return = '';
if (isset($rooms) && $rooms != '' && $rooms > 0)
{
for ($i = 0; $i < $rooms; ++$i)
{
$return .= '
';
if ($this->{'_room_name_' . $i} != '')
{
$return .= '' . $this->{'_room_name_' . $i} . '';
}
if ($this->{'_room_dimensions_' . $i} != '')
{
$return .= ' (' . $this->{'_room_dimensions_' . $i} . ')';
}
if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
{
$return .= '
';
}
$return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '
';
if ($this->{'_description_name_' . $i} != '')
{
$return .= '' . $this->{'_description_name_' . $i} . '
';
}
$return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '