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

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

211 lines 5.3 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 * Enquiry
7 *
8 * The PropertyHive enquiry class handles enquiry data.
9 *
10 * @class PH_Property
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_Enquiry; preserving the existing PH_* class name is required for plugin and extension compatibility.
17 class PH_Enquiry {
18
19 /** @public int Enquiry (post) ID */
20 public $id;
21 public $post_title;
22 public $post_status;
23
24 /**
25 * Get the enquiry if ID is passed, otherwise the enquiry is new and empty.
26 *
27 * @access public
28 * @param string $id (default: '')
29 * @return void
30 */
31 public function __construct( $id = '' ) {
32 if ( $id > 0 ) {
33 $this->get_enquiry( $id );
34 }
35 }
36
37 /**
38 * Gets a enquiry from the database.
39 *
40 * @access public
41 * @param int $id (default: 0)
42 * @return bool
43 */
44 public function get_enquiry( $id = 0 ) {
45 if ( ! $id ) {
46 return false;
47 }
48 if ( $result = get_post( $id ) ) {
49 $this->populate( $result );
50 return true;
51 }
52 return false;
53 }
54
55 /**
56 * __isset function.
57 *
58 * @access public
59 * @param mixed $key
60 * @return bool
61 */
62 public function __isset( $key ) {
63 if ( ! $this->id ) {
64 return false;
65 }
66 return metadata_exists( 'post', $this->id, '_' . $key );
67 }
68
69 /**
70 * __get function.
71 *
72 * @access public
73 * @param mixed $key
74 * @return mixed
75 */
76 public function __get( $key ) {
77 // Get values or default if not set
78 $value = get_post_meta( $this->id, $key, true );
79 if ($value == '')
80 {
81 $value = get_post_meta( $this->id, '_' . $key, true );
82 }
83 return $value;
84 }
85
86 /**
87 * Populates a enquiry from the loaded post data.
88 *
89 * @access public
90 * @param mixed $result
91 * @return void
92 */
93 public function populate( $result ) {
94 // Standard post data
95 $this->id = $result->ID;
96 $this->post_title = $result->post_title;
97 $this->post_status = $result->post_status;
98 }
99
100 /**
101 * Get the assigned negotiator
102 *
103 * @access public
104 * @return string
105 */
106 public function get_negotiator()
107 {
108 if ($this->_negotiator_id == '' || $this->_negotiator_id == 0)
109 {
110 return '<em>-- ' . __( 'Unassigned', 'propertyhive' ) . ' --</em>';
111 }
112 else
113 {
114 $userdata = get_userdata( $this->_negotiator_id );
115 if ( $userdata !== FALSE )
116 {
117 return $userdata->display_name;
118 }
119 else
120 {
121 return '<em>' . __( 'Unknown user', 'propertyhive' ) . '</em>';
122 }
123 }
124 }
125
126 /**
127 * Get the assigned office
128 *
129 * @access public
130 * @return string
131 */
132 public function get_office()
133 {
134 if ($this->_office_id == '' || $this->_office_id == 0)
135 {
136 return '<em>-- ' . __( 'Unassigned', 'propertyhive' ) . ' --</em>';
137 }
138 else
139 {
140 return get_the_title( $this->_office_id );
141 }
142 }
143
144 /**
145 * Get the associated properties
146 *
147 * @access public
148 * @return array
149 */
150 public function get_properties()
151 {
152 $property_ids = array_filter( get_post_meta($this->id, 'property_id') );
153 if ( count($property_ids) > 0 )
154 {
155 return $property_ids;
156 }
157 else
158 {
159 return array_filter( get_post_meta($this->id, '_property_id') );
160 }
161 }
162
163 /**
164 * Get the text for use in the Properties column of the enquiry list
165 *
166 * @access public
167 * @return array
168 */
169 public function get_list_property_display_text( $property_id )
170 {
171 $property = new PH_Property((int)$property_id);
172
173 if ( !isset($property->id) || empty($property->id) )
174 {
175 return __( 'Property not found', 'propertyhive' );
176 }
177
178 $display_parts = array();
179
180 $display_parts[] = '<a href="' . esc_url(get_edit_post_link( $property_id )) . '">' . $property->get_formatted_full_address() . '</a>';
181
182 $display_parts[] = $property->get_formatted_price();
183
184 $property_status = '';
185
186 $term_list = wp_get_post_terms($property_id, 'availability', array("fields" => "names"));
187
188 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
189 {
190 $property_status = $term_list[0] . ' - ';
191 }
192
193 if (isset($property->_on_market) && $property->_on_market == 'yes')
194 {
195 $property_status .= __( 'On The Market', 'propertyhive' );
196 }
197 else
198 {
199 $property_status .= __( 'Not On The Market', 'propertyhive' );
200 }
201
202 $display_parts[] = $property_status;
203
204 $display_parts = array_filter($display_parts);
205
206 $display_parts = apply_filters( 'propertyhive_enquiry_list_property_display_parts', $display_parts, $property_id );
207
208 return implode( '<br>', $display_parts );
209 }
210 }
211