PluginProbe
Property Hive / 1.4.46
Property Hive v1.4.46
2.3.1 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 All 261 releases
propertyhive / includes / class-ph-property.php

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

1,261 lines 38.0 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>';
798 }
799 if ($this->{'_description_' . $i} != '')
800 {
801 $return .= '<br>';
802 }
803 $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
804 }
805 }
806
807 return $return;
808 }
809
810 /**
811 * Get the property type taxononmy
812 *
813 * @access public
814 * @return string
815 */
816 public function get_property_type()
817 {
818 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
819
820 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
821 {
822 return implode(", ", $term_list);
823 }
824
825 return '';
826 }
827
828 /**
829 * Get the availability taxononmy
830 *
831 * @access public
832 * @return string
833 */
834 public function get_availability()
835 {
836 $term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names"));
837
838 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
839 {
840 return implode(", ", $term_list);
841 }
842
843 return '';
844 }
845
846 /**
847 * Get the location taxononmy
848 *
849 * @access public
850 * @return string
851 */
852 public function get_location()
853 {
854 $term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names"));
855
856 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
857 {
858 return implode(", ", $term_list);
859 }
860
861 return '';
862 }
863
864 /**
865 * Get the price qualifier taxononmy
866 *
867 * @access public
868 * @return string
869 */
870 public function get_price_qualifier()
871 {
872 $term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names"));
873
874 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
875 {
876 return implode(", ", $term_list);
877 }
878
879 return '';
880 }
881
882 /**
883 * Get the tenure taxononmy
884 *
885 * @access public
886 * @return string
887 */
888 public function get_tenure()
889 {
890 $term_list = wp_get_post_terms($this->id, 'tenure', array("fields" => "names"));
891
892 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
893 {
894 return implode(", ", $term_list);
895 }
896
897 return '';
898 }
899
900 /**
901 * Get the sale by taxononmy
902 *
903 * @access public
904 * @return string
905 */
906 public function get_sale_by()
907 {
908 $term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names"));
909
910 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
911 {
912 return implode(", ", $term_list);
913 }
914
915 return '';
916 }
917
918 /**
919 * Get the furnished taxononmy
920 *
921 * @access public
922 * @return string
923 */
924 public function get_furnished()
925 {
926 $term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names"));
927
928 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
929 {
930 return implode(", ", $term_list);
931 }
932
933 return '';
934 }
935
936 /**
937 * Get the parking taxononmy
938 *
939 * @access public
940 * @return string
941 */
942 public function get_parking()
943 {
944 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
945
946 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
947 {
948 return implode(", ", $term_list);
949 }
950
951 return '';
952 }
953
954 /**
955 * Get the outside space taxononmy
956 *
957 * @access public
958 * @return string
959 */
960 public function get_outside_space()
961 {
962 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
963
964 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
965 {
966 return implode(", ", $term_list);
967 }
968
969 return '';
970 }
971
972 /**
973 * Get the marketing flag taxononmy
974 *
975 * @access public
976 * @return string
977 */
978 public function get_marketing_flag()
979 {
980 $term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names"));
981
982 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
983 {
984 return implode(", ", $term_list);
985 }
986
987 return '';
988 }
989
990 /**
991 * Get the ID of property from third party system
992 *
993 * @access public
994 * @return string
995 */
996 public function get_imported_id()
997 {
998 global $wpdb;
999
1000 $row = $wpdb->get_row(
1001 "
1002 SELECT meta_value
1003 FROM {$wpdb->prefix}postmeta
1004 WHERE
1005 meta_key LIKE '_imported_ref_%'
1006 AND
1007 post_id = '" . $this->id . "'
1008 LIMIT 1
1009 ",
1010 ARRAY_A
1011 );
1012
1013 if ( null !== $row )
1014 {
1015 return $row['meta_value'];
1016 }
1017
1018 return '';
1019 }
1020
1021 /**
1022 * Get an array of property features
1023 *
1024 * @access public
1025 * @return array
1026 */
1027 public function get_features( )
1028 {
1029 $features = array();
1030
1031 if ( get_option('propertyhive_features_type') == 'checkbox' )
1032 {
1033 $term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names"));
1034 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1035 {
1036 foreach ( $term_list as $term_name )
1037 {
1038 $features[] = trim($term_name);
1039 }
1040 }
1041 }
1042 else
1043 {
1044 $num_property_features = $this->_features;
1045 if ($num_property_features == '') { $num_property_features = 0; }
1046
1047 for ($i = 0; $i < $num_property_features; ++$i)
1048 {
1049 if ( trim($this->{'_feature_' . $i}) != '' )
1050 {
1051 $features[] = trim($this->{'_feature_' . $i});
1052 }
1053 }
1054 }
1055
1056 return $features;
1057 }
1058
1059 /**
1060 * Get the full formatted address
1061 *
1062 * @access public
1063 * @return string
1064 */
1065 public function get_formatted_full_address( $separator = ', ' ) {
1066 // Standard post data
1067
1068 $return = '';
1069
1070 $address_name_number = $this->_address_name_number;
1071 if ($address_name_number != '')
1072 {
1073 $return .= $address_name_number;
1074 }
1075 $address_street = $this->_address_street;
1076 if ($address_street != '')
1077 {
1078 if ($return != '') { $return .= ' '; }
1079 $return .= $address_street;
1080 }
1081 $address_two = $this->_address_two;
1082 if ($address_two != '')
1083 {
1084 if ($return != '') { $return .= $separator; }
1085 $return .= $address_two;
1086 }
1087 $address_three = $this->_address_three;
1088 if ($address_three != '')
1089 {
1090 if ($return != '') { $return .= $separator; }
1091 $return .= $address_three;
1092 }
1093 $address_four = $this->_address_four;
1094 if ($address_four != '')
1095 {
1096 if ($return != '') { $return .= $separator; }
1097 $return .= $address_four;
1098 }
1099 $address_postcode = $this->_address_postcode;
1100 if ($address_postcode != '')
1101 {
1102 if ($return != '') { $return .= $separator; }
1103 $return .= $address_postcode;
1104 }
1105
1106 if ( $return == '' )
1107 {
1108 $return = $this->post_title;
1109 }
1110
1111 return $return;
1112 }
1113
1114 /**
1115 * Get the summary formatted address
1116 *
1117 * @access public
1118 * @return string
1119 */
1120 public function get_formatted_summary_address( $separator = ', ' ) {
1121 // Standard post data
1122
1123 $return = '';
1124
1125 $address_name_number = $this->_address_name_number;
1126 if ($address_name_number != '')
1127 {
1128 $return .= $address_name_number;
1129 }
1130 $address_street = $this->_address_street;
1131 if ($address_street != '')
1132 {
1133 if ($return != '') { $return .= ' '; }
1134 $return .= $address_street;
1135 }
1136 $address_two = $this->_address_two;
1137 $address_three = $this->_address_three;
1138 $address_four = $this->_address_four;
1139 if ($address_two != '')
1140 {
1141 if ($return != '') { $return .= $separator; }
1142 $return .= $address_two;
1143 }
1144 elseif ($address_three != '')
1145 {
1146 if ($return != '') { $return .= $separator; }
1147 $return .= $address_three;
1148 }
1149 elseif ($address_four != '')
1150 {
1151 if ($return != '') { $return .= $separator; }
1152 $return .= $address_four;
1153 }
1154 $address_postcode = $this->_address_postcode;
1155 if ($address_postcode != '')
1156 {
1157 if ($return != '') { $return .= $separator; }
1158 $return .= $address_postcode;
1159 }
1160
1161 if ( $return == '' )
1162 {
1163 $return = $this->post_title;
1164 }
1165
1166 return $return;
1167 }
1168
1169 public function get_office_name()
1170 {
1171 return get_the_title( $this->_office_id );
1172 }
1173
1174 public function get_office_address( $separator = ', ' )
1175 {
1176 $return = '';
1177
1178 for ( $i = 1; $i <= 4; ++$i )
1179 {
1180 $address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE );
1181 if ($address != '')
1182 {
1183 if ($return != '') { $return .= $separator; }
1184 $return .= $address;
1185 }
1186 }
1187 $address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE );
1188 if ($address != '')
1189 {
1190 if ($return != '') { $return .= $separator; }
1191 $return .= $address;
1192 }
1193
1194 return $return;
1195 }
1196
1197 public function get_office_telephone_number()
1198 {
1199 return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1200 }
1201
1202 public function get_office_email_address()
1203 {
1204 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1205 }
1206
1207 /**
1208 * Returns boolean whether the property is featured or not
1209 *
1210 * @access public
1211 * @return string
1212 */
1213 public function is_featured() {
1214
1215 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1216 {
1217 return true;
1218 }
1219
1220 return false;
1221
1222 }
1223
1224 /**
1225 * Adds a note (comment) to the property
1226 *
1227 * @access public
1228 * @param string $note Note to add
1229 * @return id Comment ID
1230 */
1231 public function add_note( $note ) {
1232
1233 if ( is_user_logged_in() )
1234 {
1235 $user = get_user_by( 'id', get_current_user_id() );
1236
1237 $commentdata = array(
1238 'comment_post_ID' => $this->id,
1239 'comment_author' => $user->display_name,
1240 'comment_author_email' => $user->user_email,
1241 'comment_author_url' => '',
1242 'comment_content' => $note,
1243 'comment_type' => 'propertyhive_note',
1244 'comment_parent' => 0,
1245 'user_id' => $user->ID,
1246 'comment_agent' => 'PropertyHive',
1247 'comment_date' => current_time('mysql'),
1248 'comment_approved' => 1,
1249 );
1250
1251 $comment_id = wp_insert_comment( $commentdata );
1252
1253 return $comment_id;
1254 }
1255 }
1256
1257
1258
1259
1260 }
1261