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