PluginProbe
Property Hive / trunk
Property Hive vtrunk
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-key-date.php

class-ph-key-date.php in Property Hive trunk, at includes/class-ph-key-date.php

101 lines 2.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' ) )
4 {
5 // Exit if accessed directly
6 exit;
7 }
8
9 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Key_Date; preserving the existing PH_* class name is required for plugin and extension compatibility.
10 class PH_Key_Date {
11
12 /** @var int */
13 public $id;
14
15 /** @var string */
16 private $description;
17
18 public function __construct( WP_Post $post ) {
19 $this->id = $post->ID;
20 $this->description = $post->post_title;
21 }
22
23 public function description() {
24 return $this->description;
25 }
26
27 public function notes() {
28 return $this->_key_date_notes;
29 }
30
31 public function property() {
32 return new PH_Property(get_post($this->_property_id));
33 }
34
35 public function tenancy() {
36 return new PH_Tenancy($this->_tenancy_id);
37 }
38
39 public function date_due() {
40 return new DateTime($this->_date_due);
41 }
42
43 public function key_date_type_id() {
44 return $this->_key_date_type_id;
45 }
46
47 public function status() {
48
49 switch ($this->_key_date_status)
50 {
51 case 'pending':
52
53 $overdue_threshold = ( date_format($this->date_due(), 'H:i') == '00:00' ) ? 'Today' : 'Now';
54 switch(true)
55 {
56 case $this->date_due() < new DateTime($overdue_threshold):
57 return 'overdue';
58 case $this->date_due() <= new DateTime('+ ' . apply_filters( 'propertyhive_key_date_upcoming_days', 7 ) . ' DAYS'):
59 return 'upcoming';
60 default:
61 return 'pending';
62 }
63 case 'booked':
64 case 'complete':
65 default:
66 return $this->_key_date_status;
67 }
68 }
69
70 /**
71 * __isset function.
72 *
73 * @access public
74 * @param mixed $key
75 * @return bool
76 */
77 public function __isset( $key ) {
78 if ( ! $this->id ) {
79 return false;
80 }
81 return metadata_exists( 'post', $this->id, '_' . $key );
82 }
83
84 /**
85 * __get function.
86 *
87 * @access public
88 * @param mixed $key
89 * @return mixed
90 */
91 public function __get( $key ) {
92 // Get values or default if not set
93 $value = get_post_meta( $this->id, $key, true );
94 if ($value == '')
95 {
96 $value = get_post_meta( $this->id, '_' . $key, true );
97 }
98 return $value;
99 }
100 }
101