PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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 1.4.62 All 260 releases
propertyhive / includes / class-ph-sale.php

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

261 lines 7.5 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 * Sale
7 *
8 * The Property Hive sale class handles sale data.
9 *
10 * @class PH_Sale
11 * @version 1.0.0
12 * @package PropertyHive/Classes
13 * @category Class
14 * @author PropertyHive
15 */
16 class PH_Sale {
17
18 /** @public int Sale (post) ID */
19 public $id;
20
21 /**
22 * Get the sale if ID is passed, otherwise the sale 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_sale( $id );
31 }
32 }
33
34 /**
35 * Gets a sale from the database.
36 *
37 * @access public
38 * @param int $id (default: 0)
39 * @return bool
40 */
41 public function get_sale( $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 // Get values or default if not set
75 $value = get_post_meta( $this->id, $key, true );
76 if ($value == '')
77 {
78 $value = get_post_meta( $this->id, '_' . $key, true );
79 }
80 return $value;
81 }
82
83 /**
84 * Populates a sale from the loaded post data.
85 *
86 * @access public
87 * @param mixed $result
88 * @return void
89 */
90 public function populate( $result ) {
91 // Standard post data
92 $this->id = $result->ID;
93 $this->post_title = $result->post_title;
94 $this->post_status = $result->post_status;
95 }
96
97 /**
98 * Get the formatted sale amount
99 *
100 * @access public
101 * @return string
102 */
103 public function get_formatted_amount( ) {
104
105 $amount = $this->_amount;
106 $prefix = '&pound;';
107 return ( ( $amount != '' ) ? $prefix . ph_display_price_field($amount) : '-' );
108
109 }
110
111 /**
112 * Get a list of applicants on the sale
113 *
114 * @access public
115 * @param bool $add_hyperlinks
116 * @param bool $additional_contact_details
117 * @param bool $contact_details_visible
118 * @return array
119 */
120 public function get_applicants( $add_hyperlinks = false, $additional_contact_details = false, $contact_details_visible = true )
121 {
122 $applicant_contact_ids = get_post_meta( $this->id, '_applicant_contact_id' );
123 if ( is_array($applicant_contact_ids) && !empty($applicant_contact_ids) )
124 {
125 $applicants = array();
126 foreach ( $applicant_contact_ids as $applicant_contact_id )
127 {
128 $applicant_name = get_the_title($applicant_contact_id);
129 if ( $add_hyperlinks )
130 {
131 $edit_link = get_edit_post_link( $applicant_contact_id );
132 $applicant_name = '<a href="' . esc_url( $edit_link ) . '">' . $applicant_name . '</a>';
133 }
134 if ( $additional_contact_details )
135 {
136 $contact_details = array();
137 $telephone_number = get_post_meta( $applicant_contact_id, '_telephone_number', true );
138 if( !empty($telephone_number) )
139 {
140 $contact_details[] = 'T: ' . $telephone_number;
141 }
142
143 $email_address = get_post_meta( $applicant_contact_id, '_email_address', true );
144 if( !empty($email_address) )
145 {
146 $contact_details[] = 'E: ' . $email_address;
147 }
148
149 $contact_details = apply_filters( 'propertyhive_sale_applicant_contact_details', $contact_details, $applicant_contact_id );
150
151 if ( !empty($contact_details) )
152 {
153 $applicant_name .= '<div class="row-actions' . ($contact_details_visible ? ' visible' : '') . '">' . implode( "<br>", $contact_details ) . '</div>';
154 }
155 }
156 $applicants[] = $applicant_name;
157 }
158 return implode("<br>", $applicants);
159 }
160 else
161 {
162 return '-';
163 }
164 }
165
166 /**
167 * Get the full address of the property attached to the sale
168 *
169 * @access public
170 * @return string
171 */
172 public function get_property_address()
173 {
174 $property_id = (int)$this->_property_id;
175
176 if ( !empty($property_id) )
177 {
178 $property = new PH_Property( $property_id );
179 return '<a href="' . get_edit_post_link( $property_id, '' ) . '" target="' . apply_filters('propertyhive_subgrid_link_target', '') . '">' . $property->get_formatted_full_address() . '</a>';
180 }
181 else
182 {
183 return '-';
184 }
185 }
186
187 /**
188 * Get the contact details of the owner(s) of the property attached to the sale
189 *
190 * @access public
191 * @return string
192 */
193 public function get_property_owners()
194 {
195 $property_owners = '-';
196
197 $property_id = (int)$this->_property_id;
198
199 if ( !empty($property_id) )
200 {
201 $property = new PH_Property( $property_id );
202 $owner_contact_ids = $property->_owner_contact_id;
203 if (
204 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
205 ||
206 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
207 )
208 {
209 $property_owners = '';
210
211 if ( !is_array($owner_contact_ids) )
212 {
213 $owner_contact_ids = array($owner_contact_ids);
214 }
215
216 foreach ( $owner_contact_ids as $owner_contact_id )
217 {
218 $property_owners .= $this->formatted_contact_meta_box_data($owner_contact_id, false);
219 }
220 }
221 }
222
223 return $property_owners;
224 }
225
226 /**
227 * Format contact data for display in a meta box list
228 */
229 private function formatted_contact_meta_box_data( $contact_post_id, $add_edit_link = true )
230 {
231 if ( $add_edit_link )
232 {
233 $contact_text = '<a href="' . get_edit_post_link( $contact_post_id, '' ) . '" target="' . apply_filters('propertyhive_subgrid_link_target', '') . '">' . get_the_title($contact_post_id) . '</a>';
234 }
235 else
236 {
237 $contact_text = get_the_title($contact_post_id);
238 }
239
240 $telephone_number = get_post_meta( $contact_post_id, '_telephone_number', true );
241 if( !empty($telephone_number) )
242 {
243 $contact_details = 'T: ' . $telephone_number;
244 }
245
246 $email_address = get_post_meta( $contact_post_id, '_email_address', true );
247 if( !empty($email_address) )
248 {
249 $contact_details .= ( $contact_details != '' ) ? '<br>' : '';
250 $contact_details .= 'E: ' . $email_address;
251 }
252
253 if ( $contact_details != '' )
254 {
255 $contact_text .= '<div class="row-actions visible">' . $contact_details . '</div>';
256 }
257
258 return $contact_text;
259 }
260 }
261