Пример #1
0
    /**
     * Show avg rating for multiple posts for same form id,
     * calls from shortcode or direct function call or from widget
     *
     * @param     $option
     * @param int $show_title
     * @param int $show_form_id
     * @param int $show_text
     * @param int $show_star
     * @param int $show_single
     * @param int $text_label
     *
     * @return string
     */
    public static function standalone_singlePost_rating_summary($option, $show_title = 0, $show_form_id = 0, $show_text = 0, $show_star = 1, $show_single = 0, $text_label = '')
    {
        CBRatingSystem::load_scripts_and_styles();
        if ($option == NULL) {
            return '';
        }
        $text_label = $text_label == '' ? __('Rating: ', 'cbratingsystem') : $text_label;
        $post_ids = !isset($option['post_id']) || !is_array($option['post_id']) || sizeof($option['post_id']) == 0 ? array(get_the_ID()) : $option['post_id'];
        $form_ids = !isset($option['form_id']) || !is_array($option['form_id']) || sizeof($option['form_id']) == 0 ? array(self::get_default_ratingFormId()) : $option['form_id'];
        //$post_ids        = is_array($post_ids)
        $rating_smmary = array('post' => array());
        $show = '';
        /*echo '<pre>';
        		print_r($option);
        		echo '</pre>';*/
        //var_dump($form_ids);
        //var_dump($show_single);
        if ($show_single == 1 || sizeof($post_ids) == 1) {
            //if ( $show_single == 1 ) {
            //show only for first item
            $option['post_id'] = array($post_ids[0]);
            $option['form_id'] = array($form_ids[0]);
            $average_rating = CBRatingSystemData::get_ratings_summary($option);
            if (!sizeof($average_rating)) {
                $average_rating['form_id'] = $form_ids[0];
                $average_rating['post_id'] = $post_ids[0];
                $average_rating['post_title'] = get_the_title($post_ids[0]);
                $average_rating['per_post_rating_summary'] = 0;
                $average_rating['found'] = 0;
            } else {
                $average_rating = $average_rating[0];
                //no rating found for this post and form id
                $average_rating['found'] = 1;
            }
            $show .= '<div class="cbratingavgratelist">';
            if ($show_title == 1) {
                $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
            }
            if ($show_form_id == 1) {
                $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '</p>';
            }
            if ($show_text == 1) {
                $show .= '<p>' . $text_label . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5</p>';
            }
            $clip_back = 120;
            $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
            if ($show_star == 1) {
                ?>
				<script>
					jQuery(document).ready(function ($) {
						$('.cbrp-alone-rated<?php 
                echo $average_rating['post_id'];
                ?>
').raty({
							half    : true,
							path    : '<?php 
                echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                ?>
',
							score   : <?php 
                echo $average_rating['per_post_rating_summary'] / 100 * 5;
                ?>
,
							readOnly: true,
							hintList: ['', '', '', '', '']
						});
					});
				</script>
				<?php 
                $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $average_rating['post_id'] . '" style="margin: 0;"></div>';
            }
            $show .= '</div>';
            // echo   $show;
        } else {
            //var_dump('I am here');
            //$show = '';
            if (!empty($post_ids) && !empty($form_ids)) {
                //$position = 30;
                foreach ($post_ids as $post_id) {
                    //$average_ratings = CBRatingSystemData::get_ratings($form_id,$post_id);
                    //$option=array('post_id'=>$post_id,'form_id'=>$form_id);
                    //unset( $whrOpt );
                    $option = array();
                    $option['form_id'] = $form_ids;
                    $option['post_id'] = array($post_id);
                    $average_rating = CBRatingSystemData::get_ratings_summary($option);
                    if (!sizeof($average_rating)) {
                        $average_rating['form_id'] = $form_ids[0];
                        $average_rating['post_id'] = $post_ids[0];
                        $average_rating['post_title'] = get_the_title($post_ids[0]);
                        $average_rating['per_post_rating_summary'] = 0;
                        $average_rating['found'] = 0;
                    } else {
                        $average_rating = $average_rating[0];
                        $average_rating['found'] = 1;
                    }
                    $show .= '<div class="cbratingavgratelist" style="position:relative;">';
                    if ($show_title == 1) {
                        $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
                    }
                    if ($show_form_id == 1) {
                        $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '<p>';
                    }
                    if ($show_text == 1) {
                        $show .= '<p>' . $text_label . '' . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5<p>';
                    }
                    $clip_back = 120;
                    $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
                    if ($show_star == 1) {
                        ?>
						<script>
							jQuery(document).ready(function ($) {
								$('.cbrp-alone-rated<?php 
                        echo $post_id;
                        ?>
').raty({
									half    : true,
									path    : '<?php 
                        echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                        ?>
',
									score   : <?php 
                        echo $average_rating['per_post_rating_summary'] / 100 * 5;
                        ?>
,
									readOnly: true,
									hintList: ['', '', '', '', '']
								});
							});
						</script>
						<?php 
                        $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $post_id . '" style="margin: 0;"></div>';
                    }
                    $show .= '</div>';
                    //$position += 30;
                }
                //echo $show;
            }
        }
        return $show;
    }
Пример #2
0
    /**
     * @param array $args
     * @param array $instance
     */
    function widget($args, $instance)
    {
        global $wpdb;
        extract($args);
        $widget_id = $args['widget_id'];
        // var_dump($widget_id);
        CBRatingSystem::load_scripts_and_styles();
        $posttype = $instance['posttype'];
        $date = $instance['timelimit'];
        $limit = $instance['resultlimit'];
        $form_id = $instance['form_id'];
        $user_id = $instance['user_id'];
        $post_id = $instance['post_id'];
        $post_filter = $instance['post_filter'];
        $order = $instance['order'];
        $firstorder = $instance['firstorder'];
        if ($date != 0) {
            $date = self::get_calculated_date($date);
            $whrOptn['post_date'] = $date;
        }
        $whrOptn['post_type'] = $posttype;
        $whrOptn['form_id'] = $form_id;
        //added from v3.2.20
        $whrOptn['user_id'] = $user_id;
        $whrOptn['form_id'] = $form_id;
        //added from v3.2.20
        $whrOptn['post_id'] = $post_id;
        $whrOptn['post_filter'] = $post_filter;
        //added from v3.2.20
        $whrOptn['order'] = $order;
        //added from v3.2.20
        $whrOptn['firstorder'] = $firstorder;
        $data = CBRatingSystemData::get_top_rated_post($whrOptn, false, $limit);
        $title = empty($options['widget_title']) ? __('Top Rated Posts', 'cbratingsystem') : $instance['widget_title'];
        $title = apply_filters('widget_title', $instance['title']);
        echo $before_widget;
        echo $before_title . $title . $after_title;
        ?>


        <ul class="cbrp-top-rated-wpanel" style="">
            <?php 
        if (!empty($data)) {
            ?>


          <!--          <td style=""> <?php 
            /*echo 'Name'; */
            ?>
</td>
                    <td style=""> <?php 
            /*echo 'Post '; */
            ?>
</td>
                    <td style=""> <?php 
            /*echo 'Rating'; */
            ?>
</td>
-->


                <?php 
            foreach ($data as $newdata) {
                ?>

                    <li>
                        <?php 
                $author_info = get_userdata((int) $newdata['post_author']);
                ?>
                        <div style=""> <a style="" href="<?php 
                echo get_author_posts_url((int) $newdata['post_author']);
                ?>
"><?php 
                echo $author_info->display_name;
                ?>
</a></div>
                         <div style=""> <?php 
                echo $newdata['post_count'];
                ?>
 Posts</div>
                        <?php 
                $rating = $newdata['rating'] / 100 * 5;
                ?>
                        <script>
                            jQuery(document).ready(function ($) {
                                $('#cbrp-top-rated<?php 
                echo $newdata['post_author'] . '_' . $widget_id;
                ?>
').raty({
                                    half    : true,
                                    path    : '<?php 
                echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                ?>
',
                                    score   : <?php 
                echo number_format($rating, 2, '.', '');
                ?>
,
                                    readOnly: true,
                                    hintList: ['', '', '', '', '']
                                });
                            });
                        </script>
                                   <?php 
                echo "<strong>" . number_format($rating, 2, '.', '') . "/5</strong> ";
                ?>

                                    <div id ="cbrp-top-rated<?php 
                echo $newdata['post_author'] . '_' . $widget_id;
                ?>
" style=""></div>

                          </li>
                <?php 
            }
            ?>
            <?php 
        } else {
            ?>
                <li><?php 
            _e('No Results found', 'cbratingsystem');
            ?>
</li>
            <?php 
        }
        ?>
        </ul>
        <?php 
        echo $after_widget;
    }