I am trying to create a view page that user can list all nodes that they have voted on. This view will show the node title, the users vote, the average user vote and the number of votes.

I created the view and it worked fine, except that all nodes are duplicated by the number of votes, because the “VotingAPI percent vote user” filter is not working correctly. I had a look at the SQL being generated for the view and then started hacking at the votingapi_views.inc file. Now I don’t know the views api at all and I know just as much about the votingapi, but I think I found the problem.

The filter is not adding a where clause for the user (eg uid = 1).

The following is what I added at the end of my votingapi_handler_filter_uid_voted() function, and now it seems to work.

I don’t want to use this in a production system before somebody more knowledgeable tells it’s correct.

votingapi_views.inc,v 1.11.2.5

function votingapi_handler_filter_uid_voted($op, $filter, $filterinfo, &$query) {
  ... 
  ...
  
  if ($filter['value'] == '***CURRENT_USER***') {
    $query->add_where('votingapi_vote_'. $filterinfo['tag'] .'_'. $filterinfo['value_type'] .'.uid = ***CURRENT_USER***');
  }
}

Comments

ShutterFreak’s picture

Status: Needs review » Active

Subscribing to this issue, as I experience the same behavior. Your patch however doesn't seem to work on my system (I use VotingAPI + jRating), so I have set the status to "active".

I am not sure whether it is a VotingAPI or a jRating issue.

If you import the followign view (without the opening and closing PHP tags), you'll see that when other people also rated a given page you have rated, you'll see duplicate entries:

  $view = new stdClass();
  $view->name = 'view_my_rated_pages';
  $view->description = 'My Rated Pages';
  $view->access = array (
  );
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'My Rated Pages';
  $view->page_header = '';
  $view->page_header_format = '3';
  $view->page_footer = '';
  $view->page_footer_format = '3';
  $view->page_empty = '';
  $view->page_empty_format = '3';
  $view->page_type = 'table';
  $view->url = 'view/pages/my/by/relevance';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '0';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink_with_mark',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node',
      'field' => 'changed',
      'label' => 'Last update',
      'handler' => 'views_handler_field_date_small',
    ),
    array (
      'tablename' => 'votingapi_vote_vote_percent',
      'field' => 'currentuservalue',
      'label' => 'My rating',
      'handler' => 'votingapi_views_formatter_cleaned',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'page',
),
    ),
    array (
      'tablename' => 'votingapi_cache_vote_percent_count',
      'field' => 'value',
      'operator' => '>',
      'options' => '',
      'value' => '0',
    ),
    array (
      'tablename' => 'votingapi_vote_vote_percent',
      'field' => 'uid',
      'operator' => 'IS NOT NULL',
      'options' => '',
      'value' => '***CURRENT_USER***',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, votingapi_vote_vote_percent, votingapi_cache_vote_percent_count);
  $views[$view->name] = $view;

The problem disappears when I decide to not show the vote for the current user, like in the following view:

  $view = new stdClass();
  $view->name = 'view_my_rated_pages';
  $view->description = 'My Rated Pages';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'My Rated Pages';
  $view->page_header = '';
  $view->page_header_format = '3';
  $view->page_footer = '';
  $view->page_footer_format = '3';
  $view->page_empty = '';
  $view->page_empty_format = '3';
  $view->page_type = 'table';
  $view->url = 'view/pages/my/by/relevance';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '0';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink_with_mark',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node',
      'field' => 'changed',
      'label' => 'Last update',
      'handler' => 'views_handler_field_date_small',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'page',
),
    ),
    array (
      'tablename' => 'votingapi_cache_vote_percent_count',
      'field' => 'value',
      'operator' => '>',
      'options' => '',
      'value' => '0',
    ),
    array (
      'tablename' => 'votingapi_vote_vote_percent',
      'field' => 'uid',
      'operator' => 'IS NOT NULL',
      'options' => '',
      'value' => '***CURRENT_USER***',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, votingapi_cache_vote_percent_count, votingapi_vote_vote_percent);
  $views[$view->name] = $view;

My guess is that something's wrong at the level of a JOIN in a SQL query.

Best regards,

Olivier

ShutterFreak’s picture

The problem was fixed in my situation by adding the "Node: distinct" filter to the view.

When adding this filter, make sure you click once on the "distinct" option or you'll get an error message when saving the view.

Best regards,

Olivier

keithorama’s picture

I tried the Node: Distinct fix and it didn't work - it showed only one row per node, yes, but the score given was not the correct one for the current user.

Looks like this is fixed in 5.x-1.x-dev. There is a new field type called 'VotingAPI points vote value (current user only)', which solves the problem.

ShutterFreak’s picture

You are right - my fix does not show the correct ratings for the users.

timb’s picture

uid = 1 will always give you the admin user! You want to load the current user number $user->uid

eaton’s picture

Status: Active » Closed (won't fix)

Support for the 5.x branch of VotingAPI has ended with the release of Drupal 7 and the upcoming release of VotingAPI 7.x-2.4.