This commit is contained in:
Hoang Huu 2019-09-25 15:34:38 +07:00
parent c93c699a77
commit 7ee9f6ecb0
8 changed files with 272 additions and 90 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
class OpalEstate_User_Statistics { class OpalEstate_User_Statistics {
public $user_id; public $user_id;
@ -7,23 +8,32 @@
} }
public function get_count_properties() { public function get_count_properties() {
$query = Opalestate_Query::get_properties_by_user( array(), $this->user_id ); $query = Opalestate_Query::get_properties_by_user( [], $this->user_id );
return $query->found_posts; return $query->found_posts;
} }
public function get_count_featured() { public function get_count_featured() {
$query = Opalestate_Query::get_properties_by_user( array( $query = Opalestate_Query::get_properties_by_user( [
'featured' => 1 'featured' => 1,
), $this->user_id ); ], $this->user_id );
return $query->found_posts;
}
public function get_count_published_properties() {
$query = Opalestate_Query::get_properties_by_user( [
'post_status' => 'publish',
], $this->user_id );
return $query->found_posts; return $query->found_posts;
} }
public function get_count_pending_properties() { public function get_count_pending_properties() {
$query = Opalestate_Query::get_properties_by_user( array( $query = Opalestate_Query::get_properties_by_user( [
'post_status' => 'pending' 'post_status' => 'pending',
), $this->user_id ); ], $this->user_id );
return $query->found_posts; return $query->found_posts;
} }
} }
?>

View File

@ -164,10 +164,12 @@ function opalestate_management_user_menu_tabs() {
'id' => isset( $opalestate_options['submission_page'] ) ? $opalestate_options['submission_page'] : 0, 'id' => isset( $opalestate_options['submission_page'] ) ? $opalestate_options['submission_page'] : 0,
]; ];
$statistics = new OpalEstate_User_Statistics();
$menu['myproperties'] = [ $menu['myproperties'] = [
'icon' => 'fa fa-building', 'icon' => 'fa fa-building',
'link' => 'submission_list', 'link' => 'submission_list',
'title' => esc_html__( 'My Properties', 'opalestate-pro' ), 'title' => esc_html__( 'My Properties', 'opalestate-pro' ) . '<span class="count">' . $statistics->get_count_properties() . '</span>',
'id' => isset( $opalestate_options['submission_list_page'] ) ? $opalestate_options['submission_list_page'] : 0, 'id' => isset( $opalestate_options['submission_list_page'] ) ? $opalestate_options['submission_list_page'] : 0,
]; ];
@ -255,5 +257,3 @@ if ( ! function_exists( 'opalestate_create_user' ) ) {
return $user_id; return $user_id;
} }
} }
?>

View File

@ -0,0 +1,49 @@
(function( $ ) {
'use strict';
$( document ).ready( function() {
$( ".adduser-team" ).delegate( ".remove-user", "click", function() {
if( confirm( $(this).data('alert') ) ){
$(this).parents( '.user-team' ).remove();
}
});
$( '.opalestate-add-user-field' ).each( function() {
var $this = $(this);
$('.button', this).click( function () {
var user_search = $( '.opalestate-adduser-search', $(this).parent().parent() ).val();
$('.opalestate-ajax').show();
var data = {
action: 'opalestate_ajax_search_username',
user_name: user_search,
};
$.ajax({
type: "POST",
data: data,
dataType: "json",
url: ajaxurl,
success: function ( response ) {
if( response.status == true ){
var template = wp.template( 'adduser-team-template' );
$('.adduser-team', $this ).append( template( response.user ) );
}else {
alert( response.message );
}
}
});
} );
} );
} );
})( jQuery );

View File

@ -0,0 +1,29 @@
.adduser-team{
width: 80%;
}
.user-team{
padding: 12px 10px;
display: block;
border-bottom: solid 1px #f3f3f3
}
.user-team > div{
display: inline-block;
width: 33%;
}
.user-team > div img{
width: 30px;
height: 30px;
border: solid 3px #CCC;
border-radius: 50%;
float: left;
margin-right: 6px;
}
.remove-user {
cursor: pointer;
}
.remove-user:hover {
color: red;
}

View File

@ -0,0 +1,95 @@
<?php
/**
* Opalestate_Field_Iconpicker
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Field_Iconpicker {
/**
* Current version number
*/
const VERSION = '1.0.0';
/**
* Initialize the plugin by hooking into CMB2
*/
public static function init() {
add_filter( 'cmb2_render_opal_iconpicker', [ __CLASS__, 'render_iconpicker' ], 10, 5 );
add_filter( 'cmb2_sanitize_opal_iconpicker', [ __CLASS__, 'sanitize_map' ], 10, 4 );
}
/**
* Render field
*/
public static function render_iconpicker( $field, $field_escaped_value, $field_object_id, $field_object_type, $field_type_object ) {
self::setup_admin_scripts();
$users = $field->value;
echo '<div class="opalestate-add-user-field ' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> '; ?>
<div class="col-lg-12">
<h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro' ); ?></h5>
<div>
<p><?php esc_html_e( 'Add someone to your agency, please enter extractly username in below input:', 'opalestate-pro' ); ?></p>
<div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>">
<div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div>
<div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button">
</div>
</div>
<div class="clear clearfix"></div>
</div>
<div class="adduser-team">
<?php if ( $users ): $users = array_unique( $users ); ?>
<?php foreach ( $users as $user_id ): $user = get_user_by( 'id', $user_id );
$user = $user->data ?>
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="<?php echo $user_id; ?>">
<div>
<img src="<?php echo get_avatar_url( $user_id ); ?>">
<a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove',
'opalestate-pro' ); ?></span></div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<script type="text/html" id="tmpl-adduser-team-template">
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="{{{data.ID}}}">
<div><img src="{{{data.avatar}}}"> <a href="{{{data.author_link}}}" target="_blank"> {{{data.user_login}}} </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div>
</div>
</script>
<?php echo '</div>';
}
/**
* Optionally save the latitude/longitude values into two custom fields
*/
public static function sanitize_map( $override_value, $value, $object_id, $field_args ) {
return $value;
}
/**
* Enqueue scripts and styles
*/
public static function setup_admin_scripts() {
wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), [], self::VERSION );
wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), [], self::VERSION );
}
}
Opalestate_Field_Iconpicker::init();

View File

@ -1,20 +1,15 @@
<?php <?php
/** /**
* $Desc$ * Opalestate_Field_Adduser
* *
* @version $Id$
* @package opalestate * @package opalestate
* @author Opal Team <info@wpopal.com > * @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly
} }
class Opalestate_Field_Adduser { class Opalestate_Field_Adduser {
/** /**
@ -26,8 +21,8 @@ class Opalestate_Field_Adduser {
* Initialize the plugin by hooking into CMB2 * Initialize the plugin by hooking into CMB2
*/ */
public static function init() { public static function init() {
add_filter( 'cmb2_render_adduser', array( __CLASS__, 'render_map' ), 10, 5 ); add_filter( 'cmb2_render_adduser', [ __CLASS__, 'render_map' ], 10, 5 );
add_filter( 'cmb2_sanitize_adduser', array( __CLASS__, 'sanitize_map' ), 10, 4 ); add_filter( 'cmb2_sanitize_adduser', [ __CLASS__, 'sanitize_map' ], 10, 4 );
} }
/** /**
@ -38,7 +33,6 @@ class Opalestate_Field_Adduser {
$users = $field->value; $users = $field->value;
// echo '<pre>'.print_r( $value, 1 );die;
echo '<div class="opalestate-add-user-field ' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> '; ?> echo '<div class="opalestate-add-user-field ' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> '; ?>
<div class="col-lg-12"> <div class="col-lg-12">
<h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro' ); ?></h5> <h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro' ); ?></h5>
@ -48,20 +42,22 @@ class Opalestate_Field_Adduser {
<div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>"> <div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>">
<div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div> <div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div>
<div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button"></div> <div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button">
</div>
</div> </div>
<div class="clear clearfix"></div> <div class="clear clearfix"></div>
</div> </div>
<div class="adduser-team"> <div class="adduser-team">
<?php if ( $users ): $users = array_unique( $users ); ?> <?php if ( $users ): $users = array_unique( $users ); ?>
<?php foreach ( $users as $user_id ): $user = get_user_by( 'id', $user_id );
<?php foreach( $users as $user_id ): $user = get_user_by( 'id', $user_id ); $user = $user->data ?> $user = $user->data ?>
<div class="user-team"> <div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="<?php echo $user_id; ?>"> <input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="<?php echo $user_id; ?>">
<div> <div>
<img src="<?php echo get_avatar_url( $user_id ); ?>"> <img src="<?php echo get_avatar_url( $user_id ); ?>">
<a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a></div> <a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a></div>
<div> <span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div> <div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove',
'opalestate-pro' ); ?></span></div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
@ -84,7 +80,6 @@ class Opalestate_Field_Adduser {
* Optionally save the latitude/longitude values into two custom fields * Optionally save the latitude/longitude values into two custom fields
*/ */
public static function sanitize_map( $override_value, $value, $object_id, $field_args ) { public static function sanitize_map( $override_value, $value, $object_id, $field_args ) {
return $value; return $value;
} }
@ -92,8 +87,8 @@ class Opalestate_Field_Adduser {
* Enqueue scripts and styles * Enqueue scripts and styles
*/ */
public static function setup_admin_scripts() { public static function setup_admin_scripts() {
wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), array( ), self::VERSION ); wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), [], self::VERSION );
wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), array(), self::VERSION ); wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), [], self::VERSION );
} }
} }

View File

@ -20,6 +20,7 @@ $fields = [
'required' => 'required', 'required' => 'required',
], ],
]; ];
$form = OpalEstate()->html->render_form( $fields ); $form = OpalEstate()->html->render_form( $fields );
$id = 'agency-add-member'; $id = 'agency-add-member';
?> ?>

View File

@ -8,31 +8,31 @@
$properties_count = []; $properties_count = [];
$properties_count[] = [ $properties_count[] = [
'icon' => 'fa fa-list', 'icon' => 'fa fa-list',
'count' => $statistics->get_count_properties(), 'count' => $statistics->get_count_published_properties(),
'label' => esc_html__( 'My Properties', 'opalestate-pro' ), 'label' => esc_html__( 'Published Listings', 'opalestate-pro' ),
'class' => '', 'class' => 'dash-published-listings',
]; ];
$properties_count[] = [ $properties_count[] = [
'icon' => 'fa fa-star', 'icon' => 'fa fa-star',
'count' => $statistics->get_count_featured(), 'count' => $statistics->get_count_featured(),
'label' => esc_html__( 'Featured Properties', 'opalestate-pro' ), 'label' => esc_html__( 'Featured Listings', 'opalestate-pro' ),
'class' => '', 'class' => 'dash-featured-listings',
]; ];
$properties_count[] = [ $properties_count[] = [
'icon' => 'fa fa-file', 'icon' => 'fa fa-file',
'count' => $statistics->get_count_pending_properties(), 'count' => $statistics->get_count_pending_properties(),
'label' => esc_html__( 'Pending Properties', 'opalestate-pro' ), 'label' => esc_html__( 'Pending Properties', 'opalestate-pro' ),
'class' => '', 'class' => 'dash-pending-listings',
]; ];
?> ?>
<?php foreach ( $properties_count as $item ): ?> <?php foreach ( $properties_count as $item ): ?>
<div class="col-lg-4 col-md-4"> <div class="col-lg-4 col-md-4">
<div class="card-item inner <?php echo esc_attr( $item['class'] ); ?>"> <div class="card-item inner dash-widget <?php echo esc_attr( $item['class'] ); ?>">
<div class="heading"><i class="<?php echo esc_attr( $item['icon'] ); ?>"></i> <span><?php echo esc_html( $item['label'] ); ?></span></div> <h5 class="dash-count"><?php echo esc_html( $item['count'] ); ?></h5>
<h5><?php echo esc_html( $item['count'] ); ?></h5> <div class="heading"><span><?php echo esc_html( $item['label'] ); ?></span></div>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
@ -49,9 +49,12 @@
$comments = get_comments( $args ); $comments = get_comments( $args );
?> ?>
<div class="col-lg-8 col-md-8"> <div class="col-lg-12 col-md-12">
<div class="card-item inner"> <div class="card-item inner">
<div class="heading"><i class="fa fa-comment"></i> <span><?php esc_html_e( 'Latest review' ) ?></span></div> <div class="heading"><i class="fa fa-comment"></i> <span><?php esc_html_e( 'Latest review' ) ?></span>
<a href="<?php echo esc_url( opalestate_get_user_management_page_uri() . '?tab=reviews' ); ?>" class="dash-view-all"><?php esc_html_e( 'View All', 'opalestate-pro' );
?></a>
</div>
<?php if ( ! isset( $comments ) || ! $comments ) : ?> <?php if ( ! isset( $comments ) || ! $comments ) : ?>
<p class="opalestate-my-reviews-no-reviews"><?php esc_html_e( 'You have not written any reviews yet.', 'opalestate-pro' ); ?> </p> <p class="opalestate-my-reviews-no-reviews"><?php esc_html_e( 'You have not written any reviews yet.', 'opalestate-pro' ); ?> </p>