When I created a view, if I add any fields related to VotingAPI (i.e. "VotingAPI: Voting results"), the view only shows the contents (nodes) that have been voted. This behaves like a filter which it shouldn't.

I tried to manually populate the "votingAPI_cache" table and gave every node a default voting score of 0. This actually fixed the problem and every node showed up in the view. But it broke the voting module so it is still a no go.

A rather tedious fix will be to vote each node manually which will take forever. Just wondering if there is a better solution for this? Thanks.

Comments

everbright’s picture

Ok, I digged a little deep into the code. I was looking at the MySQL query generated from the devel module:

SELECT 	count(node.nid) 
FROM 	node node 
.....
LEFT JOIN 
	votingapi_cache votingapi_cache 
ON 	node.nid = votingapi_cache.content_id 
AND 	votingapi_cache.content_type = 'node' 
WHERE 	(node.type 
	IN ('content-links')) 
AND 	((term_node.tid = '2')) 
// @@ The following three equal statements limited the result set to the ones that only have been voted
AND 	(votingapi_cache.value_type = 'percent')  
AND 	(votingapi_cache.tag = 'vote') 
AND 	(votingapi_cache.function = 'average')

As I commented in the code, although it is a left join, if you use the columns from the right table in the where clause, the result set will be restricted to that table. Move those up to right after "left join ... on ... " should solve the problem. Something like:

SELECT 	count(node.nid) 
FROM 	node node 
.....
LEFT JOIN 
	votingapi_cache votingapi_cache 
ON 	node.nid = votingapi_cache.content_id 
AND 	votingapi_cache.content_type = 'node' 
// @@ This is the right place
AND 	(votingapi_cache.value_type = 'percent')  
AND 	(votingapi_cache.tag = 'vote') 
AND 	(votingapi_cache.function = 'average')
WHERE 	(node.type 
	IN ('content-links')) 
AND 	((term_node.tid = '2')) 

I will try to put a patch for this (never done one before). Meanwhile, any suggestions or comments are welcome.

everbright’s picture

Project: Views (for Drupal 7) » Voting API
Component: Views Data » Miscellaneous

After some research, it seems to be an issue with the VotingAPI and its integration with Views.

everbright’s picture

After spending half a day, I gave up on the patch idea. I did a quick fix though to fit my needs. Below is my hack if anyone is insterested:

1. In the votingapi_views_tables() function (located in the votingapi_views.inc file), change:

......
"extra" => array(
        'content_type' => 'node',
      ),
......

to

"extra" => array(
        'content_type' => 'node',
	// Following three columns are added to the "left join ... on ..." part of the query
        'value_type' => 'percent',
		'tag' => 'vote',
		'function' => 'average'
      ),

2. Also comment out most part of the votingapi_views_value_query_handler function:

function votingapi_views_value_query_handler($field, $fieldinfo, &$query) {
  $table = $field['tablename'];
  /* Comment out this portion
  if (is_string($field['options'])) {
    $options = unserialize($field['options']);
    if (is_array($options)) {
      foreach ($options as $column => $value) {
        $query->add_where("$table.$column = '$value'");
      }
    }
  }*/
}

Question: I couldn't figure out how to programmably change the "extra" field of the table array using the "option" values. Any ideas?

eaton’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Active » Fixed

As of this evening at 2:06 AM, views integration for VotingAPI has been rewritten from scratch. All hail views! The good news? It should actually work. The bad news? You'll need to remove and re-add any VotingAPI fields that you had on existing Views. This shouldn't be problematic, as the old views integration was completely broken anyhow.

Caveats: Output formatting of vote results, etc is still being finished. In addition, much more testing is needed before it can be said that the new integration code is 'ready for prime time.' But it's definitely much better. I'm going to be closing the existing threads regarding VotingAPI and Views because all of them point to known issues with the *old* versions of the code. Those interested in testing the new code can download the latest VotingAPI from: http://drupal.org/node/128605

Thanks for your patience!

Anonymous’s picture

Status: Fixed » Closed (fixed)