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

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

111 lines 2.4 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 * Offer
7 *
8 * The Property Hive offer class handles offer data.
9 *
10 * @class PH_Offer
11 * @version 1.0.0
12 * @package PropertyHive/Classes
13 * @category Class
14 * @author PropertyHive
15 */
16 class PH_Offer {
17
18 /** @public int Offer (post) ID */
19 public $id;
20
21 /**
22 * Get the offer if ID is passed, otherwise the offer 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_offer( $id );
31 }
32 }
33
34 /**
35 * Gets a offer from the database.
36 *
37 * @access public
38 * @param int $id (default: 0)
39 * @return bool
40 */
41 public function get_offer( $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 offer 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 /**
98 * Get the formatted offer amount
99 *
100 * @access public
101 * @return string
102 */
103 public function get_formatted_amount( ) {
104
105 $amount = $this->_amount;
106 $prefix = '&pound;';
107 return ( ( $amount != '' ) ? $prefix . number_format($amount , 0) : '-' );
108
109 }
110 }
111