Beispiel #1
0
 /**
  * Displays a rating results list. This is used by the Rating Result List widet and shortcode.
  * 
  * @param unknown_type $params
  * @return string
  */
 public static function display_rating_results_list($params = array())
 {
     $general_settings = (array) get_option(Multi_Rating::GENERAL_SETTINGS);
     $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS);
     $style_settings = (array) get_option(Multi_Rating::STYLE_SETTINGS);
     $font_awesome_version = $style_settings[Multi_Rating::FONT_AWESOME_VERSION_OPTION];
     $icon_classes = MR_Utils::get_icon_classes($font_awesome_version);
     $use_custom_star_images = $style_settings[Multi_Rating::USE_CUSTOM_STAR_IMAGES];
     $image_width = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_WIDTH];
     $image_height = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_HEIGHT];
     extract(wp_parse_args($params, array('title' => $custom_text_settings[Multi_Rating::RATING_RESULTS_LIST_TITLE_TEXT_OPTION], 'before_title' => '<h4>', 'after_title' => '</h4>', 'no_rating_results_text' => $custom_text_settings[Multi_Rating::NO_RATING_RESULTS_TEXT_OPTION], 'show_count' => true, 'echo' => true, 'show_category_filter' => true, 'category_id' => 0, 'limit' => 10, 'show_rank' => true, 'result_type' => Multi_Rating::STAR_RATING_RESULT_TYPE, 'show_title' => true, 'class' => '', 'taxonomy' => null, 'term_id' => 0, 'filter_button_text' => $custom_text_settings[Multi_Rating::FILTER_BUTTON_TEXT_OPTION], 'category_label_text' => $custom_text_settings[Multi_Rating::FILTER_LABEL_TEXT_OPTION], 'show_featured_img' => true, 'image_size' => 'thumbnail', 'sort_by' => 'highest_rated', 'filter_label_text' => $custom_text_settings[Multi_Rating::FILTER_LABEL_TEXT_OPTION], 'show_filter' => false)));
     // temp
     if (is_string($show_category_filter)) {
         $show_category_filter = $show_category_filter == 'true' ? true : false;
         $show_filter = $show_category_filter;
     }
     if (is_string($show_filter)) {
         $show_filter = $show_filter == 'true' ? true : false;
     }
     if (is_string($show_count)) {
         $show_count = $show_count == 'true' ? true : false;
     }
     if (is_string($echo)) {
         $echo = $echo == 'true' ? true : false;
     }
     if (is_string($show_rank)) {
         $show_rank = $show_rank == 'true' ? true : false;
     }
     if (is_string($show_title)) {
         $show_title = $show_title == 'true' ? true : false;
     }
     if (is_string($show_featured_img)) {
         $show_featured_img = $show_featured_img == 'true' ? true : false;
     }
     // show the filter for taxonomy
     if ($show_filter == true && isset($_REQUEST['term-id'])) {
         // override category id if set in HTTP request
         $term_id = $_REQUEST['term-id'];
     }
     if ($show_filter && $taxonomy == null) {
         $taxonomy = 'category';
     }
     if ($category_id != 0) {
         $term_id = $category_id;
         $taxonomy = 'category';
     }
     if ($term_id == 0) {
         $term_id = null;
         // so that all terms are returned
     }
     $rating_results = Multi_Rating_API::get_rating_results(array('limit' => $limit, 'taxonomy' => $taxonomy, 'term_id' => $term_id, 'result_type' => $result_type, 'sort_by' => $sort_by));
     ob_start();
     mr_get_template_part('rating-result', 'list', true, array('show_title' => $show_title, 'show_count' => $show_count, 'show_filter' => $show_filter, 'category_id' => $category_id, 'before_title' => $before_title, 'after_title' => $after_title, 'title' => $title, 'show_rank' => $show_rank, 'no_rating_results_text' => $no_rating_results_text, 'result_type' => $result_type, 'taxonomy' => $taxonomy, 'term_id' => $term_id, 'filter_button_text' => $filter_button_text, 'filter_label_text' => $filter_label_text, 'show_featured_img' => $show_featured_img, 'image_size' => $image_size, 'show_rich_snippets' => false, 'class' => $class . ' rating-results-list', 'rating_results' => $rating_results, 'before_count' => '(', 'after_count' => ')', 'ignore_count' => false, 'preserve_max_option' => false, 'before_date' => '', 'after_date' => '', 'icon_classes' => $icon_classes, 'use_custom_star_images' => $use_custom_star_images, 'image_width' => $image_width, 'image_height' => $image_height));
     $html = ob_get_contents();
     ob_end_clean();
     $html = apply_filters('mr_template_html', $html);
     if ($echo == true) {
         echo $html;
     }
     return $html;
 }
 /**
  * Tests rating result list
  * 
  * @group func2
  */
 public function test_rating_result_list1()
 {
     global $wpdb;
     $results = $wpdb->insert($wpdb->prefix . Multi_Rating::RATING_ITEM_TBL_NAME, array('description' => 'Testing', 'max_option_value' => 5));
     $rating_item_id = $wpdb->insert_id;
     $post_ids = $this->factory->post->create_many(5);
     $user_id1 = $this->factory->user->create(array('role' => 'administrator'));
     $user_id2 = $this->factory->user->create(array('role' => 'subscribor'));
     $post_ratings = array(array(array(5, '2015/01/01 00:00:00', $user_id1, null), array(5, '2015/02/01 00:00:00', $user_id2, null), array(5, '2015/03/01 00:00:00', null, null)), array(array(1, '2015/01/01 00:00:00', $user_id1), array(2, '2015/02/01 00:00:00', $user_id2), array(1, '2015/03/01 00:00:00', null, null), array(2, '2015/04/01 00:00:00', null, null)), array(array(3, '2015/01/01 00:00:00', $user_id1), array(1, '2015/02/01 00:00:00', null), array(1, '2015/03/01 00:00:00', null, null)), array(array(5, '2015/01/01 00:00:00', null, null), array(4, '2015/02/01 00:00:00', null, null)), array(array(5, '2015/01/01 00:00:00', $user_id2, null)));
     $rating_entry_ids = array();
     $index = 0;
     foreach ($post_ids as $post_id) {
         $post_ratings_data = $post_ratings[$index];
         foreach ($post_ratings_data as $post_ratings_data) {
             $data = array('post_id' => $post_id, 'entry_date' => $post_ratings_data[1]);
             $data_format = array('%d', '%s');
             if (is_numeric($post_ratings_data[2])) {
                 $data['user_id'] = $post_ratings_data[2];
                 array_push($data_format, '%d');
             }
             $wpdb->insert($wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_TBL_NAME, $data, $data_format);
             $rating_entry_id = $wpdb->insert_id;
             array_push($rating_entry_ids, $rating_entry_id);
             $wpdb->insert($wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_VALUE_TBL_NAME, array('rating_item_entry_id' => $rating_entry_id, 'rating_item_id' => $rating_item_id, 'value' => $post_ratings_data[0]), array('%d', '%d', '%d'));
         }
         $index++;
     }
     // highest rated
     $rating_result_list = Multi_Rating_API::get_rating_results(array());
     $this->assertEquals(5, count($rating_result_list));
 }