File: /mnt/data/dreamsrent-wp/wp-content/plugins/dreamsrent-widgets/widgets/class-testimonials.php
<?php
namespace Dreamsrentelementor\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use \Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Elementor Hello World
*
* Elementor widget for hello world.
*
* @since 1.0.0
*/
class DRS_testimonials extends Widget_Base {
/**
* Retrieve the widget name.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'dreamsrent_elementor_testimonials';
}
/**
* Retrieve the widget title.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return __( 'DR Testimonial List', 'dreamsrent_elementor' );
}
/**
* Retrieve the widget icon.
*
* @since 1.0.0
*
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'eicon-testimonial';
}
/**
* 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 [ 'dreamsrentelemetortheme' ];
}
/**
* Retrieve the list of scripts the widget depended on.
*
* Used to set scripts dependencies required to run the widget.
*
* @since 1.0.0
*
* @access public
*
* @return array Widget scripts dependencies.
*/
public function get_script_depends() {
return [ 'dreamsrentelementor-elementor' ];
}
/**
* 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() {
$this->start_controls_section(
'section_content',
[
'label' => __( 'Content', 'dreamsrent_elementor' ),
]
);
$this->add_control(
'testimonials',
[
'label' => __( 'Testimonial Items', 'dreamsrent_elementor' ),
'type' => Controls_Manager::REPEATER,
'default' => [
[
'name' => __( 'Tony Chester', 'dreamsrent_elementor' ),
'desc' => __( 'I am item content. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'dreamsrent_elementor' ),
'rating' => __( '5', 'dreamsrent_elementor' ),
'image' => [ 'url' => Utils::get_placeholder_image_src() ],
'class' => '',
],
[
'name' => __( 'Tony Chester', 'dreamsrent_elementor' ),
'desc' => __( 'I am item content. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'dreamsrent_elementor' ),
'rating' => __( '5', 'dreamsrent_elementor' ),
'image' => [ 'url' => Utils::get_placeholder_image_src() ],
'class' => '',
],
],
'fields' => [
[
'name' => 'name',
'label' => __( 'Name', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => __( 'Tony Chester' , 'dreamsrent_elementor' ),
'dynamic' => [
'active' => true,
],
'label_block' => true,
],
[
'name' => 'rating',
'label' => __( 'Rating', 'dreamsrent_elementor' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => '5',
'options' => [
'1' => __( '1 Star', 'dreamsrent_elementor' ),
'2' => __( '2 Star', 'dreamsrent_elementor' ),
'3' => __( '3 Star', 'dreamsrent_elementor' ),
'4' => __( '4 Star', 'dreamsrent_elementor' ),
'5' => __( '5 Star', 'dreamsrent_elementor' ),
]],
[
'name' => 'image',
'label' => __( 'Image', 'dreamsrent_elementor' ),
'type' => Controls_Manager::MEDIA,
'default' => [
'url' => Utils::get_placeholder_image_src(),
],
'dynamic' => [
'active' => true,
],
'label_block' => true,
],
[
'name' => 'desc',
'label' => __( 'Content', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXTAREA,
'default' => __( 'Desciption', 'dreamsrent_elementor' ),
'show_label' => false,
],
[
'name' => 'class',
'label' => __( 'Class', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
],
'label_block' => true,
],
],
'title_field' => '{{{ name }}}',
]
);
$this->add_control(
'class',
[
'label' => __( 'Class', 'dreamsrent_elementor' ),
'type' => Controls_Manager::TEXT,
]
);
$this->end_controls_section();
// Style tab: Name
$this->start_controls_section(
'testimonials_name_style',
[
'label' => __( 'Name', 'dreamsrent_elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'testimonials_name_color',
[
'label' => __( 'Name Color', 'dreamsrent_elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .testimonial-group .review-details h6' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'testimonials_name_typography',
'label' => __( 'Name Typography', 'dreamsrent_elementor' ),
'selector' => '{{WRAPPER}} .testimonial-group .review-details h6',
]
);
$this->end_controls_section();
// Style tab: Text
$this->start_controls_section(
'testimonials_text_style',
[
'label' => __( 'Text', 'dreamsrent_elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'testimonials_text_color',
[
'label' => __( 'Text Color', 'dreamsrent_elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .testimonial-group .card-body p' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'testimonials_text_typography',
'label' => __( 'Text Typography', 'dreamsrent_elementor' ),
'selector' => '{{WRAPPER}} .testimonial-group .card-body p',
]
);
$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();
?>
<div class="container">
<div class="testimonial-group">
<div class="row">
<?php foreach ( $settings['testimonials'] as $index => $item ) :
$image = $item['image']['url'];?>
<div class="col-lg-6 col-12 d-flex " data-aos="fade-down" data-aos-duration="1200" data-aos-delay="100">
<div class="card flex-fill">
<div class="card-body">
<div class="quotes-head"></div>
<div class="review-box">
<div class="review-profile">
<div class="review-img">
<img src="<?php echo esc_url( $image ); ?>" class="img-fluid" alt="<?php echo esc_attr( $item['name'] ); ?>">
</div>
</div>
<div class="review-details">
<h6><?php echo $item['name']; ?></h6>
<div class="list-rating">
<div class="list-rating-star">
<?php
$stars = $item['rating'];
$result = "";
for($i = 1; $i <= 5; $i++){
if($stars >= $i){ ?>
<i class="fas fa-star filled"></i>
<?php } else { ?>
<i class="far fa-star"></i>
<?php } } ?>
</div>
<p><span>(<?php echo round($item['rating']); ?>.0)</span></p>
</div>
</div>
</div>
<p><?php echo $item['desc']; ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<?php
}
/**
* Render the widget output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 1.0.0
*
* @access protected
*/
protected function content_template() {
?>
<?php
}
}