PluginProbe
Property Hive / 2.2.5
Property Hive v2.2.5
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.2.5, at includes/class-ph-enquiry.php

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