Sindbad~EG File Manager
<?php
namespace RealPress\Models;
use RealPress\Helpers\Config;
class PropertyMetaModel {
private static $meta_data = array();
protected static $instance = array();
private $property_id;
/**
* @param $property_id
*/
public function __construct( $property_id ) {
$this->property_id = $property_id;
}
/**
* @param $property_id
*
* @return static
*/
public static function instance( $property_id ): self {
if ( ! isset( self::$instance[ $property_id ] ) ) {
self::$instance[ $property_id ] = new PropertyMetaModel( $property_id );
}
return self::$instance[ $property_id ];
}
/**
* @param $property_id
*
* @return mixed
*/
public static function get_meta_data( $property_id ) {
if ( ! isset( self::$meta_data[ $property_id ] ) ) {
$config = Config::instance()->get( 'property-metabox' );
$data = get_post_meta( $property_id, REALPRESS_PROPERTY_META_KEY, true );
if ( empty( $data ) ) {
$data = Config::instance()->get_default_data( $config );
} else {
$default = Config::instance()->get_default_data( $config );
//If key exist in config, not in $data, add key into key into $data
$data = wp_parse_args(
$data,
$default
);
//If key exist in $data, not in config, remove key in $data
$diff_key = array_diff_key( $data, $default );
if ( ! empty( $diff_key ) ) {
foreach ( $diff_key as $key => $value ) {
unset( $data[ $key ] );
}
}
}
self::$meta_data[ $property_id ] = $data;
}
return self::$meta_data[ $property_id ];
}
/**
* @param string $taxonomy
*
* @return array|\WP_Error|\WP_Term[]
*/
public function get_property_terms( string $taxonomy = 'realpress-type', array $args = array() ) {
$terms = wp_get_post_terms( $this->property_id, $taxonomy, $args );
if ( empty( $terms ) || is_wp_error( $terms ) ) {
return array();
}
return $terms;
}
/**
* @return mixed|string
*/
public function get_address_name() {
if ( ! $this->is_enable_map() ) {
return '';
}
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:map:fields:name'];
}
public function get_city() {
if ( ! $this->is_enable_map() ) {
return '';
}
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:map:fields:city'];
}
public function get_state() {
if ( ! $this->is_enable_map() ) {
return '';
}
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:map:fields:state'];
}
public function get_country() {
if ( ! $this->is_enable_map() ) {
return '';
}
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:map:fields:country'];
}
public function get_postcode() {
if ( ! $this->is_enable_map() ) {
return '';
}
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:map:fields:postcode'];
}
/**
* @return array
*/
public function get_lat_lng() {
if ( ! $this->is_enable_map() ) {
return array();
}
$meta_data = self::get_meta_data( $this->property_id );
return array(
'lat' => $meta_data['group:map:section:map:fields:lat'],
'lng' => $meta_data['group:map:section:map:fields:lng'],
);
}
/**
* @return int|mixed
*/
public function get_price() {
$meta_data = self::get_meta_data( $this->property_id );
$price = $meta_data['group:information:section:general:fields:price'];
return empty( $price ) ? 0 : $price;
}
/**
* @return mixed
*/
public function get_text_after_price() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:text_after_price'];
}
/**
* @return mixed
*/
public function get_galleries() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:media:section:gallery:fields:gallery'];
}
/**
* @return mixed
*/
public function get_vr_video() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:media:section:360-vr:fields:360_vr'];
}
/**
* @param $property_id
*
* @return mixed
*/
public function get_video() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:media:section:video:fields:video'];
}
/**
* @return mixed
*/
public function get_property_id() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:property_id'];
}
/**
* @return int|mixed
*/
public function get_bedrooms() {
$meta_data = self::get_meta_data( $this->property_id );
$bedrooms = $meta_data['group:information:section:general:fields:bedrooms'];
return empty( $bedrooms ) ? 0 : $bedrooms;
}
/**
* @return int|mixed
*/
public function get_bathrooms() {
$meta_data = self::get_meta_data( $this->property_id );
$bathrooms = $meta_data['group:information:section:general:fields:bathrooms'];
return empty( $bathrooms ) ? 0 : $bathrooms;
}
/**
* @return int|mixed
*/
public function get_area_size() {
$meta_data = self::get_meta_data( $this->property_id );
$area_size = $meta_data['group:information:section:general:fields:area_size'];
return empty( $area_size ) ? 0 : $area_size;
}
/**
* @return mixed
*/
public function get_area_size_postfix() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:area_size_postfix'];
}
public function get_land_area_size() {
$meta_data = self::get_meta_data( $this->property_id );
$land_area_size = $meta_data['group:information:section:general:fields:land_area_size'];
return empty( $land_area_size ) ? 0 : $land_area_size;
}
/**
* @return mixed
*/
public function get_land_area_size_postfix() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:land_area_size_postfix'];
}
/**
* @return mixed
*/
public function is_verified() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:verified'] === 'on';
}
/**
* @return mixed
*/
public function get_year_built() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:year_built'];
}
/**
* @return mixed
*/
public function get_additional_details() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:additional-features'];
}
/**
* @return mixed
*/
public function get_rooms() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:information:section:general:fields:rooms'];
}
/**
* @return mixed
*/
public function get_floor_plans() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:floor_plan:section:floor_plan'];
}
/**
* @return bool
*/
public function is_enable_map() {
$meta_data = self::get_meta_data( $this->property_id );
return $meta_data['group:map:section:enable_map:fields:enable'] === 'on';
}
/**
* @return array
*/
public function get_agent_info() {
$meta_data = self::get_meta_data( $this->property_id );
$agents = array();
$agents['enable'] = $meta_data ['group:agent:section:agent_information:fields:enable'];
$author_id = get_post_field( 'post_author', $this->property_id );
if ( ! empty( $agents['enable'] ) ) {
$agents['info'] = $meta_data ['group:agent:section:agent_information:fields:information'];
if ( $agents['info'] === 'author' ) {
$agents['user_id'] = $author_id;
} elseif ( $agents['info'] === 'agent' ) {
if ( $meta_data['group:agent:section:agent_user:fields:agent_user'] ) {
$agents['user_id'] = $meta_data['group:agent:section:agent_user:fields:agent_user'];
} else {
$agents['user_id'] = $author_id;
}
} elseif ( $agents['info'] === 'show_custom_field' ) {
$agents['custom_fields'] = $meta_data['group:agent:section:additional_agents'];
$agents['user_id'] = $author_id;
}
} else {
$agents['user_id'] = $author_id;
}
return $agents;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists