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-tenancy.php

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

202 lines 5.8 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 * Tenancy
7 *
8 * The Property Hive tenancy class handles tenancy data.
9 *
10 * @class PH_Tenancy
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_Tenancy; preserving the existing PH_* class name is required for plugin and extension compatibility.
17 class PH_Tenancy {
18
19 /** @public int Tenancy (post) ID */
20 public $id;
21
22 /**
23 * Get the tenancy if ID is passed, otherwise the tenancy 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_tenancy( $id );
32 }
33 }
34
35 /**
36 * Gets a tenancy from the database.
37 *
38 * @access public
39 * @param int $id (default: 0)
40 * @return bool
41 */
42 public function get_tenancy( $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 tenancy 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 tenancy rent
100 *
101 * @access public
102 * @return string
103 */
104 public function get_formatted_rent( ) {
105
106 $ph_countries = new PH_Countries();
107
108 if ($this->_currency != '')
109 {
110 $currency = $ph_countries->get_currency( $this->_currency );
111 }
112 else
113 {
114 $currency = $ph_countries->get_currency( 'GBP' );
115 }
116
117 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
118 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
119
120 $amount = $this->_rent;
121
122 return ( ( $amount != '' ) ? $prefix . ph_display_price_field($amount) : '-' ) . $suffix . ' ' . propertyhive_get_rent_frequency_label( $this->_rent_frequency );
123
124 }
125
126 /**
127 * Get the tenancy status
128 *
129 * @access public
130 * @return string
131 */
132 public function get_status()
133 {
134 if ( $this->_start_date && strtotime( $this->_start_date ) > time() )
135 {
136 return __( 'Pending', 'propertyhive' );
137 }
138 elseif (
139 $this->_start_date && strtotime( $this->_start_date ) <= time() &&
140 ( time() <= strtotime( $this->_end_date ) || $this->_end_date == '' )
141 )
142 {
143 return __( 'Current', 'propertyhive' );
144 }
145 elseif ( $this->_end_date && strtotime( $this->_end_date ) < time() )
146 {
147 return __( 'Finished', 'propertyhive' );
148 }
149 }
150
151 /**
152 * Get a list of tenants on the property
153 *
154 * @access public
155 * @param bool $add hyperlinks
156 * @return string
157 */
158 public function get_tenants( $add_hyperlinks = false, $additional_contact_details = false )
159 {
160 $applicant_contact_ids = get_post_meta( $this->id, '_applicant_contact_id' );
161 if ( is_array($applicant_contact_ids) && !empty($applicant_contact_ids) )
162 {
163 $applicants = array();
164 foreach ( $applicant_contact_ids as $applicant_contact_id )
165 {
166 $applicant_name = esc_html( get_the_title( $applicant_contact_id ) );
167 if ( $add_hyperlinks )
168 {
169 $edit_link = get_edit_post_link( $applicant_contact_id );
170 $applicant_name = '<a href="' . esc_url( $edit_link ) . '">' . $applicant_name . '</a>';
171 }
172 if ( $additional_contact_details )
173 {
174 $contact_details = array();
175 $telephone_number = get_post_meta( $applicant_contact_id, '_telephone_number', true );
176 if( !empty($telephone_number) )
177 {
178 $contact_details[] = 'T: ' . esc_html( $telephone_number );
179 }
180
181 $email_address = get_post_meta( $applicant_contact_id, '_email_address', true );
182 if( !empty($email_address) )
183 {
184 $contact_details[] = 'E: ' . esc_html( $email_address );
185 }
186
187 if ( !empty($contact_details) )
188 {
189 $applicant_name .= '<div class="row-actions visible">' . implode( "<br>", $contact_details ) . '</div>';
190 }
191 }
192 $applicants[] = $applicant_name;
193 }
194 return implode("<br>", $applicants);
195 }
196 else
197 {
198 return '-';
199 }
200 }
201 }
202