PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
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.5, at includes/class-ph-property.php

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