File: /home/h278792/public_html/wp-content/plugins/ecademy-toolkit/widgets/tutor-courses.php
<?php
/**
* Courses Widget
*/
namespace Elementor;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class eCademy_Tutor_Courses extends Widget_Base {
public function get_name() {
return 'eCademy_Tutor_Courses';
}
public function get_title() {
return __( 'دوره های توتور', 'ecademy-toolkit' );
}
public function get_icon() {
return 'eicon-info-box';
}
public function get_categories() {
return [ 'ecademy-elements' ];
}
protected function register_controls() {
$this->start_controls_section(
'course_section',
[
'label' => __( 'دوره ها', 'ecademy-toolkit' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'card_style',
[
'label' => __( 'سبک کارت', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => [
'1' => __( 'سبک 1', 'ecademy-toolkit' ),
'2' => __( ' سبک دو (بدون جعبه سایه) ', 'ecademy-toolkit' ),
'3' => __( ' سبک 3', 'ecademy-toolkit' ),
'4' => __( ' سبک 4', 'ecademy-toolkit' ),
'5' => __( ' سبک پنج (با نوار لغزنده) ', 'ecademy-toolkit' ),
'6' => __( 'سبک 6', 'ecademy-toolkit' ),
'7' => __( 'سبک هفت (با نوار لغزنده) ', 'ecademy-toolkit' ),
],
'default' => '1',
]
);
$this->add_control(
'cat_name',
[
'label' => __( 'انتخاب دسته بندی', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => ecademy_toolkit_get_tutor_courses_cat_list(),
]
);
$this->add_control(
'filter',
[
'label' => __( 'دوره ها فیلتر بر اساس', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => [
'popular' => __( ' ویژه ', 'ecademy-toolkit' ),
'trending' => __( ' محبوبیت ', 'ecademy-toolkit' ),
'recent' => __( ' اخیر ', 'ecademy-toolkit' ),
],
'default' => 'recent',
]
);
$this->add_control(
'order',
[
'label' => __( 'دوره ها به ترتیب ', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => [
'DESC' => __( 'DESC', 'ecademy-toolkit' ),
'ASC' => __( 'ASC', 'ecademy-toolkit' ),
],
'default' => 'DESC',
]
);
$this->add_control(
'count',
[
'label' => __( 'شمردن ', 'ecademy-toolkit' ),
'type' => Controls_Manager::NUMBER,
'default' => 3,
]
);
$this->add_control(
'lessons_title',
[
'label' => esc_html__( 'عنوان درس', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'default' => __('درس', 'ecademy-toolkit'),
'condition' => [
'card_style' => ['1', '2', '3', '4', '5', '6'],
]
]
);
$this->add_control(
'students_title',
[
'label' => esc_html__( 'عنوان دانش آموز', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'default' => __('دانش آموز', 'ecademy-toolkit'),
'condition' => [
'card_style' => ['1', '2', '3', '4', '5', '6'],
]
]
);
$this->add_control(
'free_text',
[
'label' => esc_html__( 'متن دوره رایگان', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'label_block' => true,
]
);
$this->add_control(
'button_text',
[
'label' => esc_html__( 'متن دکمه', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'default' => __('مشاهده همه دوره ها', 'ecademy-toolkit'),
'condition' => [
'card_style' => ['4', '6'],
]
]
);
$this->add_control(
'button_icon',
[
'label' => esc_html__( 'آیکن دکمه', 'ecademy-toolkit' ),
'type' => Controls_Manager::ICON,
'label_block' => true,
'options' => ecademy_flaticons(),
'condition' => [
'card_style' => ['4', '6'],
]
]
);
$this->add_control(
'btn_link_type',
[
'label' => esc_html__( 'نوع پیوند دکمه ', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'label_block' => true,
'options' => [
'1' => esc_html__( 'پیوند به صفحه', 'ecademy-toolkit' ),
'2' => esc_html__( 'لینک خارجی', 'ecademy-toolkit' ),
],
'condition' => [
'card_style' => ['4', '6'],
]
]
);
$this->add_control(
'btn_link_to_page',
[
'label' => esc_html__( ' صفحه پیوند دکمه ', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'label_block' => true,
'options' => ecademy_toolkit_get_page_as_list(),
'condition' => [
'btn_link_type' => '1',
]
]
);
$this->add_control(
'btn_ex_link',
[
'label' => esc_html__('دکمه لینک خارجی', 'ecademy-toolkit'),
'type' => Controls_Manager:: TEXT,
'condition' => [
'link_type' => '2',
]
]
);
$this->add_control(
'bottom_title',
[
'label' => __( 'متن دکمه', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'default' => __('اختصاصی ترین مشاوره را برای دوره متحول کننده زندگی خود دریافت کنید. برای تلاش و اشتیاق خود گواهینامه کسب کنید', 'ecademy-toolkit'),
'condition' => [
'card_style' => ['1', '2', '3', '4', '5', '6'],
]
]
);
$this->add_control(
'bottom_link_title',
[
'label' => __( 'عنوان لینک پایین', 'ecademy-toolkit' ),
'type' => Controls_Manager::TEXT,
'default' => __('عضویت رایگان هم اکنون.', 'ecademy-toolkit'),
'condition' => [
'card_style' => ['1', '2', '3', '4', '5', '6'],
]
]
);
$this->add_control(
'link_type',
[
'label' => esc_html__( ' نوع پیوند ', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'label_block' => true,
'options' => [
'1' => esc_html__( 'پیوند به صفحه', 'ecademy-toolkit' ),
'2' => esc_html__( 'لینک خارجی', 'ecademy-toolkit' ),
],
'condition' => [
'card_style' => ['1', '2', '3', '4', '5', '6'],
]
]
);
$this->add_control(
'link_to_page',
[
'label' => esc_html__( 'پیوند صفحه ', 'ecademy-toolkit' ),
'type' => Controls_Manager::SELECT,
'label_block' => true,
'options' => ecademy_toolkit_get_page_as_list(),
'condition' => [
'link_type' => '1',
]
]
);
$this->add_control(
'ex_link',
[
'label' => esc_html__('لینک خارجی', 'ecademy-toolkit'),
'type' => Controls_Manager:: TEXT,
'condition' => [
'link_type' => '2',
]
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
global $ecademy_opt;
if( isset( $ecademy_opt['enable_lazyloader'] ) ):
$is_lazyloader = $ecademy_opt['enable_lazyloader'];
else:
$is_lazyloader = true;
endif;
if ( !ecademy_plugin_active( 'tutor/tutor.php' ) ) {
if( is_user_logged_in() ):
?>
<div class="container">
<div class="alert alert-danger" role="alert">
<?php echo esc_html__( 'لطفا افزونه Tutor LMS را نصب و فعال کنید', 'ecademy-toolkit' ); ?>
</div>
</div>
<?php
endif;
return;
}
// Post Query
if( $settings['cat_name'] != '' ) {
if( $settings['filter'] == 'trending' ):
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
'tax_query' => array(
array(
'taxonomy' => 'course-category',
'field' => 'slug',
'terms' => $settings['cat_name'],
'hide_empty' => false,
)
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'tutor_trending_course',
'value' => true,
'compare' => 'IN',
),
),
);
elseif( $settings['filter'] == 'popular' ):
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
'tax_query' => array(
array(
'taxonomy' => 'course-category',
'field' => 'slug',
'terms' => $settings['cat_name'],
'hide_empty' => false,
)
),
'ignore_sticky_posts' => true,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'tutor_featured_course',
'value' => true,
'compare' => 'IN',
),
),
);
else:
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
'tax_query' => array(
array(
'taxonomy' => 'course-category',
'field' => 'slug',
'terms' => $settings['cat_name'],
'hide_empty' => false,
)
)
);
endif;
} else {
if( $settings['filter'] == 'trending' ):
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'tutor_trending_course',
'value' => true,
'compare' => 'IN',
),
),
);
elseif( $settings['filter'] == 'popular' ):
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
'ignore_sticky_posts' => true,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'tutor_featured_course',
'value' => true,
'compare' => 'IN',
),
),
);
else:
$args = array(
'post_type' => 'courses',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
);
endif;
}
$post_array = new \WP_Query( $args );
// Get Button Link
if($settings['link_type'] == 1){
$link = get_page_link( $settings['link_to_page'] );
} else {
$link = $settings['ex_link'];
}
?>
<?php if( $settings['card_style'] != '4' && $settings['card_style'] != '5' && $settings['card_style'] != '6' && $settings['card_style'] != '7' ): ?>
<div class="container">
<div class="row">
<?php while($post_array->have_posts()): $post_array->the_post(); ?>
<div class="col-lg-4 col-md-6">
<div class="single-courses-box <?php if( $settings['card_style'] == '2' ): ?>without-boxshadow<?php elseif( $settings['card_style'] == '3' ): ?>bg-color<?php endif; ?>">
<div class="courses-image">
<a href="<?php the_permalink(); ?>" class="d-block image">
<?php if( $is_lazyloader == true ): ?>
<img sm-src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php else: ?>
<img src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php endif; ?>
</a>
<?php
$course_id = get_the_ID();
$price_html = '<div class="price"> '.esc_html($settings['free_text']).'</div>';
if (tutor_utils()->is_course_purchasable()) {
$product_id = tutor_utils()->get_course_product_id($course_id);
$product = wc_get_product( $product_id );
if ( $product ) {
$price_html = '<div class="price"> '.$product->get_price_html().' </div>';
}
}
echo $price_html;
?>
</div>
<div class="courses-content">
<div class="course-author d-flex align-items-center">
<?php
global $post, $authordata;
$user_id = get_current_user_id();
$user = get_user_by('ID', $user_id);
$profile_url = tutor_utils()->profile_url($authordata->ID);
?>
<img src="<?php echo get_avatar_url($user_id, array('size' => 150)); ?>" />
<span><a href="<?php echo $profile_url; ?>"><?php echo get_the_author(); ?></a></span>
</div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
<ul class="courses-box-footer d-flex justify-content-between align-items-center">
<li>
<?php
$course_id = get_the_ID();
$tutor_lesson_count = tutor_utils()->get_lesson_count_by_course($course_id);
?>
<i class='flaticon-agenda'></i>
<?php echo $tutor_lesson_count; ?> <?php echo esc_html( $settings['lessons_title'] ); ?>
</li>
<li>
<i class='flaticon-people'></i>
<?php echo (int) tutor_utils()->count_enrolled_users_by_course(); ?>
<?php echo esc_html( $settings['students_title'] ); ?>
</li>
</ul>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php if( !is_user_logged_in() ): ?>
<div class="col-lg-12 col-md-12">
<div class="courses-info">
<p><?php echo esc_html( $settings['bottom_title'] ); ?> <a href="<?php echo esc_url( $link ); ?>"><strong><?php echo esc_html( $settings['bottom_link_title'] ); ?></strong></a></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php elseif( $settings['card_style'] == '4' || $settings['card_style'] == '6' ):
// Button Icon
if( $settings['button_icon'] != '' ):
$icon = $settings['button_icon'];
else:
$icon = 'flaticon-user';
endif;
// Get Button Link
if($settings['btn_link_type'] == 1){
$btn_link = get_page_link( $settings['btn_link_to_page'] );
} else {
$btn_link = $settings['btn_ex_link'];
}
?>
<div class="container">
<div class="row">
<?php while($post_array->have_posts()): $post_array->the_post(); ?>
<div class="col-lg-6 col-md-12">
<div class="<?php if( $settings['card_style'] == '6' ): ?>single-courses-item without-box-shadow<?php else: ?>single-courses-item<?php endif; ?>">
<div class="row align-items-center">
<div class="col-lg-4 col-md-4">
<div class="courses-image">
<?php if( $is_lazyloader == true ): ?>
<img sm-src="<?php the_post_thumbnail_url('ecademy_400x400'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php else: ?>
<img src="<?php the_post_thumbnail_url('ecademy_400x400'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php endif; ?>
<a href="<?php the_permalink(); ?>" class="link-btn"></a>
</div>
</div>
<div class="col-lg-8 col-md-8">
<div class="courses-content">
<?php
$course_id = get_the_ID();
$price_html = '<div class="price"> '.esc_html($settings['free_text']).'</div>';
if (tutor_utils()->is_course_purchasable()) {
$product_id = tutor_utils()->get_course_product_id($course_id);
$product = wc_get_product( $product_id );
if ( $product ) {
$price_html = '<div class="price"> '.$product->get_price_html().' </div>';
}
}
echo $price_html;
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<ul class="courses-content-footer d-flex justify-content-between align-items-center">
<li>
<?php
$course_id = get_the_ID();
$tutor_lesson_count = tutor_utils()->get_lesson_count_by_course($course_id);
?>
<i class='flaticon-agenda'></i>
<?php echo $tutor_lesson_count; ?> <?php echo esc_html( $settings['lessons_title'] ); ?>
</li>
<li>
<i class='flaticon-people'></i>
<?php echo (int) tutor_utils()->count_enrolled_users_by_course(); ?>
<?php echo esc_html( $settings['students_title'] ); ?>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<div class="col-lg-12 col-md-12">
<div class="courses-info">
<?php if( $settings['button_text'] != '' ): ?>
<a href="<?php echo esc_url( $btn_link ); ?>" class="default-btn"><i class="<?php echo esc_attr( $icon ); ?>"></i><?php echo esc_html( $settings['button_text'] ); ?><span></span></a>
<?php endif; ?>
<?php if( !is_user_logged_in() ): ?>
<p><?php echo esc_html( $settings['bottom_title'] ); ?> <a href="<?php echo esc_url( $link ); ?>"><strong><?php echo esc_html( $settings['bottom_link_title'] ); ?></strong></a></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if( $settings['card_style'] == '5'): ?>
<div class="container">
<?php if( $settings['count'] == 1 ): ?>
<div class="col-lg-6 offset-lg-3">
<?php else: ?>
<div class="courses-slides owl-carousel owl-theme">
<?php endif; ?>
<?php while($post_array->have_posts()): $post_array->the_post(); ?>
<div class="single-courses-box <?php if( $settings['card_style'] == '2' ): ?>without-boxshadow<?php elseif( $settings['card_style'] == '3' ): ?>bg-color<?php endif; ?>">
<div class="courses-image">
<a href="<?php the_permalink(); ?>" class="d-block image">
<?php if( $is_lazyloader == true ): ?>
<img sm-src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php else: ?>
<img src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php endif; ?>
</a>
<?php
$course_id = get_the_ID();
$price_html = '<div class="price"> '.esc_html($settings['free_text']).'</div>';
if (tutor_utils()->is_course_purchasable()) {
$product_id = tutor_utils()->get_course_product_id($course_id);
$product = wc_get_product( $product_id );
if ( $product ) {
$price_html = '<div class="price"> '.$product->get_price_html().' </div>';
}
}
echo $price_html;
?>
</div>
<div class="courses-content">
<div class="course-author d-flex align-items-center">
<?php
global $post, $authordata;
$user_id = get_current_user_id();
$user = get_user_by('ID', $user_id);
$profile_url = tutor_utils()->profile_url($authordata->ID);
?>
<img src="<?php echo get_avatar_url($user_id, array('size' => 150)); ?>" />
<span><a href="<?php echo $profile_url; ?>"><?php echo get_the_author(); ?></a></span>
</div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
<ul class="courses-box-footer d-flex justify-content-between align-items-center">
<li>
<?php
$course_id = get_the_ID();
$tutor_lesson_count = tutor_utils()->get_lesson_count_by_course($course_id);
?>
<i class='flaticon-agenda'></i>
<?php echo $tutor_lesson_count; ?> <?php echo esc_html( $settings['lessons_title'] ); ?>
</li>
<li>
<i class='flaticon-people'></i>
<?php echo (int) tutor_utils()->count_enrolled_users_by_course(); ?>
<?php echo esc_html( $settings['students_title'] ); ?>
</li>
</ul>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<?php if( !is_user_logged_in() ): ?>
<div class="courses-info">
<p><?php echo esc_html( $settings['bottom_title'] ); ?> <a href="<?php echo esc_url( $link ); ?>"><strong><?php echo esc_html( $settings['bottom_link_title'] ); ?></strong></a></p>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if( $settings['card_style'] == '7'): ?>
<div class="container">
<?php if( $settings['count'] == 1 ): ?>
<div class="col-lg-6 offset-lg-3">
<?php else: ?>
<div class="courses-slides-two owl-carousel owl-theme">
<?php endif; ?>
<?php while($post_array->have_posts()): $post_array->the_post(); ?>
<div class="single-kindergarten-courses-box">
<div class="courses-image">
<a href="<?php the_permalink(); ?>" class="d-block image">
<?php if( $is_lazyloader == true ): ?>
<img sm-src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php else: ?>
<img src="<?php the_post_thumbnail_url('ecademy_default_thumb'); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php endif; ?>
</a>
<?php
$course_id = get_the_ID();
$price_html = '<div class="price"> '.esc_html($settings['free_text']).'</div>';
if (tutor_utils()->is_course_purchasable()) {
$product_id = tutor_utils()->get_course_product_id($course_id);
$product = wc_get_product( $product_id );
if ( $product ) {
$price_html = '<div class="price"> '.$product->get_price_html().' </div>';
}
}
echo $price_html;
?>
<a href="<?php the_permalink(); ?>" class="link-btn"></a>
</div>
<div class="courses-content">
<div class="course-author d-flex align-items-center">
<?php
global $post, $authordata;
$user_id = get_current_user_id();
$user = get_user_by('ID', $user_id);
$profile_url = tutor_utils()->profile_url($authordata->ID);
?>
<img src="<?php echo get_avatar_url($user_id, array('size' => 150)); ?>" />
<span><a href="<?php echo $profile_url; ?>"><?php echo get_the_author(); ?></a></span>
</div>
<h3 class="font-weight-black"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php endif; ?>
<?php
}
}
Plugin::instance()->widgets_manager->register( new eCademy_Tutor_Courses );