PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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-offer.php

class-ph-offer.php in Property Hive 2.3.0, at includes/class-ph-offer.php

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