| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
/** |
| 6 |
* Property |
| 7 |
* |
| 8 |
* The PropertyHive property class handles property data. |
| 9 |
* |
| 10 |
* @class PH_Property |
| 11 |
* @version 1.0.0 |
| 12 |
* @package PropertyHive/Classes |
| 13 |
* @category Class |
| 14 |
* @author PropertyHive |
| 15 |
*/ |
| 16 |
class PH_Property { |
| 17 |
|
| 18 |
/** @public int Property (post) ID */ |
| 19 |
public $id; |
| 20 |
|
| 21 |
/** @public string Property (post) Title */ |
| 22 |
public $post_title; |
| 23 |
|
| 24 |
/** @public string Property (post) Status */ |
| 25 |
public $post_status; |
| 26 |
|
| 27 |
/** @public string Property (post) Excerpt */ |
| 28 |
public $post_excerpt; |
| 29 |
|
| 30 |
/** |
| 31 |
* Get the property if ID is passed, otherwise the property is new and empty. |
| 32 |
* |
| 33 |
* @access public |
| 34 |
* @param string|object $id (default: '') |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function __construct( $id = '' ) { |
| 38 |
if ( $id != '' ) |
| 39 |
{ |
| 40 |
if ( is_int($id) && $id > 0 ) |
| 41 |
{ |
| 42 |
|
| 43 |
} |
| 44 |
else |
| 45 |
{ |
| 46 |
// Must be post object |
| 47 |
$id = $id->ID; |
| 48 |
} |
| 49 |
$this->get_property( $id ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Gets a property from the database. |
| 55 |
* |
| 56 |
* @access public |
| 57 |
* @param int $id (default: 0) |
| 58 |
* @return bool |
| 59 |
*/ |
| 60 |
public function get_property( $id = 0 ) { |
| 61 |
if ( ! $id ) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
if ( $result = get_post( $id ) ) { |
| 65 |
$this->populate( $result ); |
| 66 |
return true; |
| 67 |
} |
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* __isset function. |
| 73 |
* |
| 74 |
* @access public |
| 75 |
* @param mixed $key |
| 76 |
* @return bool |
| 77 |
*/ |
| 78 |
public function __isset( $key ) { |
| 79 |
if ( ! $this->id ) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
return metadata_exists( 'post', $this->id, $key ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* __get function. |
| 87 |
* |
| 88 |
* @access public |
| 89 |
* @param mixed $key |
| 90 |
* @return mixed |
| 91 |
*/ |
| 92 |
public function __get( $key ) { |
| 93 |
|
| 94 |
$value = ''; |
| 95 |
|
| 96 |
if ( method_exists($this, 'get_' . $key) && 'available_date' != $key ) |
| 97 |
{ |
| 98 |
$value = $this->{'get_' . $key}(); |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
$value = get_post_meta( $this->id, $key, true ); |
| 103 |
if ($value == '') |
| 104 |
{ |
| 105 |
$value = get_post_meta( $this->id, '_' . $key, true ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
$value = apply_filters( 'propertyhive_get_detail', $value, $key, $this ); |
| 110 |
|
| 111 |
return $value; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Populates a property from the loaded post data. |
| 116 |
* |
| 117 |
* @access public |
| 118 |
* @param mixed $result |
| 119 |
* @return void |
| 120 |
*/ |
| 121 |
public function populate( $result ) { |
| 122 |
// Standard post data |
| 123 |
$this->id = $result->ID; |
| 124 |
$this->post_title = $result->post_title; |
| 125 |
$this->post_status = $result->post_status; |
| 126 |
$this->post_excerpt = apply_filters( 'propertyhive_property_post_excerpt', $result->post_excerpt ); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* get_gallery_attachment_ids function. |
| 131 |
* |
| 132 |
* @access public |
| 133 |
* @return array |
| 134 |
*/ |
| 135 |
public function get_gallery_attachment_ids() |
| 136 |
{ |
| 137 |
$photos = $this->photos; |
| 138 |
if ( is_array($photos) ) |
| 139 |
{ |
| 140 |
$photos = array_filter( $photos ); |
| 141 |
} |
| 142 |
else |
| 143 |
{ |
| 144 |
$photos = array(); |
| 145 |
} |
| 146 |
return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this ); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Gets the first photo |
| 151 |
* |
| 152 |
* @access public |
| 153 |
* @param string $size |
| 154 |
* @return string |
| 155 |
*/ |
| 156 |
public function get_main_photo_src( $size = 'thumbnail' ) { |
| 157 |
|
| 158 |
$return = false; |
| 159 |
|
| 160 |
if ( get_option('propertyhive_images_stored_as', '') == 'urls' ) |
| 161 |
{ |
| 162 |
$photos = $this->_photo_urls; |
| 163 |
|
| 164 |
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url'])) |
| 165 |
{ |
| 166 |
$return = $photos[0]['url']; |
| 167 |
} |
| 168 |
} |
| 169 |
else |
| 170 |
{ |
| 171 |
$photos = $this->_photos; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0])) |
| 176 |
{ |
| 177 |
$image_attributes = wp_get_attachment_image_src( $photos[0], $size ); |
| 178 |
if( $image_attributes ) |
| 179 |
{ |
| 180 |
$return = $image_attributes[0]; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
return $return; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* get_floorplan_attachment_ids function. |
| 191 |
* |
| 192 |
* @access public |
| 193 |
* @return array |
| 194 |
*/ |
| 195 |
public function get_floorplan_attachment_ids() |
| 196 |
{ |
| 197 |
$floorplans = $this->_floorplans; |
| 198 |
if ( is_array($floorplans) ) |
| 199 |
{ |
| 200 |
$floorplans = array_filter( $floorplans ); |
| 201 |
} |
| 202 |
else |
| 203 |
{ |
| 204 |
$floorplans = array(); |
| 205 |
} |
| 206 |
return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this ); |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* get_brochure_attachment_ids function. |
| 211 |
* |
| 212 |
* @access public |
| 213 |
* @return array |
| 214 |
*/ |
| 215 |
public function get_brochure_attachment_ids() |
| 216 |
{ |
| 217 |
$brochures = $this->_brochures; |
| 218 |
if ( is_array($brochures) ) |
| 219 |
{ |
| 220 |
$brochures = array_filter( $brochures ); |
| 221 |
} |
| 222 |
else |
| 223 |
{ |
| 224 |
$brochures = array(); |
| 225 |
} |
| 226 |
return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this ); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* get_epc_attachment_ids function. |
| 231 |
* |
| 232 |
* @access public |
| 233 |
* @return array |
| 234 |
*/ |
| 235 |
public function get_epc_attachment_ids() |
| 236 |
{ |
| 237 |
$epcs = $this->_epcs; |
| 238 |
if ( is_array($epcs) ) |
| 239 |
{ |
| 240 |
$epcs = array_filter( $epcs ); |
| 241 |
} |
| 242 |
else |
| 243 |
{ |
| 244 |
$epcs = array(); |
| 245 |
} |
| 246 |
return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this ); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* get_virtual_tours function. |
| 251 |
* |
| 252 |
* @access public |
| 253 |
* @return array |
| 254 |
*/ |
| 255 |
public function get_virtual_tours() |
| 256 |
{ |
| 257 |
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE); |
| 258 |
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; } |
| 259 |
|
| 260 |
$virtual_tours = array(); |
| 261 |
for ($i = 0; $i < $num_property_virtual_tours; ++$i) |
| 262 |
{ |
| 263 |
$label = get_post_meta($this->id, '_virtual_tour_label_' . $i, TRUE); |
| 264 |
$virtual_tours[] = array( |
| 265 |
'url' => get_post_meta($this->id, '_virtual_tour_' . $i, TRUE), |
| 266 |
'label' => ( $label != '' ? $label : __( 'Virtual Tour', 'propertyhive' ) ), |
| 267 |
); |
| 268 |
} |
| 269 |
|
| 270 |
return apply_filters( 'propertyhive_property_virtual_tours', array_filter( $virtual_tours ), $this ); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* get_virtual_tour_urls function. |
| 275 |
* deprecated |
| 276 |
* |
| 277 |
* @access public |
| 278 |
* @return array |
| 279 |
*/ |
| 280 |
public function get_virtual_tour_urls() |
| 281 |
{ |
| 282 |
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE); |
| 283 |
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; } |
| 284 |
|
| 285 |
$virtual_tour_urls = array(); |
| 286 |
for ($i = 0; $i < $num_property_virtual_tours; ++$i) |
| 287 |
{ |
| 288 |
$virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE); |
| 289 |
} |
| 290 |
|
| 291 |
return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this ); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Get the formatted price based on department. Show POA if on frontend and 'POA' ticked |
| 296 |
* |
| 297 |
* @access public |
| 298 |
* @return string |
| 299 |
*/ |
| 300 |
public function get_formatted_price( $plain_text = false ) { |
| 301 |
|
| 302 |
$return = ''; |
| 303 |
|
| 304 |
$currency = array(); |
| 305 |
$prefix = ''; |
| 306 |
$suffix = ''; |
| 307 |
|
| 308 |
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true; |
| 309 |
|
| 310 |
if ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' ) |
| 311 |
{ |
| 312 |
if ( |
| 313 |
!$is_admin && |
| 314 |
$this->_for_sale == 'yes' && $this->_price_poa == 'yes' && |
| 315 |
$this->_to_rent == 'yes' && $this->_rent_poa == 'yes' |
| 316 |
) |
| 317 |
{ |
| 318 |
$return = __( 'POA', 'propertyhive' ); |
| 319 |
} |
| 320 |
else |
| 321 |
{ |
| 322 |
// Price Details |
| 323 |
$price = $this->get_formatted_commercial_price(); |
| 324 |
|
| 325 |
if ( $price != '' && !$plain_text ) |
| 326 |
{ |
| 327 |
$price = '<span class="commercial-price">' . $price . '</span>'; |
| 328 |
} |
| 329 |
|
| 330 |
// Rent Details |
| 331 |
$rent = $this->get_formatted_commercial_rent(); |
| 332 |
|
| 333 |
if ( $rent != '' && !$plain_text ) { $rent = '<span class="commercial-rent">' . $rent . '</span>'; } |
| 334 |
|
| 335 |
if ( $price != '' && $rent != '' ) |
| 336 |
{ |
| 337 |
$price .= !$plain_text ? '<br>' : "\n"; |
| 338 |
} |
| 339 |
$price .= $rent; |
| 340 |
|
| 341 |
$return = $price; |
| 342 |
} |
| 343 |
} |
| 344 |
else |
| 345 |
{ |
| 346 |
if ( !$is_admin && $this->_poa == 'yes') |
| 347 |
{ |
| 348 |
$return = __( 'POA', 'propertyhive' ); |
| 349 |
} |
| 350 |
else |
| 351 |
{ |
| 352 |
$ph_countries = new PH_Countries(); |
| 353 |
|
| 354 |
if ( !$is_admin ) |
| 355 |
{ |
| 356 |
if ( isset($_GET['currency']) ) |
| 357 |
{ |
| 358 |
if ( $_GET['currency'] != '' ) |
| 359 |
{ |
| 360 |
$requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) ); |
| 361 |
if ( $requested_currency !== FALSE ) |
| 362 |
{ |
| 363 |
$currency = $requested_currency; |
| 364 |
$currency['exchange_rate'] = 1; |
| 365 |
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() ); |
| 366 |
if ( isset($exchange_rates[$_GET['currency']]) ) |
| 367 |
{ |
| 368 |
$currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])]; |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
else |
| 373 |
{ |
| 374 |
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' ); |
| 375 |
if ( $default_currency != '' ) |
| 376 |
{ |
| 377 |
$requested_currency = $ph_countries->get_currency( $default_currency ); |
| 378 |
if ( $requested_currency !== FALSE ) |
| 379 |
{ |
| 380 |
$currency = $requested_currency; |
| 381 |
$currency['exchange_rate'] = 1; |
| 382 |
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() ); |
| 383 |
if ( isset($exchange_rates[$default_currency]) ) |
| 384 |
{ |
| 385 |
$currency['exchange_rate'] = $exchange_rates[$default_currency]; |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' ) |
| 392 |
{ |
| 393 |
$currency = @json_decode(html_entity_decode($_COOKIE['propertyhive_currency']), true); |
| 394 |
} |
| 395 |
else |
| 396 |
{ |
| 397 |
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' ); |
| 398 |
if ( $default_currency != '' ) |
| 399 |
{ |
| 400 |
$requested_currency = $ph_countries->get_currency( $default_currency ); |
| 401 |
if ( $requested_currency !== FALSE ) |
| 402 |
{ |
| 403 |
$currency = $requested_currency; |
| 404 |
$currency['exchange_rate'] = 1; |
| 405 |
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() ); |
| 406 |
if ( isset($exchange_rates[$default_currency]) ) |
| 407 |
{ |
| 408 |
$currency['exchange_rate'] = $exchange_rates[$default_currency]; |
| 409 |
} |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
if ( empty($currency) ) |
| 416 |
{ |
| 417 |
if ($this->_currency != '') |
| 418 |
{ |
| 419 |
$currency = $ph_countries->get_currency( $this->_currency ); |
| 420 |
} |
| 421 |
else |
| 422 |
{ |
| 423 |
$currency = $ph_countries->get_currency( 'GBP' ); |
| 424 |
} |
| 425 |
} |
| 426 |
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 427 |
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 428 |
|
| 429 |
$department = $this->_department; |
| 430 |
if ( ph_get_custom_department_based_on( $department ) !== false ) |
| 431 |
{ |
| 432 |
$department = ph_get_custom_department_based_on( $department ); |
| 433 |
} |
| 434 |
switch ($department) |
| 435 |
{ |
| 436 |
case "residential-sales": |
| 437 |
{ |
| 438 |
$price = $this->_price; |
| 439 |
|
| 440 |
if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' ) |
| 441 |
{ |
| 442 |
// Round this after calculation |
| 443 |
$price = round($this->_price_actual * $currency['exchange_rate'], 0); |
| 444 |
} |
| 445 |
|
| 446 |
$return = ( ( $price != '' ) ? $prefix . ph_display_price_field($price, !$is_admin) . $suffix : '-' ); |
| 447 |
break; |
| 448 |
} |
| 449 |
case "residential-lettings": |
| 450 |
{ |
| 451 |
$price = $this->_rent; |
| 452 |
if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' ) |
| 453 |
{ |
| 454 |
// Round this after calculation as we only want to check the first two decimal places |
| 455 |
$price = round($this->_price_actual * $currency['exchange_rate'], 2); |
| 456 |
switch ( $this->_rent_frequency ) |
| 457 |
{ |
| 458 |
case "pd": { $price = ($price * 365) / 52; break; } |
| 459 |
case "pw": { $price = ($price * 12) / 52; break; } |
| 460 |
case "pq": { $price = ($price * 12) / 4; break; } |
| 461 |
case "pa": { $price = ($price * 12); break; } |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
$return = ( ( $price != '' ) ? $prefix . ph_display_price_field($price, !$is_admin) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' ); |
| 466 |
break; |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix ); |
| 473 |
} |
| 474 |
|
| 475 |
/** |
| 476 |
* Get the formatted commercial price. Show POA if on frontend and 'POA' ticked |
| 477 |
* |
| 478 |
* @access public |
| 479 |
* @return string |
| 480 |
*/ |
| 481 |
public function get_formatted_commercial_price( ) { |
| 482 |
|
| 483 |
$price = ''; |
| 484 |
|
| 485 |
if ( $this->_for_sale == 'yes' ) |
| 486 |
{ |
| 487 |
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true; |
| 488 |
|
| 489 |
if ( !$is_admin && $this->_price_poa == 'yes' ) |
| 490 |
{ |
| 491 |
$price .= __( 'POA', 'propertyhive' ); |
| 492 |
} |
| 493 |
else |
| 494 |
{ |
| 495 |
$ph_countries = new PH_Countries(); |
| 496 |
if ( $this->_commercial_price_currency != '' ) |
| 497 |
{ |
| 498 |
$currency = $ph_countries->get_currency( $this->_commercial_price_currency ); |
| 499 |
} |
| 500 |
else |
| 501 |
{ |
| 502 |
$currency = $ph_countries->get_currency( 'GBP' ); |
| 503 |
} |
| 504 |
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 505 |
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 506 |
|
| 507 |
if ( $this->_price_from != '' ) |
| 508 |
{ |
| 509 |
$price .= $prefix . ph_display_price_field($this->_price_from, !$is_admin) . $suffix; |
| 510 |
} |
| 511 |
if ( $this->_price_to != '' && $this->_price_to != $this->_price_from ) |
| 512 |
{ |
| 513 |
if ( $price != '' ) |
| 514 |
{ |
| 515 |
$price .= ' - '; |
| 516 |
} |
| 517 |
$price .= $prefix . ph_display_price_field($this->_price_to, !$is_admin) . $suffix; |
| 518 |
} |
| 519 |
if ( $price != '' ) |
| 520 |
{ |
| 521 |
$price_units = get_commercial_price_units( ); |
| 522 |
$price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : ''; |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
return apply_filters( 'propertyhive_commercial_price_output', $price, $this ); |
| 528 |
} |
| 529 |
|
| 530 |
/** |
| 531 |
* Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked |
| 532 |
* |
| 533 |
* @access public |
| 534 |
* @return string |
| 535 |
*/ |
| 536 |
public function get_formatted_commercial_rent( ) { |
| 537 |
|
| 538 |
$rent = ''; |
| 539 |
|
| 540 |
if ( $this->_to_rent == 'yes' ) |
| 541 |
{ |
| 542 |
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true; |
| 543 |
|
| 544 |
if ( !$is_admin && $this->_rent_poa == 'yes' ) |
| 545 |
{ |
| 546 |
$rent .= __( 'POA', 'propertyhive' ); |
| 547 |
} |
| 548 |
else |
| 549 |
{ |
| 550 |
$ph_countries = new PH_Countries(); |
| 551 |
if ( $this->_commercial_rent_currency != '' ) |
| 552 |
{ |
| 553 |
$currency = $ph_countries->get_currency( $this->_commercial_rent_currency ); |
| 554 |
} |
| 555 |
else |
| 556 |
{ |
| 557 |
$currency = $ph_countries->get_currency( 'GBP' ); |
| 558 |
} |
| 559 |
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 560 |
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 561 |
|
| 562 |
if ( $this->_rent_from != '' ) |
| 563 |
{ |
| 564 |
$rent .= $prefix . ph_display_price_field($this->_rent_from, !$is_admin) . $suffix; |
| 565 |
} |
| 566 |
if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from ) |
| 567 |
{ |
| 568 |
if ( $rent != '' ) |
| 569 |
{ |
| 570 |
$rent .= ' - '; |
| 571 |
} |
| 572 |
$rent .= $prefix . ph_display_price_field($this->_rent_to, !$is_admin) . $suffix; |
| 573 |
} |
| 574 |
if ( $rent != '' ) |
| 575 |
{ |
| 576 |
$price_units = get_commercial_price_units( ); |
| 577 |
$rent .= ' ' . __( ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units ), 'propertyhive' ); |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
return apply_filters( 'propertyhive_commercial_rent_output', $rent, $this ); |
| 583 |
} |
| 584 |
|
| 585 |
public function get_formatted_floor_area( ) { |
| 586 |
|
| 587 |
$area = ''; |
| 588 |
|
| 589 |
if ( $this->_floor_area_from != '' ) |
| 590 |
{ |
| 591 |
$explode_area = explode(".", $this->_floor_area_from); |
| 592 |
if ( count($explode_area) == 2 ) |
| 593 |
{ |
| 594 |
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1]; |
| 595 |
} |
| 596 |
else |
| 597 |
{ |
| 598 |
$area .= number_format((float)$this->_floor_area_from, 0); |
| 599 |
} |
| 600 |
} |
| 601 |
if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from ) |
| 602 |
{ |
| 603 |
if ( $area != '' ) |
| 604 |
{ |
| 605 |
$area .= ' - '; |
| 606 |
} |
| 607 |
$explode_area = explode(".", $this->_floor_area_to); |
| 608 |
if ( count($explode_area) == 2 ) |
| 609 |
{ |
| 610 |
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1]; |
| 611 |
} |
| 612 |
else |
| 613 |
{ |
| 614 |
$area .= number_format((float)$this->_floor_area_to, 0); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
if ( $area != '' ) |
| 619 |
{ |
| 620 |
$area_units = get_area_units( ); |
| 621 |
$area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : ''; |
| 622 |
} |
| 623 |
|
| 624 |
return apply_filters( 'propertyhive_floor_area_output', $area, $this ); |
| 625 |
|
| 626 |
} |
| 627 |
|
| 628 |
public function get_formatted_site_area( ) { |
| 629 |
|
| 630 |
$area = ''; |
| 631 |
|
| 632 |
if ( $this->_site_area_from != '' ) |
| 633 |
{ |
| 634 |
$explode_area = explode(".", $this->_site_area_from); |
| 635 |
if ( count($explode_area) == 2 ) |
| 636 |
{ |
| 637 |
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1]; |
| 638 |
} |
| 639 |
else |
| 640 |
{ |
| 641 |
$area .= number_format((float)$this->_site_area_from, 0); |
| 642 |
} |
| 643 |
} |
| 644 |
if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from ) |
| 645 |
{ |
| 646 |
if ( $area != '' ) |
| 647 |
{ |
| 648 |
$area .= ' - '; |
| 649 |
} |
| 650 |
$explode_area = explode(".", $this->_site_area_to); |
| 651 |
if ( count($explode_area) == 2 ) |
| 652 |
{ |
| 653 |
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1]; |
| 654 |
} |
| 655 |
else |
| 656 |
{ |
| 657 |
$area .= number_format((float)$this->_site_area_to, 0); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
if ( $area != '' ) |
| 662 |
{ |
| 663 |
$area_units = get_area_units( ); |
| 664 |
$area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : ''; |
| 665 |
} |
| 666 |
|
| 667 |
return apply_filters( 'propertyhive_site_area_output', $area, $this ); |
| 668 |
|
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* Get the formatted deposit |
| 673 |
* |
| 674 |
* @access public |
| 675 |
* @return string |
| 676 |
*/ |
| 677 |
public function get_formatted_deposit( ) |
| 678 |
{ |
| 679 |
if ( $this->_deposit == '' ) |
| 680 |
{ |
| 681 |
return ''; |
| 682 |
} |
| 683 |
|
| 684 |
$ph_countries = new PH_Countries(); |
| 685 |
|
| 686 |
$currency = $ph_countries->get_currency( $this->_currency ); |
| 687 |
|
| 688 |
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true; |
| 689 |
|
| 690 |
if ( $currency === false ) |
| 691 |
{ |
| 692 |
return ph_display_price_field($this->_deposit, !$is_admin); |
| 693 |
} |
| 694 |
|
| 695 |
$prefix = ( !isset($currency['currency_prefix']) || ( isset($currency['currency_prefix']) && $currency['currency_prefix'] ) ) ? $currency['currency_symbol'] : ''; |
| 696 |
$suffix = ( isset($currency['currency_prefix']) && !$currency['currency_prefix'] ) ? $currency['currency_symbol'] : ''; |
| 697 |
|
| 698 |
return $prefix . ph_display_price_field($this->_deposit, !$is_admin) . $suffix; |
| 699 |
} |
| 700 |
|
| 701 |
/** |
| 702 |
* Get the available date, or 'Now' if date is in past |
| 703 |
* |
| 704 |
* @access public |
| 705 |
* @return string |
| 706 |
*/ |
| 707 |
public function get_available_date( ) |
| 708 |
{ |
| 709 |
if ( $this->_available_date == '' ) |
| 710 |
{ |
| 711 |
return ''; |
| 712 |
} |
| 713 |
|
| 714 |
if (strtotime($this->_available_date) > time()) |
| 715 |
{ |
| 716 |
return date( get_option( 'date_format' ), strtotime($this->_available_date) ); |
| 717 |
} |
| 718 |
else |
| 719 |
{ |
| 720 |
return __( 'Now', 'propertyhive' ); |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
/** |
| 725 |
* Get the full description by constructing the rooms or commercial description (dependant on department) |
| 726 |
* |
| 727 |
* @access public |
| 728 |
* @return string |
| 729 |
*/ |
| 730 |
public function get_formatted_description( $plain_text = false ) { |
| 731 |
|
| 732 |
$department = $this->_department; |
| 733 |
if ( ph_get_custom_department_based_on( $department ) !== false ) |
| 734 |
{ |
| 735 |
$department = ph_get_custom_department_based_on( $department ); |
| 736 |
} |
| 737 |
if ( $department == 'commercial' ) |
| 738 |
{ |
| 739 |
$description = $this->get_formatted_descriptions( $plain_text ); // Haven't called this commercial_descriptions as we might use generic descriptions for other areas going forward |
| 740 |
} |
| 741 |
else |
| 742 |
{ |
| 743 |
$description = $this->get_formatted_rooms( $plain_text ); |
| 744 |
} |
| 745 |
|
| 746 |
return apply_filters( 'propertyhive_description_output', $description ); |
| 747 |
} |
| 748 |
|
| 749 |
/** |
| 750 |
* Get the full description by constructing the rooms |
| 751 |
* |
| 752 |
* @access public |
| 753 |
* @return string |
| 754 |
*/ |
| 755 |
public function get_formatted_rooms( $plain_text = false ) { |
| 756 |
|
| 757 |
$rooms = $this->_rooms; |
| 758 |
|
| 759 |
$return = ''; |
| 760 |
|
| 761 |
if (isset($rooms) && $rooms != '' && $rooms > 0) |
| 762 |
{ |
| 763 |
for ($i = 0; $i < $rooms; ++$i) |
| 764 |
{ |
| 765 |
if ( !$plain_text ) |
| 766 |
{ |
| 767 |
$return .= '<p class="room">'; |
| 768 |
if ($this->{'_room_name_' . $i} != '') |
| 769 |
{ |
| 770 |
$return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>'; |
| 771 |
} |
| 772 |
if ($this->{'_room_dimensions_' . $i} != '') |
| 773 |
{ |
| 774 |
$return .= ' <span class="dimension">' . $this->{'_room_dimensions_' . $i} . '</span>'; |
| 775 |
} |
| 776 |
if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '') |
| 777 |
{ |
| 778 |
$return .= '<br>'; |
| 779 |
} |
| 780 |
$return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>'; |
| 781 |
} |
| 782 |
else |
| 783 |
{ |
| 784 |
if ($this->{'_room_name_' . $i} != '') |
| 785 |
{ |
| 786 |
$return .= $this->{'_room_name_' . $i}; |
| 787 |
} |
| 788 |
if ($this->{'_room_dimensions_' . $i} != '') |
| 789 |
{ |
| 790 |
$return .= ' ' . $this->{'_room_dimensions_' . $i}; |
| 791 |
} |
| 792 |
if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '') |
| 793 |
{ |
| 794 |
$return .= "\n"; |
| 795 |
} |
| 796 |
$return .= strip_tags($this->{'_room_description_' . $i}) . "\n\n"; |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
return $return; |
| 802 |
} |
| 803 |
|
| 804 |
/** |
| 805 |
* Get the full description by constructing the descriptions |
| 806 |
* |
| 807 |
* @access public |
| 808 |
* @return string |
| 809 |
*/ |
| 810 |
public function get_formatted_descriptions( $plain_text = false ) { |
| 811 |
|
| 812 |
$descriptions = $this->_descriptions; |
| 813 |
|
| 814 |
$return = ''; |
| 815 |
|
| 816 |
if (isset($descriptions) && $descriptions != '' && $descriptions > 0) |
| 817 |
{ |
| 818 |
for ($i = 0; $i < $descriptions; ++$i) |
| 819 |
{ |
| 820 |
if ( !$plain_text ) |
| 821 |
{ |
| 822 |
$return .= '<p class="description-section'; |
| 823 |
if ($this->{'_description_name_' . $i} != '') |
| 824 |
{ |
| 825 |
$return .= ' description-section-' . esc_attr(sanitize_title($this->{'_description_name_' . $i})); |
| 826 |
} |
| 827 |
$return .= '">'; |
| 828 |
if ($this->{'_description_name_' . $i} != '') |
| 829 |
{ |
| 830 |
$return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>'; |
| 831 |
} |
| 832 |
$return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>'; |
| 833 |
} |
| 834 |
else |
| 835 |
{ |
| 836 |
if ($this->{'_description_name_' . $i} != '') |
| 837 |
{ |
| 838 |
$return .= $this->{'_description_name_' . $i} . "\n"; |
| 839 |
} |
| 840 |
$return .= strip_tags($this->{'_description_' . $i}) . "\n\n"; |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
return $return; |
| 846 |
} |
| 847 |
|
| 848 |
/** |
| 849 |
* Get the property type taxononmy |
| 850 |
* |
| 851 |
* @access public |
| 852 |
* @return string |
| 853 |
*/ |
| 854 |
public function get_property_type() |
| 855 |
{ |
| 856 |
$term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names")); |
| 857 |
|
| 858 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 859 |
{ |
| 860 |
return implode(", ", $term_list); |
| 861 |
} |
| 862 |
|
| 863 |
return ''; |
| 864 |
} |
| 865 |
|
| 866 |
/** |
| 867 |
* Get the availability taxononmy |
| 868 |
* |
| 869 |
* @access public |
| 870 |
* @return string |
| 871 |
*/ |
| 872 |
public function get_availability() |
| 873 |
{ |
| 874 |
$term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names")); |
| 875 |
|
| 876 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 877 |
{ |
| 878 |
return implode(", ", $term_list); |
| 879 |
} |
| 880 |
|
| 881 |
return ''; |
| 882 |
} |
| 883 |
|
| 884 |
/** |
| 885 |
* Get the location taxononmy |
| 886 |
* |
| 887 |
* @access public |
| 888 |
* @return string |
| 889 |
*/ |
| 890 |
public function get_location() |
| 891 |
{ |
| 892 |
$term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names")); |
| 893 |
|
| 894 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 895 |
{ |
| 896 |
return implode(", ", $term_list); |
| 897 |
} |
| 898 |
|
| 899 |
return ''; |
| 900 |
} |
| 901 |
|
| 902 |
/** |
| 903 |
* Get the price qualifier taxononmy |
| 904 |
* |
| 905 |
* @access public |
| 906 |
* @return string |
| 907 |
*/ |
| 908 |
public function get_price_qualifier() |
| 909 |
{ |
| 910 |
$term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names")); |
| 911 |
|
| 912 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 913 |
{ |
| 914 |
return implode(", ", $term_list); |
| 915 |
} |
| 916 |
|
| 917 |
return ''; |
| 918 |
} |
| 919 |
|
| 920 |
/** |
| 921 |
* Get the tenure taxononmy |
| 922 |
* |
| 923 |
* @access public |
| 924 |
* @return string |
| 925 |
*/ |
| 926 |
public function get_tenure() |
| 927 |
{ |
| 928 |
$term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' ) ? 'commercial_' : '' ) . 'tenure', array("fields" => "names")); |
| 929 |
|
| 930 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 931 |
{ |
| 932 |
return implode(", ", $term_list); |
| 933 |
} |
| 934 |
|
| 935 |
return ''; |
| 936 |
} |
| 937 |
|
| 938 |
/** |
| 939 |
* Get the sale by taxononmy |
| 940 |
* |
| 941 |
* @access public |
| 942 |
* @return string |
| 943 |
*/ |
| 944 |
public function get_sale_by() |
| 945 |
{ |
| 946 |
$term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names")); |
| 947 |
|
| 948 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 949 |
{ |
| 950 |
return implode(", ", $term_list); |
| 951 |
} |
| 952 |
|
| 953 |
return ''; |
| 954 |
} |
| 955 |
|
| 956 |
/** |
| 957 |
* Get the furnished taxononmy |
| 958 |
* |
| 959 |
* @access public |
| 960 |
* @return string |
| 961 |
*/ |
| 962 |
public function get_furnished() |
| 963 |
{ |
| 964 |
$term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names")); |
| 965 |
|
| 966 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 967 |
{ |
| 968 |
return implode(", ", $term_list); |
| 969 |
} |
| 970 |
|
| 971 |
return ''; |
| 972 |
} |
| 973 |
|
| 974 |
/** |
| 975 |
* Get the parking taxononmy |
| 976 |
* |
| 977 |
* @access public |
| 978 |
* @return string |
| 979 |
*/ |
| 980 |
public function get_parking() |
| 981 |
{ |
| 982 |
$term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names")); |
| 983 |
|
| 984 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 985 |
{ |
| 986 |
return implode(", ", $term_list); |
| 987 |
} |
| 988 |
|
| 989 |
return ''; |
| 990 |
} |
| 991 |
|
| 992 |
/** |
| 993 |
* Get the outside space taxononmy |
| 994 |
* |
| 995 |
* @access public |
| 996 |
* @return string |
| 997 |
*/ |
| 998 |
public function get_outside_space() |
| 999 |
{ |
| 1000 |
$term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names")); |
| 1001 |
|
| 1002 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 1003 |
{ |
| 1004 |
return implode(", ", $term_list); |
| 1005 |
} |
| 1006 |
|
| 1007 |
return ''; |
| 1008 |
} |
| 1009 |
|
| 1010 |
/** |
| 1011 |
* Get the marketing flag taxononmy |
| 1012 |
* |
| 1013 |
* @access public |
| 1014 |
* @return string |
| 1015 |
*/ |
| 1016 |
public function get_marketing_flag() |
| 1017 |
{ |
| 1018 |
$term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names")); |
| 1019 |
|
| 1020 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 1021 |
{ |
| 1022 |
return implode(", ", $term_list); |
| 1023 |
} |
| 1024 |
|
| 1025 |
return ''; |
| 1026 |
} |
| 1027 |
|
| 1028 |
/** |
| 1029 |
* Get the ID of property from third party system |
| 1030 |
* |
| 1031 |
* @access public |
| 1032 |
* @return string |
| 1033 |
*/ |
| 1034 |
public function get_imported_id() |
| 1035 |
{ |
| 1036 |
global $wpdb; |
| 1037 |
|
| 1038 |
$row = $wpdb->get_row( |
| 1039 |
$wpdb->prepare( |
| 1040 |
" |
| 1041 |
SELECT meta_value |
| 1042 |
FROM {$wpdb->prefix}postmeta |
| 1043 |
WHERE |
| 1044 |
meta_key LIKE %s |
| 1045 |
AND post_id = %d |
| 1046 |
LIMIT 1 |
| 1047 |
", |
| 1048 |
'_imported_ref_%', |
| 1049 |
$this->id |
| 1050 |
), |
| 1051 |
ARRAY_A |
| 1052 |
); |
| 1053 |
|
| 1054 |
if ( null !== $row ) |
| 1055 |
{ |
| 1056 |
return $row['meta_value']; |
| 1057 |
} |
| 1058 |
|
| 1059 |
return ''; |
| 1060 |
} |
| 1061 |
|
| 1062 |
/** |
| 1063 |
* Get an array of property features |
| 1064 |
* |
| 1065 |
* @access public |
| 1066 |
* @return array |
| 1067 |
*/ |
| 1068 |
public function get_features( ) |
| 1069 |
{ |
| 1070 |
$features = array(); |
| 1071 |
|
| 1072 |
if ( get_option('propertyhive_features_type') == 'checkbox' ) |
| 1073 |
{ |
| 1074 |
$term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names")); |
| 1075 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 1076 |
{ |
| 1077 |
foreach ( $term_list as $term_name ) |
| 1078 |
{ |
| 1079 |
$features[] = trim($term_name); |
| 1080 |
} |
| 1081 |
} |
| 1082 |
} |
| 1083 |
else |
| 1084 |
{ |
| 1085 |
$num_property_features = $this->_features; |
| 1086 |
if ($num_property_features == '') { $num_property_features = 0; } |
| 1087 |
|
| 1088 |
for ($i = 0; $i < $num_property_features; ++$i) |
| 1089 |
{ |
| 1090 |
if ( trim($this->{'_feature_' . $i}) != '' ) |
| 1091 |
{ |
| 1092 |
$features[] = trim($this->{'_feature_' . $i}); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
return apply_filters( 'propertyhive_property_features', $features ); |
| 1098 |
} |
| 1099 |
|
| 1100 |
/** |
| 1101 |
* Get the full formatted address |
| 1102 |
* |
| 1103 |
* @access public |
| 1104 |
* @return string |
| 1105 |
*/ |
| 1106 |
public function get_formatted_full_address( $separator = ', ' ) { |
| 1107 |
// Standard post data |
| 1108 |
|
| 1109 |
$return = ''; |
| 1110 |
|
| 1111 |
$address_name_number = $this->_address_name_number; |
| 1112 |
if ($address_name_number != '') |
| 1113 |
{ |
| 1114 |
$return .= $address_name_number; |
| 1115 |
} |
| 1116 |
$address_street = $this->_address_street; |
| 1117 |
if ($address_street != '') |
| 1118 |
{ |
| 1119 |
if ($return != '') { $return .= ' '; } |
| 1120 |
$return .= $address_street; |
| 1121 |
} |
| 1122 |
$address_two = $this->_address_two; |
| 1123 |
if ($address_two != '') |
| 1124 |
{ |
| 1125 |
if ($return != '') { $return .= $separator; } |
| 1126 |
$return .= $address_two; |
| 1127 |
} |
| 1128 |
$address_three = $this->_address_three; |
| 1129 |
if ($address_three != '') |
| 1130 |
{ |
| 1131 |
if ($return != '') { $return .= $separator; } |
| 1132 |
$return .= $address_three; |
| 1133 |
} |
| 1134 |
$address_four = $this->_address_four; |
| 1135 |
if ($address_four != '') |
| 1136 |
{ |
| 1137 |
if ($return != '') { $return .= $separator; } |
| 1138 |
$return .= $address_four; |
| 1139 |
} |
| 1140 |
$address_postcode = $this->_address_postcode; |
| 1141 |
if ($address_postcode != '') |
| 1142 |
{ |
| 1143 |
if ($return != '') { $return .= $separator; } |
| 1144 |
$return .= $address_postcode; |
| 1145 |
} |
| 1146 |
|
| 1147 |
if ( $return == '' ) |
| 1148 |
{ |
| 1149 |
$return = $this->post_title; |
| 1150 |
} |
| 1151 |
|
| 1152 |
return $return; |
| 1153 |
} |
| 1154 |
|
| 1155 |
/** |
| 1156 |
* Get the summary formatted address |
| 1157 |
* |
| 1158 |
* @access public |
| 1159 |
* @return string |
| 1160 |
*/ |
| 1161 |
public function get_formatted_summary_address( $separator = ', ' ) { |
| 1162 |
// Standard post data |
| 1163 |
|
| 1164 |
$return = ''; |
| 1165 |
|
| 1166 |
$address_name_number = $this->_address_name_number; |
| 1167 |
if ($address_name_number != '') |
| 1168 |
{ |
| 1169 |
$return .= $address_name_number; |
| 1170 |
} |
| 1171 |
$address_street = $this->_address_street; |
| 1172 |
if ($address_street != '') |
| 1173 |
{ |
| 1174 |
if ($return != '') { $return .= ' '; } |
| 1175 |
$return .= $address_street; |
| 1176 |
} |
| 1177 |
$address_two = $this->_address_two; |
| 1178 |
$address_three = $this->_address_three; |
| 1179 |
$address_four = $this->_address_four; |
| 1180 |
if ($address_two != '') |
| 1181 |
{ |
| 1182 |
if ($return != '') { $return .= $separator; } |
| 1183 |
$return .= $address_two; |
| 1184 |
} |
| 1185 |
elseif ($address_three != '') |
| 1186 |
{ |
| 1187 |
if ($return != '') { $return .= $separator; } |
| 1188 |
$return .= $address_three; |
| 1189 |
} |
| 1190 |
elseif ($address_four != '') |
| 1191 |
{ |
| 1192 |
if ($return != '') { $return .= $separator; } |
| 1193 |
$return .= $address_four; |
| 1194 |
} |
| 1195 |
$address_postcode = $this->_address_postcode; |
| 1196 |
if ($address_postcode != '') |
| 1197 |
{ |
| 1198 |
if ($return != '') { $return .= $separator; } |
| 1199 |
$return .= $address_postcode; |
| 1200 |
} |
| 1201 |
|
| 1202 |
if ( $return == '' ) |
| 1203 |
{ |
| 1204 |
$return = $this->post_title; |
| 1205 |
} |
| 1206 |
|
| 1207 |
return $return; |
| 1208 |
} |
| 1209 |
|
| 1210 |
public function get_material_information() |
| 1211 |
{ |
| 1212 |
$return = array(); |
| 1213 |
|
| 1214 |
$utilities = array(); |
| 1215 |
|
| 1216 |
// Utilities |
| 1217 |
$utility_types = array( |
| 1218 |
'electricity' => __( 'Electricity Type', 'propertyhive' ), |
| 1219 |
'water' => __( 'Water Type', 'propertyhive' ), |
| 1220 |
'heating' => __( 'Heating Type', 'propertyhive' ), |
| 1221 |
'broadband' => __( 'Broadband Type', 'propertyhive' ), |
| 1222 |
'sewerage' => __( 'Sewerage Type', 'propertyhive' ), |
| 1223 |
); |
| 1224 |
foreach ( $utility_types as $utility_key => $utility_label ) |
| 1225 |
{ |
| 1226 |
$property_utility_types = $this->{'_' . $utility_key . '_type'}; |
| 1227 |
if ( is_array($property_utility_types) && !empty($property_utility_types) ) |
| 1228 |
{ |
| 1229 |
$types = array(); |
| 1230 |
foreach ( $property_utility_types as $type ) |
| 1231 |
{ |
| 1232 |
if ( $type == 'other' ) |
| 1233 |
{ |
| 1234 |
$types[] = $this->{'_' . $utility_key . '_type_other'}; |
| 1235 |
} |
| 1236 |
else |
| 1237 |
{ |
| 1238 |
$function_name = "get_{$utility_key}_type"; |
| 1239 |
|
| 1240 |
if ( function_exists($function_name) ) |
| 1241 |
{ |
| 1242 |
$types[] = $function_name($type); |
| 1243 |
} |
| 1244 |
else |
| 1245 |
{ |
| 1246 |
$types[] = $type; |
| 1247 |
} |
| 1248 |
} |
| 1249 |
} |
| 1250 |
if ( !isset($utilities[$utility_key]) ) { $utilities[$utility_key] = array(); } |
| 1251 |
$utilities[$utility_key] = implode(", ", $types); |
| 1252 |
} |
| 1253 |
} |
| 1254 |
|
| 1255 |
if ( !empty($utilities) ) |
| 1256 |
{ |
| 1257 |
$return['utilities'] = $utilities; |
| 1258 |
} |
| 1259 |
|
| 1260 |
// Accessibility |
| 1261 |
$accessibility = array(); |
| 1262 |
|
| 1263 |
$property_accessibility = $this->_accessibility; |
| 1264 |
if ( is_array($property_accessibility) && !empty($property_accessibility) ) |
| 1265 |
{ |
| 1266 |
foreach ( $property_accessibility as $type ) |
| 1267 |
{ |
| 1268 |
if ( $type == 'other' ) |
| 1269 |
{ |
| 1270 |
$accessibility[] = $this->_accessibility_other; |
| 1271 |
} |
| 1272 |
else |
| 1273 |
{ |
| 1274 |
$function_name = "get_accessibility_type"; |
| 1275 |
|
| 1276 |
if ( function_exists($function_name) ) |
| 1277 |
{ |
| 1278 |
$accessibility[] = $function_name($type); |
| 1279 |
} |
| 1280 |
else |
| 1281 |
{ |
| 1282 |
$accessibility[] = $type; |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
if ( !empty($accessibility) ) |
| 1289 |
{ |
| 1290 |
$return['accessibility'] = implode(", ", $accessibility); |
| 1291 |
} |
| 1292 |
|
| 1293 |
// Restrictions |
| 1294 |
$restrictions = array(); |
| 1295 |
|
| 1296 |
$property_restriction = $this->_restriction; |
| 1297 |
if ( is_array($property_restriction) && !empty($property_restriction) ) |
| 1298 |
{ |
| 1299 |
foreach ( $property_restriction as $type ) |
| 1300 |
{ |
| 1301 |
if ( $type == 'other' ) |
| 1302 |
{ |
| 1303 |
$restrictions[] = $this->_restriction_other; |
| 1304 |
} |
| 1305 |
else |
| 1306 |
{ |
| 1307 |
$function_name = "get_restriction"; |
| 1308 |
|
| 1309 |
if ( function_exists($function_name) ) |
| 1310 |
{ |
| 1311 |
$restrictions[] = $function_name($type); |
| 1312 |
} |
| 1313 |
else |
| 1314 |
{ |
| 1315 |
$restrictions[] = $type; |
| 1316 |
} |
| 1317 |
} |
| 1318 |
} |
| 1319 |
} |
| 1320 |
|
| 1321 |
if ( !empty($restrictions) ) |
| 1322 |
{ |
| 1323 |
$return['restrictions'] = implode(", ", $restrictions); |
| 1324 |
} |
| 1325 |
|
| 1326 |
// Rights & Easements |
| 1327 |
$rights = array(); |
| 1328 |
|
| 1329 |
$property_right = $this->_right; |
| 1330 |
if ( is_array($property_right) && !empty($property_right) ) |
| 1331 |
{ |
| 1332 |
foreach ( $property_right as $type ) |
| 1333 |
{ |
| 1334 |
if ( $type == 'other' ) |
| 1335 |
{ |
| 1336 |
$rights[] = $this->_right_other; |
| 1337 |
} |
| 1338 |
else |
| 1339 |
{ |
| 1340 |
$function_name = "get_right"; |
| 1341 |
|
| 1342 |
if ( function_exists($function_name) ) |
| 1343 |
{ |
| 1344 |
$rights[] = $function_name($type); |
| 1345 |
} |
| 1346 |
else |
| 1347 |
{ |
| 1348 |
$rights[] = $type; |
| 1349 |
} |
| 1350 |
} |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
if ( !empty($rights) ) |
| 1355 |
{ |
| 1356 |
$return['rights'] = implode(", ", $rights); |
| 1357 |
} |
| 1358 |
|
| 1359 |
// Flood Risk |
| 1360 |
$flood_data = array(); |
| 1361 |
|
| 1362 |
$property_flood_data = $this->_flooded_in_last_five_years; |
| 1363 |
if ( !empty($property_flood_data) ) |
| 1364 |
{ |
| 1365 |
$flood_data['flooded_in_last_five_years'] = ucfirst($property_flood_data); |
| 1366 |
} |
| 1367 |
|
| 1368 |
$flood_sources = array(); |
| 1369 |
|
| 1370 |
$property_flood_source_type = $this->_flood_source_type; |
| 1371 |
if ( is_array($property_flood_source_type) && !empty($property_flood_source_type) ) |
| 1372 |
{ |
| 1373 |
foreach ( $property_flood_source_type as $type ) |
| 1374 |
{ |
| 1375 |
if ( $type == 'other' ) |
| 1376 |
{ |
| 1377 |
$flood_sources[] = $this->_flood_source_type_other; |
| 1378 |
} |
| 1379 |
else |
| 1380 |
{ |
| 1381 |
$function_name = "get_flooding_source_type"; |
| 1382 |
|
| 1383 |
if ( function_exists($function_name) ) |
| 1384 |
{ |
| 1385 |
$flood_sources[] = $function_name($type); |
| 1386 |
} |
| 1387 |
else |
| 1388 |
{ |
| 1389 |
$flood_sources[] = $type; |
| 1390 |
} |
| 1391 |
} |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
if ( !empty($flood_sources) ) |
| 1396 |
{ |
| 1397 |
$flood_data['flood_source'] = implode(", ", $flood_sources); |
| 1398 |
} |
| 1399 |
|
| 1400 |
$property_flood_data = $this->_flood_defences; |
| 1401 |
if ( !empty($property_flood_data) ) |
| 1402 |
{ |
| 1403 |
$flood_data['flood_defences'] = ucfirst($property_flood_data); |
| 1404 |
} |
| 1405 |
|
| 1406 |
if ( !empty($flood_data) ) |
| 1407 |
{ |
| 1408 |
$return['flood_risk'] = $flood_data; |
| 1409 |
} |
| 1410 |
|
| 1411 |
$return = apply_filters( 'propertyhive_property_material_information', $return, $this ); |
| 1412 |
|
| 1413 |
return $return; |
| 1414 |
} |
| 1415 |
|
| 1416 |
public function get_office_name() |
| 1417 |
{ |
| 1418 |
return get_the_title( $this->_office_id ); |
| 1419 |
} |
| 1420 |
|
| 1421 |
public function get_office_address( $separator = ', ' ) |
| 1422 |
{ |
| 1423 |
$return = ''; |
| 1424 |
|
| 1425 |
for ( $i = 1; $i <= 4; ++$i ) |
| 1426 |
{ |
| 1427 |
$address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE ); |
| 1428 |
if ($address != '') |
| 1429 |
{ |
| 1430 |
if ($return != '') { $return .= $separator; } |
| 1431 |
$return .= $address; |
| 1432 |
} |
| 1433 |
} |
| 1434 |
$address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE ); |
| 1435 |
if ($address != '') |
| 1436 |
{ |
| 1437 |
if ($return != '') { $return .= $separator; } |
| 1438 |
$return .= $address; |
| 1439 |
} |
| 1440 |
|
| 1441 |
return $return; |
| 1442 |
} |
| 1443 |
|
| 1444 |
public function get_office_telephone_number() |
| 1445 |
{ |
| 1446 |
return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE ); |
| 1447 |
} |
| 1448 |
|
| 1449 |
public function get_office_email_address() |
| 1450 |
{ |
| 1451 |
return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE ); |
| 1452 |
} |
| 1453 |
|
| 1454 |
public function get_negotiator_name() |
| 1455 |
{ |
| 1456 |
if ( empty($this->_negotiator_id) ) |
| 1457 |
{ |
| 1458 |
return ''; |
| 1459 |
} |
| 1460 |
|
| 1461 |
$user = get_userdata( $this->_negotiator_id ); |
| 1462 |
|
| 1463 |
if ( $user === false ) |
| 1464 |
{ |
| 1465 |
return ''; |
| 1466 |
} |
| 1467 |
|
| 1468 |
return $user->display_name; |
| 1469 |
} |
| 1470 |
|
| 1471 |
public function get_negotiator_telephone_number( $fallback_to_office = true ) |
| 1472 |
{ |
| 1473 |
if ( empty($this->_negotiator_id) ) |
| 1474 |
{ |
| 1475 |
return ''; |
| 1476 |
} |
| 1477 |
|
| 1478 |
$user = get_userdata( $this->_negotiator_id ); |
| 1479 |
|
| 1480 |
if ( $user === false ) |
| 1481 |
{ |
| 1482 |
return ''; |
| 1483 |
} |
| 1484 |
|
| 1485 |
$telephone_number = get_user_meta( $this->_negotiator_id, 'telephone_number', true ); |
| 1486 |
|
| 1487 |
if ( empty($telephone_number) && $fallback_to_office ) |
| 1488 |
{ |
| 1489 |
// need to fallback |
| 1490 |
$telephone_number = $this->get_office_telephone_number(); |
| 1491 |
} |
| 1492 |
|
| 1493 |
return $telephone_number; |
| 1494 |
} |
| 1495 |
|
| 1496 |
public function get_negotiator_email_address( $fallback_to_office = true ) |
| 1497 |
{ |
| 1498 |
if ( empty($this->_negotiator_id) ) |
| 1499 |
{ |
| 1500 |
return ''; |
| 1501 |
} |
| 1502 |
|
| 1503 |
$user = get_userdata( $this->_negotiator_id ); |
| 1504 |
|
| 1505 |
if ( $user === false ) |
| 1506 |
{ |
| 1507 |
return ''; |
| 1508 |
} |
| 1509 |
|
| 1510 |
$email_address = $user->user_email; |
| 1511 |
|
| 1512 |
if ( empty($email_address) && $fallback_to_office ) |
| 1513 |
{ |
| 1514 |
// need to fallback |
| 1515 |
$email_address = $this->get_office_email_address(); |
| 1516 |
} |
| 1517 |
|
| 1518 |
return $email_address; |
| 1519 |
} |
| 1520 |
|
| 1521 |
public function get_negotiator_photo() |
| 1522 |
{ |
| 1523 |
if ( empty($this->_negotiator_id) ) |
| 1524 |
{ |
| 1525 |
return ''; |
| 1526 |
} |
| 1527 |
|
| 1528 |
$user = get_userdata( $this->_negotiator_id ); |
| 1529 |
|
| 1530 |
if ( $user === false ) |
| 1531 |
{ |
| 1532 |
return ''; |
| 1533 |
} |
| 1534 |
|
| 1535 |
$photo_attachment_id = get_user_meta( $this->_negotiator_id, 'photo_attachment_id', true ); |
| 1536 |
|
| 1537 |
$photo = wp_get_attachment_image( $photo_attachment_id, 'large' ); |
| 1538 |
|
| 1539 |
return $photo; |
| 1540 |
} |
| 1541 |
|
| 1542 |
/** |
| 1543 |
* Returns boolean whether the property is featured or not |
| 1544 |
* |
| 1545 |
* @access public |
| 1546 |
* @return string |
| 1547 |
*/ |
| 1548 |
public function is_featured() { |
| 1549 |
|
| 1550 |
if ( $this->_featured == 'yes' ) |
| 1551 |
{ |
| 1552 |
return true; |
| 1553 |
} |
| 1554 |
|
| 1555 |
return false; |
| 1556 |
|
| 1557 |
} |
| 1558 |
|
| 1559 |
/** |
| 1560 |
* Adds a note (comment) to the property |
| 1561 |
* |
| 1562 |
* @access public |
| 1563 |
* @param string $note Note to add |
| 1564 |
* @return id Comment ID |
| 1565 |
*/ |
| 1566 |
public function add_note( $note ) { |
| 1567 |
|
| 1568 |
if ( is_user_logged_in() ) |
| 1569 |
{ |
| 1570 |
$user = get_user_by( 'id', get_current_user_id() ); |
| 1571 |
|
| 1572 |
$commentdata = array( |
| 1573 |
'comment_post_ID' => $this->id, |
| 1574 |
'comment_author' => $user->display_name, |
| 1575 |
'comment_author_email' => $user->user_email, |
| 1576 |
'comment_author_url' => '', |
| 1577 |
'comment_content' => $note, |
| 1578 |
'comment_type' => 'propertyhive_note', |
| 1579 |
'comment_parent' => 0, |
| 1580 |
'user_id' => $user->ID, |
| 1581 |
'comment_agent' => 'PropertyHive', |
| 1582 |
'comment_date' => current_time('mysql'), |
| 1583 |
'comment_approved' => 1, |
| 1584 |
); |
| 1585 |
|
| 1586 |
$comment_id = wp_insert_comment( $commentdata ); |
| 1587 |
|
| 1588 |
return $comment_id; |
| 1589 |
} |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
} |
| 1596 |
|