File: /mnt/data/truelysell-wp/wp-content/plugins/truelysell-elementor/widgets/class-providers-popular.php
<?php
/**
* Awesomesauce class.
*
* @category Class
* @package ElementorAwesomesauce
* @subpackage WordPress
* @author Ben Marshall <[email protected]>
* @copyright 2020 Ben Marshall
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0-only
* @link link(https://www.benmarshall.me/build-custom-elementor-widgets/,
* Build Custom Elementor Widgets)
* @since 1.0.0
* php version 7.3.9
*/
namespace ElementorTruelysell\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) {
// Exit if accessed directly.
exit;
}
/**
* Awesomesauce widget class.
*
* @since 1.0.0
*/
class Truelysell_Popular_Providers extends Widget_Base {
/**
* Retrieve the widget name.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'TruelysellpopularProviders';
}
/**
* Retrieve the widget title.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return __( 'Truelysell Popular Providers', 'truelysell_elementor' );
}
/**
* Retrieve the widget icon.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'eicon-gallery-grid';
}
/**
* Retrieve the list of categories the widget belongs to.
*
* Used to determine where to display the widget in the editor.
*
* Note that currently Elementor supports only one category.
* When multiple categories passed, Elementor uses the first one.
*
* @since 1.0.0
*
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return array( 'truelysell' );
}
/**
* Register the widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
*
* @access protected
*/
protected function _register_controls() {
//Content
$this->start_controls_section(
'content_section',
[
'label' => esc_html__( 'Content', 'truelysell_elementor' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'style',
[
'label' => __( 'Style ', 'truelysell_elementor' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'style1',
'options' => [
'style1' => __( 'Style 1', 'truelysell_elementor' ),
'style2' => __( 'Style 2', 'truelysell_elementor' ),
],
]
);
$this->add_control(
'title',
array(
'label' => __( 'Title', 'truelysell_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'Popular', 'truelysell_elementor' ),
)
);
$this->add_control(
'ttitle',
array(
'label' => __( 'Highlight Title', 'truelysell_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'Providers', 'truelysell_elementor' ),
'condition' => [
'style' => [ 'style1'],
],
)
);
$this->add_control(
'subtitle',
array(
'label' => __( 'Sub-Title', 'truelysell_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'Each listing is designed to be clear and concise, providing customers', 'truelysell_elementor' ),
)
);
$this->add_control(
'viewall',
array(
'label' => __( 'View All ', 'truelysell_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'View All', 'truelysell_elementor' ),
'condition' => [
'style' => [ 'style1'],
],
)
);
$this->add_control(
'viewalllink',
array(
'label' => __( 'View All Link', 'truelysell_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( '#', 'truelysell_elementor' ),
'condition' => [
'style' => [ 'style1'],
],
)
);
$this->add_control(
'limit',
[
'label' => __( 'Providers to display', 'truelysell_elementor' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 21,
'step' => 1,
'default' => 6,
]
);
$this->add_control(
'order',
[
'label' => __( 'Order', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'DESC',
'options' => [
'DESC' => __( 'Descending', 'truelysell_elementor' ),
'ASC' => __( 'Ascending. ', 'truelysell_elementor' ),
],
]
);
$this->end_controls_section();
}
/**
* Render the widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
*
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
$limit = $settings['limit'] ? $settings['limit'] : 4;
$order = $settings['order'] ? $settings['order'] : 'ASC';
$args = array(
'role' => 'owner',
'number' => $limit, // limit
//'orderby' => 'user_nicename',
'order' => $order
);
$users = get_users( $args );
?>
<?php if($settings['style']=='style1') { ?>
<!-- Popular Providers -->
<section class="section provider-sectionnew pt-0">
<div class="container">
<div class="provider-sec">
<div class="row justify-content-center">
<div class="col-lg-12 text-center wow fadeInUp" data-wow-delay="0.2s">
<div class="section-header text-center">
<h2 class="mb-1"><?php echo $settings['title']; ?> <span class="text-linear-primary"><?php echo $settings['ttitle']; ?></span></h2>
<p class="sub-title"><?php echo $settings['subtitle']; ?></p>
</div>
</div>
</div>
<div class="row gx-0">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'bookings_calendar';
$results = $wpdb->get_results("SELECT owner_id, COUNT(*) as order_count FROM {$table_name} GROUP BY owner_id ORDER BY order_count DESC");
$user_data = [];
$count = 0; // Initialize counter
foreach ( $results as $row ) {
if ($count >= 4) break; // Stop after 4 providers
$count++; // Increment counter
$owner_id = $row->owner_id;
$order_count = $row->order_count;
$user = get_user_by('ID', $owner_id);
if ($user && user_can($user, 'owner')) {
$user_data[] = [
'user' => $user,
'order_count' => $order_count,
];
}
}
foreach ( $user_data as $user_info ) {
$user = $user_info['user'];
$order_count = $user_info['order_count'];
?>
<div class="col-xl-3 col-lg-4 col-md-6 d-flex">
<div class="provider-item flex-fill">
<div class="d-flex align-items-center">
<a href="#" class="avatar avatar-xl me-2">
<?php
$owner_id = $user->ID;
$total_posts = count_user_posts( $owner_id, 'listing' );
$listings = get_posts(array(
'author' => $owner_id,
'post_type' => 'listing',
'posts_per_page'=> -1,
'fields' => 'ids'
));
$min_price = null;
foreach ( $listings as $listing_id ) {
$price = get_post_meta( $listing_id, '_normal_price', true );
if ( $price !== '' ) {
$price = floatval($price);
if ( is_null($min_price) || $price < $min_price ) {
$min_price = $price;
}
}
}
if($min_price) {
$currency_abbr = truelysell_fl_framework_getoptions('currency' );
$currency_symbol = \Truelysell_Core_Listing::get_currency_symbol($currency_abbr);
$currency_postion = truelysell_fl_framework_getoptions('currency_postion' );
if($currency_postion == 'after') {
$normal_price = (float) $min_price . $currency_symbol;
} else {
$normal_price = $currency_symbol . (float) $min_price;
}
}
?>
<?php echo get_avatar( $owner_id, 56, '', '', [ 'class' => 'rounded-circle' ] ); ?>
</a>
<div>
<h6><a href="#"><?php echo esc_html_e( $user->display_name ); ?></a></h6>
<?php $profile_designation = get_the_author_meta( 'profile_designation' , $owner_id); ?>
<?php if($profile_designation) { ?>
<p class="fs-14 mb-0"><?php echo $profile_designation; ?></p>
<?php } else { ?>
<p class="fs-14 mb-0"><?php echo $user->user_email; ?></p>
<?php }?>
<?php if($min_price) { ?>
<p class="mb-0"><?php echo $total_posts; ?> <?php echo esc_html__( 'Services, From', 'truelysell_elementor' ); ?> <span class="text-gray-9"><?php echo $normal_price; ?></span></p>
<?php } ?>
<!-- <p class="fs-14 mb-0">Total Orders: <?php echo $order_count; ?></p> -->
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php if($settings['viewall']) { ?>
<div class="text-center view-all wow fadeInUp" data-wow-delay="0.2s">
<a href="<?php echo $settings['viewalllink']; ?>" class="btn btn-dark"><?php echo $settings['viewall']; ?><i class="ti ti-arrow-right ms-2"></i></a>
</div>
<?php } ?>
</div>
</div>
</section>
<?php } else if($settings['style']=='style2') { ?>
<section class="providers-section abt-provider">
<div class="container">
<div class="section-heading">
<div class="row">
<div class="col-md-6">
<p class="mb-0 fs-16"><?php echo $settings['subtitle']; ?></p>
<h2 class="fs-32"><?php echo $settings['title']; ?></h2>
</div>
</div>
</div>
<div class="row">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'bookings_calendar';
$results = $wpdb->get_results("SELECT owner_id, COUNT(*) as order_count FROM {$table_name} GROUP BY owner_id ORDER BY order_count DESC");
$user_data = [];
$count = 0; // Initialize counter
foreach ( $results as $row ) {
if ($count >= 4) break; // Stop after 4 providers
$count++; // Increment counter
$owner_id = $row->owner_id;
$order_count = $row->order_count;
$user = get_user_by('ID', $owner_id);
if ($user && user_can($user, 'owner')) {
$user_data[] = [
'user' => $user,
'order_count' => $order_count,
];
}
}
foreach ( $user_data as $user_info ) {
$user = $user_info['user'];
$order_count = $user_info['order_count'];
?>
<div class="col-lg-3 col-md-4 col-sm-6">
<div class="card providerset p-0 ">
<div class="card-body">
<div class="providerset-img">
<a href="#">
<?php
$owner_id = $user->ID;
$total_posts = count_user_posts( $owner_id, 'listing' );
$listings = get_posts(array(
'author' => $owner_id,
'post_type' => 'listing',
'posts_per_page'=> -1,
'fields' => 'ids'
));
$min_price = null;
foreach ( $listings as $listing_id ) {
$price = get_post_meta( $listing_id, '_normal_price', true );
if ( $price !== '' ) {
$price = floatval($price);
if ( is_null($min_price) || $price < $min_price ) {
$min_price = $price;
}
}
}
if($min_price) {
$currency_abbr = truelysell_fl_framework_getoptions('currency' );
$currency_symbol = \Truelysell_Core_Listing::get_currency_symbol($currency_abbr);
$currency_postion = truelysell_fl_framework_getoptions('currency_postion' );
if($currency_postion == 'after') {
$normal_price = (float) $min_price . $currency_symbol;
} else {
$normal_price = $currency_symbol . (float) $min_price;
}
}
?>
<?php echo get_avatar( $owner_id, 56, '', '', [ 'class' => '' ] ); ?>
</a>
</div>
<div class="providerset-content">
<div class="providerset-price mb-0 ">
<div class="d-flex justify-content-between align-items-center flex-fill">
<div class="providerset-name">
<h4 class="d-flex align-items-center "><a href="#" class="me-1 text-truncate"><?php echo esc_html_e( $user->display_name ); ?></a><i class="ti ti-circle-check-filled text-success"></i></h4>
<?php $profile_designation = get_the_author_meta( 'profile_designation' , $owner_id); ?>
<?php if($profile_designation) { ?>
<span><?php echo $profile_designation; ?></span>
<?php } else { ?>
<span><?php echo $user->user_email; ?></span>
<?php }?>
<!-- <div class="providerset-prices">
<?php if($min_price) { ?>
<h6><?php echo esc_html__( 'From', 'truelysell_elementor' ); ?> <?php echo $normal_price; ?><span><?php echo esc_html__( 'Services', 'truelysell_elementor' ); ?> <?php echo $total_posts; ?></span></h6>
<?php } ?>
</div> -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
<?php } ?>
<?php
}
}