# propertyhive/1.4.49/includes/class-ph-viewing.php

Property Hive, version 1.4.49. 97 lines.

- Page: https://pluginprobe.com/plugins/propertyhive/1.4.49/code/includes/class-ph-viewing.php
- Raw: https://pluginprobe.com/plugins/propertyhive/1.4.49/raw/includes/class-ph-viewing.php
- Modified: 2017-01-09T16:28:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/propertyhive/1.4.49/code/includes/class-ph-viewing.php#L10-L20`.

```php
<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Viewing
 *
 * The Property Hive viewing class handles viewing data.
 *
 * @class       PH_Viewing
 * @version     1.0.0
 * @package     PropertyHive/Classes
 * @category    Class
 * @author      PropertyHive
 */
class PH_Viewing {

    /** @public int Viewing (post) ID */
    public $id;

    /**
     * Get the viewing if ID is passed, otherwise the viewing is new and empty.
     *
     * @access public
     * @param string $id (default: '')
     * @return void
     */
    public function __construct( $id = '' ) {
        if ( $id > 0 ) {
            $this->get_viewing( $id );
        }
    }

    /**
     * Gets a viewing from the database.
     *
     * @access public
     * @param int $id (default: 0)
     * @return bool
     */
    public function get_viewing( $id = 0 ) {
        if ( ! $id ) {
            return false;
        }
        if ( $result = get_post( $id ) ) {
            $this->populate( $result );
            return true;
        }
        return false;
    }
    
    /**
     * __isset function.
     *
     * @access public
     * @param mixed $key
     * @return bool
     */
    public function __isset( $key ) {
        if ( ! $this->id ) {
            return false;
        }
        return metadata_exists( 'post', $this->id, '_' . $key );
    }

    /**
     * __get function.
     *
     * @access public
     * @param mixed $key
     * @return mixed
     */
    public function __get( $key ) {
        // Get values or default if not set
        $value = get_post_meta( $this->id, $key, true );
        if ($value == '')
        {
            $value = get_post_meta( $this->id, '_' . $key, true );
        }
        return $value;
    }
    
    /**
     * Populates a viewing from the loaded post data.
     *
     * @access public
     * @param mixed $result
     * @return void
     */
    public function populate( $result ) {
        // Standard post data
        $this->id                  = $result->ID;
        $this->post_title          = $result->post_title;
        $this->post_status         = $result->post_status;
    }
}

```
