| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
/** |
| 6 |
* Appraisal |
| 7 |
* |
| 8 |
* The Property Hive appraisal class handles appraisal data. |
| 9 |
* |
| 10 |
* @class PH_Appraisal |
| 11 |
* @version 1.0.0 |
| 12 |
* @package PropertyHive/Classes |
| 13 |
* @category Class |
| 14 |
* @author PropertyHive |
| 15 |
*/ |
| 16 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Appraisal; preserving the existing PH_* class name is required for plugin and extension compatibility. |
| 17 |
class PH_Appraisal { |
| 18 |
|
| 19 |
/** @public int Appraisal (post) ID */ |
| 20 |
public $id; |
| 21 |
|
| 22 |
/** |
| 23 |
* Get the appraisal if ID is passed, otherwise the appraisal is new and empty. |
| 24 |
* |
| 25 |
* @access public |
| 26 |
* @param string $id (default: '') |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public function __construct( $id = '' ) { |
| 30 |
if ( $id > 0 ) { |
| 31 |
$this->get_appraisal( $id ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Gets a appraisal from the database. |
| 37 |
* |
| 38 |
* @access public |
| 39 |
* @param int $id (default: 0) |
| 40 |
* @return bool |
| 41 |
*/ |
| 42 |
public function get_appraisal( $id = 0 ) { |
| 43 |
if ( ! $id ) { |
| 44 |
return false; |
| 45 |
} |
| 46 |
if ( $result = get_post( $id ) ) { |
| 47 |
$this->populate( $result ); |
| 48 |
return true; |
| 49 |
} |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* __isset function. |
| 55 |
* |
| 56 |
* @access public |
| 57 |
* @param mixed $key |
| 58 |
* @return bool |
| 59 |
*/ |
| 60 |
public function __isset( $key ) { |
| 61 |
if ( ! $this->id ) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
return metadata_exists( 'post', $this->id, '_' . $key ); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* __get function. |
| 69 |
* |
| 70 |
* @access public |
| 71 |
* @param mixed $key |
| 72 |
* @return mixed |
| 73 |
*/ |
| 74 |
public function __get( $key ) { |
| 75 |
|
| 76 |
if ( 'property_type' == $key ) |
| 77 |
{ |
| 78 |
return $this->get_property_type(); |
| 79 |
} |
| 80 |
if ( 'parking' == $key ) |
| 81 |
{ |
| 82 |
return $this->get_parking(); |
| 83 |
} |
| 84 |
if ( 'outside_space' == $key ) |
| 85 |
{ |
| 86 |
return $this->get_outside_space(); |
| 87 |
} |
| 88 |
|
| 89 |
// Get values or default if not set |
| 90 |
$value = get_post_meta( $this->id, $key, true ); |
| 91 |
if ($value == '') |
| 92 |
{ |
| 93 |
$value = get_post_meta( $this->id, '_' . $key, true ); |
| 94 |
} |
| 95 |
return $value; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Populates a viewing from the loaded post data. |
| 100 |
* |
| 101 |
* @access public |
| 102 |
* @param mixed $result |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
public function populate( $result ) { |
| 106 |
// Standard post data |
| 107 |
$this->id = $result->ID; |
| 108 |
$this->post_title = $result->post_title; |
| 109 |
$this->post_status = $result->post_status; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Get the full formatted address |
| 114 |
* |
| 115 |
* @access public |
| 116 |
* @return string |
| 117 |
*/ |
| 118 |
public function get_formatted_full_address( $separator = ', ' ) { |
| 119 |
// Standard post data |
| 120 |
|
| 121 |
$return = ''; |
| 122 |
|
| 123 |
$address_name_number = $this->_address_name_number; |
| 124 |
if ($address_name_number != '') |
| 125 |
{ |
| 126 |
$return .= $address_name_number; |
| 127 |
} |
| 128 |
$address_street = $this->_address_street; |
| 129 |
if ($address_street != '') |
| 130 |
{ |
| 131 |
if ($return != '') { $return .= ' '; } |
| 132 |
$return .= $address_street; |
| 133 |
} |
| 134 |
$address_two = $this->_address_two; |
| 135 |
if ($address_two != '') |
| 136 |
{ |
| 137 |
if ($return != '') { $return .= $separator; } |
| 138 |
$return .= $address_two; |
| 139 |
} |
| 140 |
$address_three = $this->_address_three; |
| 141 |
if ($address_three != '') |
| 142 |
{ |
| 143 |
if ($return != '') { $return .= $separator; } |
| 144 |
$return .= $address_three; |
| 145 |
} |
| 146 |
$address_four = $this->_address_four; |
| 147 |
if ($address_four != '') |
| 148 |
{ |
| 149 |
if ($return != '') { $return .= $separator; } |
| 150 |
$return .= $address_four; |
| 151 |
} |
| 152 |
$address_postcode = $this->_address_postcode; |
| 153 |
if ($address_postcode != '') |
| 154 |
{ |
| 155 |
if ($return != '') { $return .= $separator; } |
| 156 |
$return .= $address_postcode; |
| 157 |
} |
| 158 |
|
| 159 |
return $return; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Get the formatted price based on department |
| 164 |
* |
| 165 |
* @access public |
| 166 |
* @return string |
| 167 |
*/ |
| 168 |
public function get_formatted_price( ) { |
| 169 |
|
| 170 |
$ph_countries = new PH_Countries(); |
| 171 |
|
| 172 |
$currency = 'GBP'; |
| 173 |
|
| 174 |
$default_country = get_option( 'propertyhive_default_country', 'GB' ); |
| 175 |
$countries = get_option( 'propertyhive_countries', array( $default_country ) ); |
| 176 |
if ( count($countries) == 1 ) |
| 177 |
{ |
| 178 |
foreach ( $countries as $country ) |
| 179 |
{ |
| 180 |
$country = $ph_countries->get_country( $country ); |
| 181 |
|
| 182 |
$currency = $country['currency_code']; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
$currency = $ph_countries->get_currency( $currency ); |
| 187 |
|
| 188 |
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 189 |
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' ); |
| 190 |
|
| 191 |
switch ($this->_department) |
| 192 |
{ |
| 193 |
case "residential-sales": |
| 194 |
{ |
| 195 |
$price = $this->_valued_price; |
| 196 |
|
| 197 |
return ( ( $price != '' ) ? $prefix . ph_display_price_field($price) . $suffix : '-' ); |
| 198 |
break; |
| 199 |
} |
| 200 |
case "residential-lettings": |
| 201 |
{ |
| 202 |
$price = $this->_valued_rent; |
| 203 |
if ( $price != '' ) |
| 204 |
{ |
| 205 |
switch ( $this->_valued_rent_frequency ) |
| 206 |
{ |
| 207 |
case "pd": { $price = ($price * 365) / 52; break; } |
| 208 |
case "pw": { $price = ($price * 12) / 52; break; } |
| 209 |
case "pq": { $price = ($price * 12) / 4; break; } |
| 210 |
case "pa": { $price = ($price * 12); break; } |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
return ( ( $price != '' ) ? $prefix . ph_display_price_field($price) . $suffix . ' ' . propertyhive_get_rent_frequency_label( $this->_rent_frequency ) : '-' ); |
| 215 |
break; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
return ''; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Get the summary formatted address |
| 224 |
* |
| 225 |
* @access public |
| 226 |
* @return string |
| 227 |
*/ |
| 228 |
public function get_formatted_summary_address( $separator = ', ' ) { |
| 229 |
// Standard post data |
| 230 |
|
| 231 |
$return = ''; |
| 232 |
|
| 233 |
$address_name_number = $this->_address_name_number; |
| 234 |
if ($address_name_number != '') |
| 235 |
{ |
| 236 |
$return .= $address_name_number; |
| 237 |
} |
| 238 |
$address_street = $this->_address_street; |
| 239 |
if ($address_street != '') |
| 240 |
{ |
| 241 |
if ($return != '') { $return .= ' '; } |
| 242 |
$return .= $address_street; |
| 243 |
} |
| 244 |
$address_two = $this->_address_two; |
| 245 |
$address_three = $this->_address_three; |
| 246 |
$address_four = $this->_address_four; |
| 247 |
if ($address_two != '') |
| 248 |
{ |
| 249 |
if ($return != '') { $return .= $separator; } |
| 250 |
$return .= $address_two; |
| 251 |
} |
| 252 |
elseif ($address_three != '') |
| 253 |
{ |
| 254 |
if ($return != '') { $return .= $separator; } |
| 255 |
$return .= $address_three; |
| 256 |
} |
| 257 |
elseif ($address_four != '') |
| 258 |
{ |
| 259 |
if ($return != '') { $return .= $separator; } |
| 260 |
$return .= $address_four; |
| 261 |
} |
| 262 |
$address_postcode = $this->_address_postcode; |
| 263 |
if ($address_postcode != '') |
| 264 |
{ |
| 265 |
if ($return != '') { $return .= $separator; } |
| 266 |
$return .= $address_postcode; |
| 267 |
} |
| 268 |
|
| 269 |
return $return; |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Get the property type taxononmy |
| 274 |
* |
| 275 |
* @access public |
| 276 |
* @return string |
| 277 |
*/ |
| 278 |
public function get_property_type() |
| 279 |
{ |
| 280 |
$term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names")); |
| 281 |
|
| 282 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 283 |
{ |
| 284 |
return implode(", ", $term_list); |
| 285 |
} |
| 286 |
|
| 287 |
return ''; |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Get the parking taxononmy |
| 292 |
* |
| 293 |
* @access public |
| 294 |
* @return string |
| 295 |
*/ |
| 296 |
public function get_parking() |
| 297 |
{ |
| 298 |
$term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names")); |
| 299 |
|
| 300 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 301 |
{ |
| 302 |
return implode(", ", $term_list); |
| 303 |
} |
| 304 |
|
| 305 |
return ''; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Get the outside space taxononmy |
| 310 |
* |
| 311 |
* @access public |
| 312 |
* @return string |
| 313 |
*/ |
| 314 |
public function get_outside_space() |
| 315 |
{ |
| 316 |
$term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names")); |
| 317 |
|
| 318 |
if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) ) |
| 319 |
{ |
| 320 |
return implode(", ", $term_list); |
| 321 |
} |
| 322 |
|
| 323 |
return ''; |
| 324 |
} |
| 325 |
} |
| 326 |
|