Posted by AChamp on May 4, 2007 at 7:36pm
| Project: | Voting API |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (won't fix) |
Issue Summary
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.
Comments
#1
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.
#2
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
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
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
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.
#6
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.