I'm using rate with value type options in a view. I want to know how I can sort by the highest rated in each option. You can see this up at http://ideapals.org If you scroll down past the "under construction" graphic. Each option is an emotion like "Train Wreck", "Brilliant", etc. I need to be able to make a top list that shows the top ideas voted 'brilliant' etc. I used a node relationship, and I can get the votes to show up in views, the rating is working perfectly, but I need to know how to sort by the highest votes in a particular option? Ideas, advice, solutions? BTW, LOVE the module.

Comments

mauritsl’s picture

Status: Active » Fixed

I was unsure if this is possible in views, but I got it working :)

Not many people seems to be doing this, as it results in a SQL error in views. I wrote a patch which fixes this bug, please refer to:
http://drupal.org/node/937998#comment-3658114

Apply that patch before we begin, you won't get it working otherwise.

The configuration is far from straightforward, but I'll explain. Start with a relationship to "Vote results" (you will find it under the category "Node"). The options you have to use here are different from the configuration as described in the readme file.

* Require this relationship: check this box
* Value type: other, fill in "option"
* Vote tag: same value as used in the rate widget configuration
* Aggregation function: Other, fill in "option-2", where 2 is the value of the option (visible in the rate widget configuration). You may use another value than 2 of course.

Now add a sort criteria on "Vote results: Value". Under "Relationship", select the relationship you just created. Ordering has to be descending.

Add a field with the type "Vote results: Value". Use the same relationship and choose the rate widget under "Appearance".

You have to create a display for each option. Only the value used for the aggregation function in the relationship has to be different, as that option determines what rate button the view is for.

And here is an export of my view:

$view = new view;
$view->name = 'rate';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'votingapi_cache' => array(
    'label' => 'Vote results',
    'required' => 1,
    'votingapi' => array(
      'value_type' => 'option',
      'tag' => 'vote',
      'function' => 'option-2',
    ),a
    'id' => 'votingapi_cache',
    'table' => 'node',
    'field' => 'votingapi_cache',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'type' => array(
    'label' => 'Type',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 1,
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'value' => array(
    'label' => 'Rate widget',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'set_precision' => 0,
    'precision' => '0',
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'appearance' => 'rate_views_widget_compact',
    'exclude' => 0,
    'id' => 'value',
    'table' => 'votingapi_cache',
    'field' => 'value',
    'relationship' => 'votingapi_cache',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('sorts', array(
  'value' => array(
    'order' => 'DESC',
    'id' => 'value',
    'table' => 'votingapi_cache',
    'field' => 'value',
    'relationship' => 'votingapi_cache',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'ratings');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

N1L’s picture

You are awesome mate! Thanks for that patch.

mrweiner’s picture

Version: 6.x-1.0-beta5 » 7.x-2.x-dev
Status: Closed (fixed) » Active

I've come across this exact same issue in D7, and need this functionality for my site. Does anybody know if this should have been fixed, or how to fix it? I looked at the patch linked in the first comment, but it doesn't look like it can be applied to the current version of Voting API.

mrweiner’s picture

Version: 7.x-2.x-dev » 7.x-1.3

Sorry, wrong version selected. :(

mototribe’s picture

Status: Active » Closed (works as designed)
mrweiner’s picture

Category: support » bug
Status: Closed (works as designed) » Active

Well, if that is the way that it is supposed to work, then I'm changing this to a bug report. If I have an "options" widget setup, and everything configured as laid out in that thread and elsewhere, the sort does not work. Both ascending and descending show the results in the same order, and neither of them are remotely correct.

The options in my widget are "Helpful" and "Unhelpful". Before I stopped trying to figure this problem out, the view's sorts would show one node with a vote of "Helpful", one node with a vote of "Unhelpful", and then the rest in no reasonable order. I can provide an export of the view, or anything else that's required, if somebody tells me what they would need to help diagnose the problem.

mrweiner’s picture

Status: Active » Closed (works as designed)

Of course, I decide to try it one more time, and it works. Not sure what I was doing wrong before.

mrweiner’s picture

Title: How to sort by options voting in views » Sorting by "options" results seems to be broken.
Status: Closed (works as designed) » Active

Sorry to clog up the issue page, but this seems to not actually be working for me. It only appeared to be working momentarily. The random results, as described below, just happened to appear in the order which seemed to be correct. To give an example of the issues, my rate widget type is "options". The options of the widget are Helpful, with a value of 1, and Unhelpful, with a value of -1. With the relationship configured as it should be, and without an "aggregation function" (image 1):

In descending mode, they are shown in no particular order, with voted nodes first and non-voted nodes after.
In ascending mode, the results are reversed. Non-voted nodes are shown first, and then voted nodes are shown in the opposite order from before.

With the same relationship configuration, but with an aggregation function of "Total score" (image 2):

Both ascending and descending appear to sort by a completely random order. It doesn't seem to be sorted by anything related to the votes themselves or other aspects of the node.

If this is the intended functionality of the module, then I am rather baffled.

xandeadx’s picture

Module for 6.x branch allowing sort on average value Yes/No widget — http://drupal.org/sandbox/xandeadx/1790062

scoffield’s picture

Version: 7.x-1.3 » 7.x-1.4
Issue tags: -view +rate, +drupal 7

Does anybody have a solution to sort nodes by "options" with views in the version 1.4 of rate module.
I try to sort nodes by total sum of yes/no, but it s not working with drupal 7, votingapi and rate updated.
I did not see my options when i had a relationship in a view. I only saw "no filters" or "normal vote".

Or am i doing this false ? Did views and rate work on your website ?

ymakux’s picture

scoffield: same situation. In my case I need to display 5 most useful comments (yes/no widget).

ymakux’s picture

Ok, got it (comments)

$view = new view();
$view->name = 'product_reviews';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'comment';
$view->human_name = 'Product reviews';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Product reviews';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['uses_fields'] = TRUE;
$handler->display->display_options['row_plugin'] = 'comment';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'Be first to review this product';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
/* Relationship: Comment: Content */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'comment';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
$handler->display->display_options['relationships']['nid']['required'] = TRUE;
/* Field: Comment: Title */
$handler->display->display_options['fields']['subject']['id'] = 'subject';
$handler->display->display_options['fields']['subject']['table'] = 'comment';
$handler->display->display_options['fields']['subject']['field'] = 'subject';
$handler->display->display_options['fields']['subject']['label'] = '';
$handler->display->display_options['fields']['subject']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['subject']['alter']['ellipsis'] = FALSE;
/* Field: Comment: Author */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'comment';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['link_to_user'] = FALSE;
/* Field: Comment: Edit link */
$handler->display->display_options['fields']['edit_comment']['id'] = 'edit_comment';
$handler->display->display_options['fields']['edit_comment']['table'] = 'comment';
$handler->display->display_options['fields']['edit_comment']['field'] = 'edit_comment';
$handler->display->display_options['fields']['edit_comment']['label'] = '';
$handler->display->display_options['fields']['edit_comment']['element_label_colon'] = FALSE;
/* Field: Comment: Post date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'comment';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = '';
$handler->display->display_options['fields']['created']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created']['date_format'] = 'custom';
$handler->display->display_options['fields']['created']['custom_date_format'] = 'd.m.Y';
/* Field: Comment: Reply-to link */
$handler->display->display_options['fields']['replyto_comment']['id'] = 'replyto_comment';
$handler->display->display_options['fields']['replyto_comment']['table'] = 'comment';
$handler->display->display_options['fields']['replyto_comment']['field'] = 'replyto_comment';
$handler->display->display_options['fields']['replyto_comment']['label'] = '';
$handler->display->display_options['fields']['replyto_comment']['element_label_colon'] = FALSE;
/* Sort criterion: Comment: Thread */
$handler->display->display_options['sorts']['thread']['id'] = 'thread';
$handler->display->display_options['sorts']['thread']['table'] = 'comment';
$handler->display->display_options['sorts']['thread']['field'] = 'thread';
$handler->display->display_options['sorts']['thread']['order'] = 'DESC';
/* Sort criterion: Comment: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'comment';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['relationship'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Comment: Approved */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'comment';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status_node']['id'] = 'status_node';
$handler->display->display_options['filters']['status_node']['table'] = 'node';
$handler->display->display_options['filters']['status_node']['field'] = 'status';
$handler->display->display_options['filters']['status_node']['relationship'] = 'nid';
$handler->display->display_options['filters']['status_node']['value'] = 1;
$handler->display->display_options['filters']['status_node']['group'] = 1;
$handler->display->display_options['filters']['status_node']['expose']['operator'] = FALSE;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['use_more_always'] = FALSE;
$handler->display->display_options['defaults']['use_more_always'] = FALSE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['defaults']['use_more_text'] = FALSE;
$handler->display->display_options['use_more_text'] = 'Смотреть все отзывы';
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['relationships'] = FALSE;
/* Relationship: Comment: Content */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'comment';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
$handler->display->display_options['relationships']['nid']['required'] = TRUE;
/* Relationship: Comment: Vote results */
$handler->display->display_options['relationships']['votingapi_cache']['id'] = 'votingapi_cache';
$handler->display->display_options['relationships']['votingapi_cache']['table'] = 'comment';
$handler->display->display_options['relationships']['votingapi_cache']['field'] = 'votingapi_cache';
$handler->display->display_options['relationships']['votingapi_cache']['votingapi'] = array(
  'value_type' => 'option',
  'tag' => 'comment',
  'function' => '',
);
$handler->display->display_options['defaults']['sorts'] = FALSE;
/* Sort criterion: Vote results: Function */
$handler->display->display_options['sorts']['function']['id'] = 'function';
$handler->display->display_options['sorts']['function']['table'] = 'votingapi_cache';
$handler->display->display_options['sorts']['function']['field'] = 'function';
$handler->display->display_options['sorts']['function']['relationship'] = 'votingapi_cache';
$handler->display->display_options['sorts']['function']['order'] = 'DESC';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Comment: Approved */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'comment';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status_node']['id'] = 'status_node';
$handler->display->display_options['filters']['status_node']['table'] = 'node';
$handler->display->display_options['filters']['status_node']['field'] = 'status';
$handler->display->display_options['filters']['status_node']['relationship'] = 'nid';
$handler->display->display_options['filters']['status_node']['value'] = 1;
$handler->display->display_options['filters']['status_node']['group'] = 1;
$handler->display->display_options['filters']['status_node']['expose']['operator'] = FALSE;
$translatables['product_reviews'] = array(
  t('Master'),
  t('Product reviews'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Be first to review this product'),
  t('Content'),
  t('All'),
  t('Block'),
  t('All reviews'),
  t('Vote results'),
);
mrweiner’s picture

@ymakux: Would you mind describing what you did to get it working?

pradyumnahpt’s picture

Version: 7.x-1.4 » 7.x-1.6

Even I too have a problem sorting the comments from views based on the number of votes, even after following steps mentioned in readme,and the patch in comment #1 cannot be applied for latest recommended release. I am using points value type.and the sort is not stable,It appears to sort correctly sometimes but the sort functionality is not working.Any one please guide to get it right..

Thankyou

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)
Issue tags: -rate, -drupal 7

Drupal 7 is EOL. Issue will be closed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.