public function do_shortcode_reviewer($atts) { extract(shortcode_atts(array('id' => '', 'post' => get_the_ID(), 'size' => '24', 'stars' => '5'), $atts)); $review_id = intval($id); $post_id = intval($post); $size = intval($size); $stars = intval($stars); // Get post reviews $reviews = get_post_meta($post_id, 'rwp_reviews', true); // Check if user has inserted a valid review ID if (!isset($reviews[$review_id])) { return '<p>' . __('No review found! Insert a valid review ID.', $this->plugin_slug) . '</p>'; } // Get Review $this->review = $reviews[$id]; // Check box type $review_type = $this->review_field('review_type', true); if ($review_type != 'PAR+UR') { return '<p>' . __('It\'s not possible to get reviewer scores of a users reviews box', $this->plugin_slug) . '</p>'; } // Get Template $templates = RWP_Reviewer::get_option('rwp_templates'); $this->template = isset($templates[$this->review['review_template']]) ? $templates[$this->review['review_template']] : array(); $max = $this->template_field('template_maximum_score', true); $min = $this->template_field('template_minimum_score', true); $scores = $this->review_field('review_scores', true); $avg = RWP_Reviewer::get_avg($scores); $score = $this->map_range($avg, $min, $max, 0, $stars); ob_start(); echo $this->get_stars($score, $size, $stars); //RWP_Reviewer::pretty_print( $this->review ); //RWP_Reviewer::pretty_print( $this->template ); return ob_get_clean(); }
public static function get_score_bar($score = array(), $template = array(), $theme = '', $size = 0) { $avg = is_array($score) ? RWP_Reviewer::get_avg($score) : floatval($score); $max = floatval(self::template_field('template_maximum_score', $template, true)); $value = floatval($avg); $range = explode('-', self::template_field('template_score_percentages', $template, true)); $low = floatval($range[0]); $high = floatval($range[1]); $pct = round($value / $max * 100, 1); if ($pct < $low) { $color = self::template_field('template_low_score_color', $template, true); } else { if ($pct > $high) { $color = self::template_field('template_high_score_color', $template, true); } else { $color = self::template_field('template_medium_score_color', $template, true); } } $in = !empty($theme) ? '<span class="rwp-criterion-score" style="font-size: ' . ($size + 2) . 'px;">' . RWP_Reviewer::format_number($avg) . '</span>' : ''; return '<div class="rwp-score-bar" style="width: ' . $pct . '%; background: ' . $color . ';">' . $in . '</div>'; }
private static function get_stars($scores = array(), $max = 10, $stars = 5, $icon = '') { $avg = is_array($scores) ? RWP_Reviewer::get_avg($scores) : floatval($scores); $value = RWP_Reviewer::get_in_base($max, $stars, $avg); $int_value = intval($value); $decimal_value = $value - $int_value; if ($decimal_value >= 0.4 && $decimal_value <= 0.6) { $score = $int_value + 0.5; } else { if ($decimal_value > 0.6) { $score = $int_value + 1; } else { $score = $int_value; } } $count = $stars * 2; $html = '<div class="rwp-str rwp-api-rating-wrapper">'; $j = 0; for ($i = 0; $i < $count; $i++) { $oe = $i % 2 == 0 ? 'rwp-o' : 'rwp-e'; $fx = $j < $score ? 'rwp-f' : 'rwp-x'; $html .= '<span class="rwp-s ' . $oe . ' ' . $fx . '" style="background-image: url(' . $icon . ');"></span>'; $j += 0.5; } $html .= '</div><!-- /stars -->'; return $html; }
protected function get_stars($scores = array(), $template, $stars = 5) { $avg = is_array($scores) ? RWP_Reviewer::get_avg($scores) : floatval($scores); $value = RWP_Reviewer::get_in_base($template['template_maximum_score'], $stars, $avg); $int_value = intval($value); $decimal_value = $value - $int_value; if ($decimal_value >= 0.4 && $decimal_value <= 0.6) { $score = $int_value + 0.5; } else { if ($decimal_value > 0.6) { $score = $int_value + 1; } else { $score = $int_value; } } $count = $stars * 2; $html = '<div class="rwp-str">'; $j = 0; for ($i = 0; $i < $count; $i++) { $oe = $i % 2 == 0 ? 'rwp-o' : 'rwp-e'; $fx = $j < $score ? 'rwp-f' : 'rwp-x'; $html .= '<span class="rwp-s ' . $oe . ' ' . $fx . '" style="background-image: url(' . $template['template_rate_image'] . ');"></span>'; $j += 0.5; } $html .= '</div><!-- /stars -->'; return $html; }
function column_rwp_reviews_table_review_score($item) { $type = isset($item['review_type']) ? $item['review_type'] : 'PAR+UR'; if ($type == 'PAR+UR') { $overall = isset($item['review_scores']) ? round(RWP_Reviewer::get_avg($item['review_scores']), 1) : 0; $score = isset($item['review_custom_overall_score']) && !empty($item['review_custom_overall_score']) ? $item['review_custom_overall_score'] : $overall; return '<strong>' . $score . '</strong> / ' . $this->templates[$item['review_template']]['template_maximum_score']; } else { return '---'; } }
public static function sort_score($a, $b) { $avg_a = RWP_Reviewer::get_avg($a['rating_score']); $avg_b = RWP_Reviewer::get_avg($b['rating_score']); if ($avg_a == $avg_b) { return 0; } return $avg_a > $avg_b ? -1 : 1; }