| @@ -12,12 +12,15 @@ | ||
| 12 | 12 | * @package PropertyHive/Classes |
| 13 | 13 | * @category Class |
| 14 | 14 | * @author PropertyHive |
| 15 | 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. | |
| 16 | 17 | class PH_Enquiry { |
| 17 | 18 | |
| 18 | 19 | /** @public int Enquiry (post) ID */ |
| 19 | 20 | public $id; |
| 21 | + public $post_title; | |
| 22 | + public $post_status; | |
| 20 | 23 | |
| 21 | 24 | /** |
| 22 | 25 | * Get the enquiry if ID is passed, otherwise the enquiry is new and empty. |
| 23 | 26 | * |
| @@ -91,6 +94,117 @@ | ||
| 91 | 94 | // Standard post data |
| 92 | 95 | $this->id = $result->ID; |
| 93 | 96 | $this->post_title = $result->post_title; |
| 94 | 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 ); | |
| 95 | 209 | } |
| 96 | 210 | } |