wpcap_content_layout_options(); $this->wpcap_content_design_options(); } /** * Content Layout Options. */ private function wpcap_content_layout_options() { $this->start_controls_section( 'section_content', [ 'label' => esc_html__('Content', 'fieldday'), ] ); $this->add_control( 'grid_layout', [ 'label' => __('Grid Layout', 'fieldday'), 'type' => Controls_Manager::SELECT, 'options' => [ '1' => __('1 Column view', 'fieldday'), '2' => __('2 Columns view', 'fieldday'), '3' => __('3 Colums view', 'fieldday') ], 'default' => '1' ] ); $this->add_control( 'content_tag', [ 'label' => __('Content HTML Tag', 'fieldday'), 'type' => Controls_Manager::SELECT, 'options' => [ 'h1' => 'H1', 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'div' => 'div', 'span' => 'span', 'p' => 'p', 'i' => 'i' ], 'default' => 'i' ] ); $this->add_control( 'counts', [ 'label' => __('Counts', 'fieldday'), 'type' => Controls_Manager::TEXT, 'default' => __('', 'fieldday') ] ); $this->end_controls_section(); } private function wpcap_content_design_options() { $this->start_controls_section( 'section_design_options', [ 'label' => __('Design Options', 'elementor'), ] ); $this->add_control( 'description_color', [ 'label' => __('Testimonial Color', 'elementor'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .km_review_description' => 'color: {{VALUE}};', ] ] ); /*$this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'testimonial_desc_design', 'label' => __('Testimonial Typography', 'plugin-domain'), 'scheme' => Typography::TYPOGRAPHY_1, 'selector' => '{{WRAPPER}} .km_review_description', ] );*/ $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'testimonial_desc_design', 'label' => __('Testimonial Typography', 'fieldday'), 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY, ], 'selector' => '{{WRAPPER}} .km_review_description', ] ); $this->add_control( 'username_color', [ 'label' => __('Username Color', 'elementor'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .km_review_username' => 'color: {{VALUE}};', ] ] ); /*$this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'testimonial_username_design', 'label' => __('Username Typography', 'fieldday'), 'scheme' => Typography::TYPOGRAPHY_1, 'selector' => '{{WRAPPER}} .km_review_username', ] );*/ $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'testimonial_username_design', 'label' => __('Username Typography', 'fieldday'), 'global' => [ 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY, ], 'selector' => '{{WRAPPER}} .km_review_username', ] ); $this->end_controls_section(); } /** * render the widget * @param mixed $instance * @return HTML content */ protected function render($instance = []) { // Get settings. $this->settings = $this->get_active_settings(); $set_counts_value = $this->settings['counts']??10; if($set_counts_value && $set_counts_value!=''){ $testemonials = fieldday()->api->getProviderTestimonials(['page' => 0, 'count' => $set_counts_value]); }else{ $testemonials = fieldday()->api->getProviderTestimonials(['page' => 0, 'count' => 10]); } if ($testemonials->statusCode !== 200) { echo fieldday()->engine->displayFlash('error', __($testemonials->message, 'fieldday')); return; } $this->displayReviews($testemonials); } private function displayReviews($testemonialsResponse) { $testemonials = $testemonialsResponse->data; print '
'; print $this->displayReviewSummary($testemonials); print wp_sprintf("

%s

", __("Reviews")); print "
"; foreach ($testemonials->testimonials as $key => $testimonial) { print $this->singleReview($testimonial); } print '
'; print '
'; } private function singleReview($testimonial) { $layoutColumns = $this->settings['grid_layout']; $layoutclass = "layout_{$layoutColumns}_columns"; $html = '
'; $html .= "
"; $html .= wp_sprintf("%s", fieldday()->engine->parseDate($testimonial->createdAt)); $html .= $this->testimonialUserDetail($testimonial->reviewBy, $testimonial); $html .= '
'; $html .= "
"; $html .= $this->testimonialDescription($testimonial); $html .= '
'; $html .= '
'; return $html; } /** * display testimonial description * @param type $testimonial * @return String */ protected function testimonialDescription($testimonial) { return wp_sprintf('<%1$s class="km_review_description">%2$s', $this->settings['content_tag'], $testimonial->description); } /** * testimonial user info * @param object $userInfo * @param object $testimonial testimonial data * @return string */ protected function testimonialUserDetail($userInfo, $testimonial) { if ($testimonial->verifiedCustomer) { $isVerified = "km_verified_user km_secondary_color"; $verifiedText = __("Verified Buyer", 'fieldday'); } else { $isVerified = "km_unverified_user"; $verifiedText = __("Guest Buyer", 'fieldday'); } $html = "
"; $html .= wp_sprintf("
%s
", fieldday()->engine->getfielddayUserDP($userInfo)); $html .= "
"; $html .= wp_sprintf("
%s%s
", $userInfo->name, $isVerified, $verifiedText); $html .= $this->displayStars($testimonial->rating); $html .= '
'; $html .= '
'; return $html; } protected function displayReviewSummary($testimonials) { $averageRating = $testimonials->averageRating; $reviewCount = (array) $testimonials->reviewCount; $html = "
"; $html .= "
"; $html .= "
"; $html .= wp_sprintf("%s", number_format($averageRating->rating, 1)); $html .= $this->displayStars($averageRating->rating); $html .= "
"; $html .= wp_sprintf("Based on %d Reviews", $averageRating->ratingCount); $html .= "
"; $html .= "
"; $html .= $this->displayDetailedSummary($reviewCount, $averageRating->ratingCount); $html .= "
"; $html .= "
"; return $html; } /** * * @param INT $rating * @param INT $totalReviews * @return string */ private function displayStars($rating) { $html = '
'; $html .= "
"; for ($index = 5; $index >= 1; $index--) { $class = $rating >= $index ? "km_star_yellow" : "km_star_gray"; $html .= wp_sprintf('', $index, $class); } $html .= '
'; $html .= '
'; return $html; } /** * display detailed info * @param array $reviews */ private function displayDetailedSummary($reviews, $totalRate) { $html =''; $k = array_keys($reviews); $v = array_values($reviews); $rv = array_reverse($v); $kv = array_reverse($k); $reviews = array_combine($kv, $rv); $html.= "
"; foreach ($reviews as $key => $reviewsCount) { $percentage = round(($reviewsCount * 100) / $totalRate, 1); $html .= "
"; $html .= $this->displayStars($key); $html .= wp_sprintf("", __("{$percentage}%")); $html .= wp_sprintf("(%s)", $reviewsCount); $html .= '
'; } $html .= '
'; return $html; } }