1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class BKAP_Product_Resource {
private $resource;
private $product_id;
private $id;
public function __construct( $post , $product_id = 0 ) {
if ( is_numeric( $post ) ) {
$this->resource = get_post( $post );
$this->id = $post;
} else {
$this->resource = $post;
}
$this->product_id = $product_id;
}
public function get_id() {
return $this->resource->ID;
}
public function set_id( $id ) {
$this->resource->ID = $id;
}
public function get_title() {
return $this->resource->post_title;
}
public function has_qty() {
return $this->get_qty() !== '';
}
public function get_qty() {
return get_post_meta( $this->get_id(), 'qty', true );
}
public function get_base_cost() {
$costs = get_post_meta( $this->product_id, '_bkap_resource_base_costs', true );
$cost = isset( $costs[ $this->get_id() ] ) ? $costs[ $this->get_id() ] : '';
return (float) $cost;
}
public function get_block_cost() {
$costs = get_post_meta( $this->product_id, '_resource_block_costs', true );
$cost = isset( $costs[ $this->get_id() ] ) ? $costs[ $this->get_id() ] : '';
return (float) $cost;
}
public function get_resource_availability() {
$bkap_resource_availability = get_post_meta( $this->get_id(), '_bkap_resource_availability', true );
return $bkap_resource_availability;
}
public function get_resource_qty() {
$bkap_resource_qty = get_post_meta( $this->get_id(), '_bkap_resource_qty', true );
return $bkap_resource_qty;
}
public static function bkap_create_resource( $add_resource_name ) {
$id = wp_insert_post( array(
'post_title' => $add_resource_name,
'menu_order' => 0,
'post_content' => '',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'bkap_resource',
), true );
if ( $id && ! is_wp_error( $id ) ) {
update_post_meta( $id, '_bkap_resource_qty', 1 );
update_post_meta( $id, '_bkap_resource_availability', array() );
return $id;
}
}
}