2019-09-10 06:27:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2019-09-25 03:44:27 +02:00
|
|
|
* OpalEstate_Agent
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
|
|
|
* @package opalestate
|
|
|
|
* @author Opal Team <info@wpopal.com >
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OpalEstate_Agent
|
|
|
|
*
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
|
|
|
class OpalEstate_Agent {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var String $author_name
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $author_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean $is_featured
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $is_featured;
|
|
|
|
|
2019-09-28 11:39:55 +02:00
|
|
|
/**
|
|
|
|
* @var Boolean $is_featured
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
public $post_id;
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct( $post_id = null ) {
|
|
|
|
global $post;
|
|
|
|
|
|
|
|
if ( $post ) {
|
|
|
|
$this->post = $post;
|
|
|
|
$this->post_id = $post_id ? $post_id : get_the_ID();
|
|
|
|
$this->author = get_userdata( $post->post_author );
|
|
|
|
$this->author_name = ! empty( $this->author ) ? sprintf( '%s %s', $this->author->first_name, $this->author->last_name ) : null;
|
|
|
|
$this->is_featured = $this->get_meta( 'featured' );
|
|
|
|
$this->is_trusted = $this->get_meta( 'trusted' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_id() {
|
|
|
|
return $this->post_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Collection Of soicals with theirs values
|
|
|
|
*/
|
|
|
|
public function get_socials() {
|
|
|
|
$socials = [
|
|
|
|
'facebook' => '',
|
|
|
|
'twitter' => '',
|
|
|
|
'pinterest' => '',
|
|
|
|
'google' => '',
|
|
|
|
'instagram' => '',
|
|
|
|
'linkedIn' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
foreach ( $socials as $social => $k ) {
|
|
|
|
|
|
|
|
$data = $this->get_meta( $social );
|
|
|
|
if ( $data && $data != "#" && ! empty( $data ) ) {
|
|
|
|
$output[ $social ] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get url of user avatar by agent id
|
|
|
|
*/
|
2019-10-03 05:10:43 +02:00
|
|
|
public static function get_avatar_url( $userID, $size='thumbnail' ) {
|
|
|
|
$id = get_post_meta( $userID, OPALESTATE_AGENT_PREFIX . 'avatar_id', true );;
|
|
|
|
$url = wp_get_attachment_image_url( $id, $size );
|
|
|
|
|
|
|
|
if( $url ) {
|
|
|
|
return $url;
|
|
|
|
}
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render list of levels of agent
|
|
|
|
*/
|
|
|
|
public function render_level() {
|
|
|
|
$levels = wp_get_post_terms( $this->get_id(), 'opalestate_agent_level' );
|
|
|
|
|
|
|
|
if ( empty( $levels ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '<span class="agent-levels">';
|
|
|
|
foreach ( $levels as $key => $value ) {
|
|
|
|
$output .= '<span class="agent-label"><span>' . $value->name . '</span></span>';
|
|
|
|
}
|
|
|
|
$output .= '</span>';
|
|
|
|
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get meta data value of key without prefix
|
|
|
|
*/
|
|
|
|
public function get_meta( $key ) {
|
|
|
|
return get_post_meta( $this->get_id(), OPALESTATE_AGENT_PREFIX . $key, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return true if this agent is featured
|
|
|
|
*/
|
|
|
|
public function is_featured() {
|
|
|
|
return $this->is_featured;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* render block information by id
|
|
|
|
*/
|
|
|
|
public static function render_box_info( $post_id ) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_link( $agent_id ) {
|
|
|
|
$agent = get_post( $agent_id );
|
2019-10-01 10:57:58 +02:00
|
|
|
|
|
|
|
if ( ! $agent ) {
|
|
|
|
return [
|
|
|
|
'name' => '',
|
|
|
|
'avatar' => '',
|
|
|
|
'link' => '',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
$url = self::get_avatar_url( $agent_id );
|
|
|
|
|
|
|
|
return [
|
|
|
|
'name' => $agent->post_title,
|
|
|
|
'avatar' => $url,
|
|
|
|
'link' => get_permalink( $agent->ID ),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function metaboxes_fields() {
|
|
|
|
$metabox = new Opalestate_Agent_MetaBox();
|
|
|
|
$fields = $metabox->metaboxes_admin_fields();
|
|
|
|
|
|
|
|
return array_merge_recursive( $fields, $metabox->get_social_fields( OPALESTATE_AGENT_PREFIX ) );
|
|
|
|
}
|
|
|
|
|
2019-09-25 03:44:27 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function get_trusted() {
|
|
|
|
return $this->is_trusted;
|
|
|
|
}
|
2019-09-10 06:27:33 +02:00
|
|
|
|
2019-09-25 03:44:27 +02:00
|
|
|
/**
|
|
|
|
* Update user data.
|
|
|
|
*
|
|
|
|
* @param $user_id User ID.
|
|
|
|
*/
|
|
|
|
public static function update_user_data( $user_id ) {
|
2019-09-10 06:27:33 +02:00
|
|
|
$fields = self::metaboxes_fields();
|
|
|
|
|
|
|
|
$others = [
|
|
|
|
'avatar_id' => '',
|
|
|
|
'opalestate_agt_map' => '',
|
|
|
|
'map' => '',
|
|
|
|
];
|
2019-09-25 03:44:27 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
foreach ( $fields as $key => $field ) {
|
|
|
|
$kpos = $field['id'];
|
|
|
|
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, '', $field['id'] );
|
|
|
|
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
|
|
|
|
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
|
|
|
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $tmp, $data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update for others
|
|
|
|
foreach ( $others as $key => $value ) {
|
|
|
|
$kpos = OPALESTATE_AGENT_PREFIX . $key;
|
|
|
|
if ( isset( $_POST[ $kpos ] ) ) {
|
|
|
|
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
|
|
|
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $key, $data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-25 03:44:27 +02:00
|
|
|
* Update data from user.
|
2019-09-10 06:27:33 +02:00
|
|
|
*
|
2019-09-25 03:44:27 +02:00
|
|
|
* @param $related_id Post ID.
|
2019-09-10 06:27:33 +02:00
|
|
|
*/
|
|
|
|
public static function update_data_from_user( $related_id ) {
|
|
|
|
$fields = self::metaboxes_fields();
|
|
|
|
|
|
|
|
$others = [
|
|
|
|
'avatar_id' => '',
|
|
|
|
'map' => '',
|
|
|
|
];
|
|
|
|
|
2019-09-25 03:44:27 +02:00
|
|
|
foreach ( $fields as $key => $field ) {
|
|
|
|
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, '', $field['id'] );
|
2019-09-10 06:27:33 +02:00
|
|
|
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $tmp;
|
|
|
|
|
|
|
|
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
|
|
|
|
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
|
|
|
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $tmp, $data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update for others
|
|
|
|
foreach ( $others as $key => $value ) {
|
|
|
|
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $key;
|
|
|
|
if ( isset( $_POST[ $kpos ] ) ) {
|
|
|
|
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
|
|
|
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $key, $data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get rating count.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are view and edit.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function get_rating_counts() {
|
|
|
|
return $this->get_meta( 'rating_count' ) ? $this->get_meta( 'rating_count' ) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get average rating.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are view and edit.
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public function get_average_rating() {
|
|
|
|
return $this->get_meta( 'average_rating' ) ? $this->get_meta( 'average_rating' ) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get review count.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are view and edit.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function get_review_count() {
|
|
|
|
return $this->get_meta( 'review_count' ) ? $this->get_meta( 'review_count' ) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_rating_count_stats() {
|
|
|
|
return $this->get_meta( 'rating_count_stats' ) ? $this->get_meta( 'rating_count_stats' ) : [
|
|
|
|
5 => 0,
|
|
|
|
4 => 0,
|
|
|
|
3 => 0,
|
|
|
|
2 => 0,
|
|
|
|
1 => 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_rating_average_stats() {
|
|
|
|
return $this->get_meta( 'rating_average_stats' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_count_listing() {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|