PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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-appraisal.php

class-ph-appraisal.php in Property Hive 2.2.4, at includes/class-ph-appraisal.php

325 lines 8.6 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 * 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 $ph_countries = new PH_Countries();
170
171 $currency = 'GBP';
172
173 $default_country = get_option( 'propertyhive_default_country', 'GB' );
174 $countries = get_option( 'propertyhive_countries', array( $default_country ) );
175 if ( count($countries) == 1 )
176 {
177 foreach ( $countries as $country )
178 {
179 $country = $ph_countries->get_country( $country );
180
181 $currency = $country['currency_code'];
182 }
183 }
184
185 $currency = $ph_countries->get_currency( $currency );
186
187 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
188 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
189
190 switch ($this->_department)
191 {
192 case "residential-sales":
193 {
194 $price = $this->_valued_price;
195
196 return ( ( $price != '' ) ? $prefix . ph_display_price_field($price) . $suffix : '-' );
197 break;
198 }
199 case "residential-lettings":
200 {
201 $price = $this->_valued_rent;
202 if ( $price != '' )
203 {
204 switch ( $this->_valued_rent_frequency )
205 {
206 case "pd": { $price = ($price * 365) / 52; break; }
207 case "pw": { $price = ($price * 12) / 52; break; }
208 case "pq": { $price = ($price * 12) / 4; break; }
209 case "pa": { $price = ($price * 12); break; }
210 }
211 }
212
213 return ( ( $price != '' ) ? $prefix . ph_display_price_field($price) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
214 break;
215 }
216 }
217
218 return '';
219 }
220
221 /**
222 * Get the summary formatted address
223 *
224 * @access public
225 * @return string
226 */
227 public function get_formatted_summary_address( $separator = ', ' ) {
228 // Standard post data
229
230 $return = '';
231
232 $address_name_number = $this->_address_name_number;
233 if ($address_name_number != '')
234 {
235 $return .= $address_name_number;
236 }
237 $address_street = $this->_address_street;
238 if ($address_street != '')
239 {
240 if ($return != '') { $return .= ' '; }
241 $return .= $address_street;
242 }
243 $address_two = $this->_address_two;
244 $address_three = $this->_address_three;
245 $address_four = $this->_address_four;
246 if ($address_two != '')
247 {
248 if ($return != '') { $return .= $separator; }
249 $return .= $address_two;
250 }
251 elseif ($address_three != '')
252 {
253 if ($return != '') { $return .= $separator; }
254 $return .= $address_three;
255 }
256 elseif ($address_four != '')
257 {
258 if ($return != '') { $return .= $separator; }
259 $return .= $address_four;
260 }
261 $address_postcode = $this->_address_postcode;
262 if ($address_postcode != '')
263 {
264 if ($return != '') { $return .= $separator; }
265 $return .= $address_postcode;
266 }
267
268 return $return;
269 }
270
271 /**
272 * Get the property type taxononmy
273 *
274 * @access public
275 * @return string
276 */
277 public function get_property_type()
278 {
279 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
280
281 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
282 {
283 return implode(", ", $term_list);
284 }
285
286 return '';
287 }
288
289 /**
290 * Get the parking taxononmy
291 *
292 * @access public
293 * @return string
294 */
295 public function get_parking()
296 {
297 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
298
299 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
300 {
301 return implode(", ", $term_list);
302 }
303
304 return '';
305 }
306
307 /**
308 * Get the outside space taxononmy
309 *
310 * @access public
311 * @return string
312 */
313 public function get_outside_space()
314 {
315 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
316
317 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
318 {
319 return implode(", ", $term_list);
320 }
321
322 return '';
323 }
324 }
325