Should cache table store Zero Vote values on new node creation?

AChamp - May 4, 2007 - 19:36
Project:Voting API
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

I have the latest version of Voting API, and I still cannot get Views to display storylink nodes with 0 votes. Should this have been corrected in this version? Is there a fix? I've tried a "sum'" result less than a particular number, and I've tried a combination of "greater than or equal to 0" with "less than" a particular number of votes. Nothing seems to display nodes with 0 votes. Thanks for the help.

#1

sudeoo - August 15, 2007 - 10:05
Status:active» needs work

Dear AChamp,

try the following code in votingapi_views.inc in votingapi module.

replacing (line 212):
$query->add_where("%s %s %d", $field, $filter['operator'], $filter['value']);

with:
if (( $filter['operator'] == "<") || ( $filter['operator'] == "<=") ){
$query->add_where("$field is NULL OR %s %s %d", $field, $filter['operator'], $filter['value']);
} else {
$query->add_where("%s %s %d", $field, $filter['operator'], $filter['value']);
}

The patch (i donot have cvs installed and therefore, cannot create patch correctly using cvs diff and then this one is my first patches), therefore, somebody has to verify it before commiting to the CVS.

AttachmentSize
votingapi_views.patch 686 bytes

#2

webastien - September 26, 2007 - 16:18

I had the same problem...
but line 212 is note the same (I use last 4.7 official release of votingapi).

An other tips to add "zero vote" to your views, is to call the "_votingapi_insert_cache_result" function like this :

_votingapi_insert_cache_result('node', $nid, 0, 'percent', 'rating', 'count');
_votingapi_insert_cache_result('node', $nid, 0, 'percent', 'rating', 'average');

It requires any modification of the module if you put this code in a hook, in my case, hook_noapi : $op = insert.

#3

joshk - December 13, 2007 - 18:46
Title:Zero Vote» Should cache table store Zero Vote values on new node creation?

I'm curious whether or not eaton thinks this is a use-case that votingapi should handle: storing "zeros" in the cache table on node-creation. Currently, without something that works around this, combining votes and views to sort by rating is semi-broken out of the box because ranking nodes by sum(points) will put a node with -10 above a node with 0 (no votes), because at the sql level it's NULL, which always comes last.

Perhaps this is really an issue with the various voting modules though, in that they define the types of votes to be scored.

#4

Scott Reynolds - December 13, 2007 - 20:27

I have worked my way around this issue by using a custom module that, on node insert, adds a cache record of 0 votes.

I would not suggest doing a votingapi_set_vote() but rather a direct insertion into the cache.

#5

codenamerhubarb - February 18, 2008 - 13:33

Or replacing $query->add_where("%s %s %d", $field, $filter['operator'], $filter['value']); with the following worked for me...(using 5.x-1.5)

if (( $filter['value'] == "0") || ( $filter['value'] === NULL) ){
$query->add_where("$field is NULL OR %s %s %d", $field, $filter['operator'], $filter['value']);
} else {
$query->add_where("%s %s %d", $field, $filter['operator'], $filter['value']);
}

Check out http://downloadabook.net/ebooks/price for an example of filtering a list view by minimum average vote, using 0% as a possible value.

 
 

Drupal is a registered trademark of Dries Buytaert.