PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / class-ph-property.php

class-ph-property.php in Property Hive 1.4.53, at includes/class-ph-property.php

1,257 lines 37.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
22 * Get the property if ID is passed, otherwise the property is new and empty.
23 *
24 * @access public
25 * @param string|object $id (default: '')
26 * @return void
27 */
28 public function __construct( $id = '' ) {
29 if ( $id != '' )
30 {
31 if ( is_int($id) && $id > 0 )
32 {
33
34 }
35 else
36 {
37 // Must be post object
38 $id = $id->ID;
39 }
40 $this->get_property( $id );
41 }
42 }
43
44 /**
45 * Gets a property from the database.
46 *
47 * @access public
48 * @param int $id (default: 0)
49 * @return bool
50 */
51 public function get_property( $id = 0 ) {
52 if ( ! $id ) {
53 return false;
54 }
55 if ( $result = get_post( $id ) ) {
56 $this->populate( $result );
57 return true;
58 }
59 return false;
60 }
61
62 /**
63 * __isset function.
64 *
65 * @access public
66 * @param mixed $key
67 * @return bool
68 */
69 public function __isset( $key ) {
70 if ( ! $this->id ) {
71 return false;
72 }
73 return metadata_exists( 'post', $this->id, $key );
74 }
75
76 /**
77 * __get function.
78 *
79 * @access public
80 * @param mixed $key
81 * @return mixed
82 */
83 public function __get( $key ) {
84
85 if ( 'property_type' == $key )
86 {
87 return $this->get_property_type();
88 }
89 if ( 'availability' == $key )
90 {
91 return $this->get_availability();
92 }
93 if ( 'location' == $key )
94 {
95 return $this->get_location();
96 }
97 if ( 'price_qualifier' == $key )
98 {
99 return $this->get_price_qualifier();
100 }
101 if ( 'tenure' == $key )
102 {
103 return $this->get_tenure();
104 }
105 if ( 'sale_by' == $key )
106 {
107 return $this->get_sale_by();
108 }
109 if ( 'furnished' == $key )
110 {
111 return $this->get_furnished();
112 }
113 if ( 'parking' == $key )
114 {
115 return $this->get_parking();
116 }
117 if ( 'outside_space' == $key )
118 {
119 return $this->get_outside_space();
120 }
121 if ( 'marketing_flag' == $key )
122 {
123 return $this->get_marketing_flag();
124 }
125 if ( 'imported_id' == $key )
126 {
127 return $this->get_imported_id();
128 }
129 if ( 'office_name' == $key )
130 {
131 return $this->get_office_name();
132 }
133 if ( 'office_address' == $key )
134 {
135 return $this->get_office_address();
136 }
137 if ( 'office_telephone_number' == $key )
138 {
139 return $this->get_office_telephone_number();
140 }
141 if ( 'office_email_address' == $key )
142 {
143 return $this->get_office_email_address();
144 }
145
146 // Get values or default if not set
147 $value = get_post_meta( $this->id, $key, true );
148 if ($value == '')
149 {
150 $value = get_post_meta( $this->id, '_' . $key, true );
151 }
152 return $value;
153 }
154
155 /**
156 * Populates a property from the loaded post data.
157 *
158 * @access public
159 * @param mixed $result
160 * @return void
161 */
162 public function populate( $result ) {
163 // Standard post data
164 $this->id = $result->ID;
165 $this->post_title = $result->post_title;
166 $this->post_status = $result->post_status;
167 $this->post_excerpt = $result->post_excerpt;
168 }
169
170 /**
171 * get_gallery_attachment_ids function.
172 *
173 * @access public
174 * @return array
175 */
176 public function get_gallery_attachment_ids()
177 {
178 $photos = $this->photos;
179 if ( is_array($photos) )
180 {
181 $photos = array_filter( $photos );
182 }
183 else
184 {
185 $photos = array();
186 }
187 return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this );
188 }
189
190 /**
191 * Gets the first photo
192 *
193 * @access public
194 * @param string $size
195 * @return string
196 */
197 public function get_main_photo_src( $size = 'thumbnail' ) {
198
199 $return = false;
200
201 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
202 {
203 $photos = $this->_photo_urls;
204
205 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
206 {
207 $return = $photos[0]['url'];
208 }
209 }
210 else
211 {
212 $photos = $this->_photos;
213
214
215
216 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
217 {
218 $image_attributes = wp_get_attachment_image_src( $photos[0], $size );
219 if( $image_attributes )
220 {
221 $return = $image_attributes[0];
222 }
223 }
224 }
225
226
227 return $return;
228 }
229
230 /**
231 * get_floorplan_attachment_ids function.
232 *
233 * @access public
234 * @return array
235 */
236 public function get_floorplan_attachment_ids()
237 {
238 $floorplans = $this->_floorplans;
239 if ( is_array($floorplans) )
240 {
241 $floorplans = array_filter( $floorplans );
242 }
243 else
244 {
245 $floorplans = array();
246 }
247 return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this );
248 }
249
250 /**
251 * get_brochure_attachment_ids function.
252 *
253 * @access public
254 * @return array
255 */
256 public function get_brochure_attachment_ids()
257 {
258 $brochures = $this->_brochures;
259 if ( is_array($brochures) )
260 {
261 $brochures = array_filter( $brochures );
262 }
263 else
264 {
265 $brochures = array();
266 }
267 return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this );
268 }
269
270 /**
271 * get_epc_attachment_ids function.
272 *
273 * @access public
274 * @return array
275 */
276 public function get_epc_attachment_ids()
277 {
278 $epcs = $this->_epcs;
279 if ( is_array($epcs) )
280 {
281 $epcs = array_filter( $epcs );
282 }
283 else
284 {
285 $epcs = array();
286 }
287 return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
288 }
289
290 /**
291 * get_virtual_tour_urls function.
292 *
293 * @access public
294 * @return array
295 */
296 public function get_virtual_tour_urls()
297 {
298 $num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
299 if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
300
301 $virtual_tour_urls = array();
302 for ($i = 0; $i < $num_property_virtual_tours; ++$i)
303 {
304 $virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE);
305 }
306
307 return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this );
308 }
309
310 /**
311 * Get the formatted price based on department. Show POA if on frontend and 'POA' ticked
312 *
313 * @access public
314 * @return string
315 */
316 public function get_formatted_price( ) {
317
318 $return = '';
319
320 $currency = array();
321 $prefix = '';
322 $suffix = '';
323
324 if ( $this->_department == 'commercial' )
325 {
326 $price = '';
327
328 // Price Details
329 $price .= $this->get_formatted_commercial_price();
330
331 // Rent Details
332 $rent = $this->get_formatted_commercial_rent();
333 if ( $price != '' && $rent != '' )
334 {
335 $price .= '<br>';
336 }
337 $price .= $rent;
338
339 $return = $price;
340 }
341 else
342 {
343 if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
344 {
345 $return = __( 'POA', 'propertyhive' );
346 }
347 else
348 {
349 $ph_countries = new PH_Countries();
350
351 if ( !is_admin() )
352 {
353 if ( isset($_GET['currency']) )
354 {
355 if ( $_GET['currency'] != '' )
356 {
357 $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
358 if ( $requested_currency !== FALSE )
359 {
360 $currency = $requested_currency;
361 $currency['exchange_rate'] = 1;
362 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
363 if ( isset($exchange_rates[$_GET['currency']]) )
364 {
365 $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
366 }
367 }
368 }
369 else
370 {
371 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
372 if ( $default_currency != '' )
373 {
374 $requested_currency = $ph_countries->get_currency( $default_currency );
375 if ( $requested_currency !== FALSE )
376 {
377 $currency = $requested_currency;
378 $currency['exchange_rate'] = 1;
379 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
380 if ( isset($exchange_rates[$default_currency]) )
381 {
382 $currency['exchange_rate'] = $exchange_rates[$default_currency];
383 }
384 }
385 }
386 }
387 }
388 elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
389 {
390 $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
391 }
392 else
393 {
394 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
395 if ( $default_currency != '' )
396 {
397 $requested_currency = $ph_countries->get_currency( $default_currency );
398 if ( $requested_currency !== FALSE )
399 {
400 $currency = $requested_currency;
401 $currency['exchange_rate'] = 1;
402 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
403 if ( isset($exchange_rates[$default_currency]) )
404 {
405 $currency['exchange_rate'] = $exchange_rates[$default_currency];
406 }
407 }
408 }
409 }
410 }
411
412 if ( empty($currency) )
413 {
414 if ($this->_currency != '')
415 {
416 $currency = $ph_countries->get_currency( $this->_currency );
417 }
418 else
419 {
420 $currency = $ph_countries->get_currency( 'GBP' );
421 }
422 }
423 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
424 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
425 switch ($this->_department)
426 {
427 case "residential-sales":
428 {
429 $price = $this->_price;
430 if ( isset($currency['exchange_rate']) && $price != '' )
431 {
432 $price = $this->_price_actual * $currency['exchange_rate'];
433 }
434 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix : '-' );
435 break;
436 }
437 case "residential-lettings":
438 {
439 $price = $this->_rent;
440 if ( isset($currency['exchange_rate']) && $price != '' )
441 {
442 $price = $this->_price_actual * $currency['exchange_rate'];
443 switch ( $this->_rent_frequency )
444 {
445 case "pw": { $price = ($price * 12) / 52; break; }
446 case "pq": { $price = ($price * 12) / 4; break; }
447 case "pa": { $price = ($price * 12); break; }
448 }
449 }
450 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
451 break;
452 }
453 }
454 }
455 }
456
457 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
458 }
459
460 /**
461 * Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
462 *
463 * @access public
464 * @return string
465 */
466 public function get_formatted_commercial_price( ) {
467
468 $price = '';
469
470 if ( $this->_for_sale == 'yes' )
471 {
472 if ( !is_admin() && $this->_price_poa == 'yes' )
473 {
474 $price .= __( 'POA', 'propertyhive' );
475 }
476 else
477 {
478 $ph_countries = new PH_Countries();
479 if ( $this->_commercial_price_currency != '' )
480 {
481 $currency = $ph_countries->get_currency( $this->_commercial_price_currency );
482 }
483 else
484 {
485 $currency = $ph_countries->get_currency( 'GBP' );
486 }
487 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
488 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
489
490 if ( $this->_price_from != '' )
491 {
492 $explode_price = explode(".", $this->_price_from);
493 if ( count($explode_price) == 2 )
494 {
495 $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;
496 }
497 else
498 {
499 $price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
500 }
501 }
502 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
503 {
504 if ( $price != '' )
505 {
506 $price .= ' - ';
507 }
508 $explode_price = explode(".", $this->_price_to);
509 if ( count($explode_price) == 2 )
510 {
511 $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;
512 }
513 else
514 {
515 $price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
516 }
517 }
518 if ( $price != '' )
519 {
520 $price_units = get_commercial_price_units( );
521 $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
522 }
523 }
524 }
525
526 return $price;
527 }
528
529 /**
530 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
531 *
532 * @access public
533 * @return string
534 */
535 public function get_formatted_commercial_rent( ) {
536
537 $rent = '';
538
539 if ( $this->_to_rent == 'yes' )
540 {
541 if ( !is_admin() && $this->_rent_poa == 'yes' )
542 {
543 $rent .= __( 'POA', 'propertyhive' );
544 }
545 else
546 {
547 $ph_countries = new PH_Countries();
548 if ( $this->_commercial_rent_currency != '' )
549 {
550 $currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
551 }
552 else
553 {
554 $currency = $ph_countries->get_currency( 'GBP' );
555 }
556 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
557 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
558
559 if ( $this->_rent_from != '' )
560 {
561 $explode_rent = explode(".", $this->_rent_from);
562 if ( count($explode_rent) == 2 )
563 {
564 $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;
565 }
566 else
567 {
568 $rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
569 }
570 }
571 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
572 {
573 if ( $rent != '' )
574 {
575 $rent .= ' - ';
576 }
577 $explode_rent = explode(".", $this->_rent_to);
578 if ( count($explode_rent) == 2 )
579 {
580 $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;
581 }
582 else
583 {
584 $rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
585 }
586 }
587 if ( $rent != '' )
588 {
589 $price_units = get_commercial_price_units( );
590 $rent .= ' ' . ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units );
591 }
592 }
593 }
594
595 return $rent;
596 }
597
598 public function get_formatted_floor_area( ) {
599
600 $area = '';
601
602 if ( $this->_floor_area_from != '' )
603 {
604 $explode_area = explode(".", $this->_floor_area_from);
605 if ( count($explode_area) == 2 )
606 {
607 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
608 }
609 else
610 {
611 $area .= number_format($this->_floor_area_from, 0);
612 }
613 }
614 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
615 {
616 if ( $area != '' )
617 {
618 $area .= ' - ';
619 }
620 $explode_area = explode(".", $this->_floor_area_to);
621 if ( count($explode_area) == 2 )
622 {
623 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
624 }
625 else
626 {
627 $area .= number_format($this->_floor_area_to, 0);
628 }
629 }
630
631 if ( $area != '' )
632 {
633 $area_units = get_area_units( );
634 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
635 }
636
637 return $area;
638
639 }
640
641 public function get_formatted_site_area( ) {
642
643 $area = '';
644
645 if ( $this->_site_area_from != '' )
646 {
647 $explode_area = explode(".", $this->_site_area_from);
648 if ( count($explode_area) == 2 )
649 {
650 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
651 }
652 else
653 {
654 $area .= number_format($this->_site_area_from, 0);
655 }
656 }
657 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
658 {
659 if ( $area != '' )
660 {
661 $area .= ' - ';
662 }
663 $explode_area = explode(".", $this->_site_area_to);
664 if ( count($explode_area) == 2 )
665 {
666 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
667 }
668 else
669 {
670 $area .= number_format($this->_site_area_to, 0);
671 }
672 }
673
674 if ( $area != '' )
675 {
676 $area_units = get_area_units( );
677 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
678 }
679
680 return $area;
681
682 }
683
684 /**
685 * Get the formatted deposit
686 *
687 * @access public
688 * @return string
689 */
690 public function get_formatted_deposit( )
691 {
692 if ( $this->_deposit == '' )
693 {
694 return '';
695 }
696
697 $ph_countries = new PH_Countries();
698
699 $currency = $ph_countries->get_currency( $this->_currency );
700 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
701 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
702
703 return $prefix . number_format($this->_deposit, 0) . $suffix;
704 }
705
706 /**
707 * Get the available date, or 'Now' if date is in past
708 *
709 * @access public
710 * @return string
711 */
712 public function get_available_date( )
713 {
714 if (strtotime($this->_available_date))
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( ) {
731
732 if ( $this->_department == 'commercial' )
733 {
734 return $this->get_formatted_descriptions(); // Haven't called this commercial_descriptions as we might use generic descriptions for other area going forward
735 }
736 else
737 {
738 return $this->get_formatted_rooms();
739 }
740 }
741
742 /**
743 * Get the full description by constructing the rooms
744 *
745 * @access public
746 * @return string
747 */
748 public function get_formatted_rooms( ) {
749
750 $rooms = $this->_rooms;
751
752 $return = '';
753
754 if (isset($rooms) && $rooms != '' && $rooms > 0)
755 {
756 for ($i = 0; $i < $rooms; ++$i)
757 {
758 $return .= '<p class="room">';
759 if ($this->{'_room_name_' . $i} != '')
760 {
761 $return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>';
762 }
763 if ($this->{'_room_dimensions_' . $i} != '')
764 {
765 $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
766 }
767 if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
768 {
769 $return .= '<br>';
770 }
771 $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
772 }
773 }
774
775 return $return;
776 }
777
778 /**
779 * Get the full description by constructing the descriptions
780 *
781 * @access public
782 * @return string
783 */
784 public function get_formatted_descriptions( ) {
785
786 $descriptions = $this->_descriptions;
787
788 $return = '';
789
790 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
791 {
792 for ($i = 0; $i < $descriptions; ++$i)
793 {
794 $return .= '<p class="description-section">';
795 if ($this->{'_description_name_' . $i} != '')
796 {
797 $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>';
798 }
799 $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
800 }
801 }
802
803 return $return;
804 }
805
806 /**
807 * Get the property type taxononmy
808 *
809 * @access public
810 * @return string
811 */
812 public function get_property_type()
813 {
814 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
815
816 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
817 {
818 return implode(", ", $term_list);
819 }
820
821 return '';
822 }
823
824 /**
825 * Get the availability taxononmy
826 *
827 * @access public
828 * @return string
829 */
830 public function get_availability()
831 {
832 $term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names"));
833
834 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
835 {
836 return implode(", ", $term_list);
837 }
838
839 return '';
840 }
841
842 /**
843 * Get the location taxononmy
844 *
845 * @access public
846 * @return string
847 */
848 public function get_location()
849 {
850 $term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names"));
851
852 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
853 {
854 return implode(", ", $term_list);
855 }
856
857 return '';
858 }
859
860 /**
861 * Get the price qualifier taxononmy
862 *
863 * @access public
864 * @return string
865 */
866 public function get_price_qualifier()
867 {
868 $term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names"));
869
870 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
871 {
872 return implode(", ", $term_list);
873 }
874
875 return '';
876 }
877
878 /**
879 * Get the tenure taxononmy
880 *
881 * @access public
882 * @return string
883 */
884 public function get_tenure()
885 {
886 $term_list = wp_get_post_terms($this->id, 'tenure', array("fields" => "names"));
887
888 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
889 {
890 return implode(", ", $term_list);
891 }
892
893 return '';
894 }
895
896 /**
897 * Get the sale by taxononmy
898 *
899 * @access public
900 * @return string
901 */
902 public function get_sale_by()
903 {
904 $term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names"));
905
906 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
907 {
908 return implode(", ", $term_list);
909 }
910
911 return '';
912 }
913
914 /**
915 * Get the furnished taxononmy
916 *
917 * @access public
918 * @return string
919 */
920 public function get_furnished()
921 {
922 $term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names"));
923
924 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
925 {
926 return implode(", ", $term_list);
927 }
928
929 return '';
930 }
931
932 /**
933 * Get the parking taxononmy
934 *
935 * @access public
936 * @return string
937 */
938 public function get_parking()
939 {
940 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
941
942 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
943 {
944 return implode(", ", $term_list);
945 }
946
947 return '';
948 }
949
950 /**
951 * Get the outside space taxononmy
952 *
953 * @access public
954 * @return string
955 */
956 public function get_outside_space()
957 {
958 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
959
960 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
961 {
962 return implode(", ", $term_list);
963 }
964
965 return '';
966 }
967
968 /**
969 * Get the marketing flag taxononmy
970 *
971 * @access public
972 * @return string
973 */
974 public function get_marketing_flag()
975 {
976 $term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names"));
977
978 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
979 {
980 return implode(", ", $term_list);
981 }
982
983 return '';
984 }
985
986 /**
987 * Get the ID of property from third party system
988 *
989 * @access public
990 * @return string
991 */
992 public function get_imported_id()
993 {
994 global $wpdb;
995
996 $row = $wpdb->get_row(
997 "
998 SELECT meta_value
999 FROM {$wpdb->prefix}postmeta
1000 WHERE
1001 meta_key LIKE '_imported_ref_%'
1002 AND
1003 post_id = '" . $this->id . "'
1004 LIMIT 1
1005 ",
1006 ARRAY_A
1007 );
1008
1009 if ( null !== $row )
1010 {
1011 return $row['meta_value'];
1012 }
1013
1014 return '';
1015 }
1016
1017 /**
1018 * Get an array of property features
1019 *
1020 * @access public
1021 * @return array
1022 */
1023 public function get_features( )
1024 {
1025 $features = array();
1026
1027 if ( get_option('propertyhive_features_type') == 'checkbox' )
1028 {
1029 $term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names"));
1030 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1031 {
1032 foreach ( $term_list as $term_name )
1033 {
1034 $features[] = trim($term_name);
1035 }
1036 }
1037 }
1038 else
1039 {
1040 $num_property_features = $this->_features;
1041 if ($num_property_features == '') { $num_property_features = 0; }
1042
1043 for ($i = 0; $i < $num_property_features; ++$i)
1044 {
1045 if ( trim($this->{'_feature_' . $i}) != '' )
1046 {
1047 $features[] = trim($this->{'_feature_' . $i});
1048 }
1049 }
1050 }
1051
1052 return $features;
1053 }
1054
1055 /**
1056 * Get the full formatted address
1057 *
1058 * @access public
1059 * @return string
1060 */
1061 public function get_formatted_full_address( $separator = ', ' ) {
1062 // Standard post data
1063
1064 $return = '';
1065
1066 $address_name_number = $this->_address_name_number;
1067 if ($address_name_number != '')
1068 {
1069 $return .= $address_name_number;
1070 }
1071 $address_street = $this->_address_street;
1072 if ($address_street != '')
1073 {
1074 if ($return != '') { $return .= ' '; }
1075 $return .= $address_street;
1076 }
1077 $address_two = $this->_address_two;
1078 if ($address_two != '')
1079 {
1080 if ($return != '') { $return .= $separator; }
1081 $return .= $address_two;
1082 }
1083 $address_three = $this->_address_three;
1084 if ($address_three != '')
1085 {
1086 if ($return != '') { $return .= $separator; }
1087 $return .= $address_three;
1088 }
1089 $address_four = $this->_address_four;
1090 if ($address_four != '')
1091 {
1092 if ($return != '') { $return .= $separator; }
1093 $return .= $address_four;
1094 }
1095 $address_postcode = $this->_address_postcode;
1096 if ($address_postcode != '')
1097 {
1098 if ($return != '') { $return .= $separator; }
1099 $return .= $address_postcode;
1100 }
1101
1102 if ( $return == '' )
1103 {
1104 $return = $this->post_title;
1105 }
1106
1107 return $return;
1108 }
1109
1110 /**
1111 * Get the summary formatted address
1112 *
1113 * @access public
1114 * @return string
1115 */
1116 public function get_formatted_summary_address( $separator = ', ' ) {
1117 // Standard post data
1118
1119 $return = '';
1120
1121 $address_name_number = $this->_address_name_number;
1122 if ($address_name_number != '')
1123 {
1124 $return .= $address_name_number;
1125 }
1126 $address_street = $this->_address_street;
1127 if ($address_street != '')
1128 {
1129 if ($return != '') { $return .= ' '; }
1130 $return .= $address_street;
1131 }
1132 $address_two = $this->_address_two;
1133 $address_three = $this->_address_three;
1134 $address_four = $this->_address_four;
1135 if ($address_two != '')
1136 {
1137 if ($return != '') { $return .= $separator; }
1138 $return .= $address_two;
1139 }
1140 elseif ($address_three != '')
1141 {
1142 if ($return != '') { $return .= $separator; }
1143 $return .= $address_three;
1144 }
1145 elseif ($address_four != '')
1146 {
1147 if ($return != '') { $return .= $separator; }
1148 $return .= $address_four;
1149 }
1150 $address_postcode = $this->_address_postcode;
1151 if ($address_postcode != '')
1152 {
1153 if ($return != '') { $return .= $separator; }
1154 $return .= $address_postcode;
1155 }
1156
1157 if ( $return == '' )
1158 {
1159 $return = $this->post_title;
1160 }
1161
1162 return $return;
1163 }
1164
1165 public function get_office_name()
1166 {
1167 return get_the_title( $this->_office_id );
1168 }
1169
1170 public function get_office_address( $separator = ', ' )
1171 {
1172 $return = '';
1173
1174 for ( $i = 1; $i <= 4; ++$i )
1175 {
1176 $address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE );
1177 if ($address != '')
1178 {
1179 if ($return != '') { $return .= $separator; }
1180 $return .= $address;
1181 }
1182 }
1183 $address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE );
1184 if ($address != '')
1185 {
1186 if ($return != '') { $return .= $separator; }
1187 $return .= $address;
1188 }
1189
1190 return $return;
1191 }
1192
1193 public function get_office_telephone_number()
1194 {
1195 return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1196 }
1197
1198 public function get_office_email_address()
1199 {
1200 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1201 }
1202
1203 /**
1204 * Returns boolean whether the property is featured or not
1205 *
1206 * @access public
1207 * @return string
1208 */
1209 public function is_featured() {
1210
1211 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1212 {
1213 return true;
1214 }
1215
1216 return false;
1217
1218 }
1219
1220 /**
1221 * Adds a note (comment) to the property
1222 *
1223 * @access public
1224 * @param string $note Note to add
1225 * @return id Comment ID
1226 */
1227 public function add_note( $note ) {
1228
1229 if ( is_user_logged_in() )
1230 {
1231 $user = get_user_by( 'id', get_current_user_id() );
1232
1233 $commentdata = array(
1234 'comment_post_ID' => $this->id,
1235 'comment_author' => $user->display_name,
1236 'comment_author_email' => $user->user_email,
1237 'comment_author_url' => '',
1238 'comment_content' => $note,
1239 'comment_type' => 'propertyhive_note',
1240 'comment_parent' => 0,
1241 'user_id' => $user->ID,
1242 'comment_agent' => 'PropertyHive',
1243 'comment_date' => current_time('mysql'),
1244 'comment_approved' => 1,
1245 );
1246
1247 $comment_id = wp_insert_comment( $commentdata );
1248
1249 return $comment_id;
1250 }
1251 }
1252
1253
1254
1255
1256 }
1257