PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
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-viewing.php

class-ph-viewing.php in Property Hive 1.4.53, at includes/class-ph-viewing.php

97 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' ) ) exit; // Exit if accessed directly
4
5 /**
6 * Viewing
7 *
8 * The Property Hive viewing class handles viewing data.
9 *
10 * @class PH_Viewing
11 * @version 1.0.0
12 * @package PropertyHive/Classes
13 * @category Class
14 * @author PropertyHive
15 */
16 class PH_Viewing {
17
18 /** @public int Viewing (post) ID */
19 public $id;
20
21 /**
22 * Get the viewing if ID is passed, otherwise the viewing is new and empty.
23 *
24 * @access public
25 * @param string $id (default: '')
26 * @return void
27 */
28 public function __construct( $id = '' ) {
29 if ( $id > 0 ) {
30 $this->get_viewing( $id );
31 }
32 }
33
34 /**
35 * Gets a viewing from the database.
36 *
37 * @access public
38 * @param int $id (default: 0)
39 * @return bool
40 */
41 public function get_viewing( $id = 0 ) {
42 if ( ! $id ) {
43 return false;
44 }
45 if ( $result = get_post( $id ) ) {
46 $this->populate( $result );
47 return true;
48 }
49 return false;
50 }
51
52 /**
53 * __isset function.
54 *
55 * @access public
56 * @param mixed $key
57 * @return bool
58 */
59 public function __isset( $key ) {
60 if ( ! $this->id ) {
61 return false;
62 }
63 return metadata_exists( 'post', $this->id, '_' . $key );
64 }
65
66 /**
67 * __get function.
68 *
69 * @access public
70 * @param mixed $key
71 * @return mixed
72 */
73 public function __get( $key ) {
74 // Get values or default if not set
75 $value = get_post_meta( $this->id, $key, true );
76 if ($value == '')
77 {
78 $value = get_post_meta( $this->id, '_' . $key, true );
79 }
80 return $value;
81 }
82
83 /**
84 * Populates a viewing from the loaded post data.
85 *
86 * @access public
87 * @param mixed $result
88 * @return void
89 */
90 public function populate( $result ) {
91 // Standard post data
92 $this->id = $result->ID;
93 $this->post_title = $result->post_title;
94 $this->post_status = $result->post_status;
95 }
96 }
97