Hi, and thanks for creating a great module!

There's something I either don't know how to do or isn't possible:

Let's say I have 100 nodes of a particular type, which has been set to be votable. Only 40 have ever been voted on thus far. I also have a View that creates a table to list all nodes of this type. Among that table's columns is one for average rating (i.e., it's a field in the View).

Here's the problem: only the 40 nodes that've been voted on show up in the table! (If I remove the rating column/field from the View, all 100 nodes show up.)

Is there a way to have a default value be inserted for all unvoted-on nodes (of the applicable type) so that those nodes are NOT excluded from a Views query result? I.e., to have their average rating value be zero or something?

(Should I go into the database and manually add records to the cache table for all unvoted-on nodes? If so, should those records indicate 0 votes with an average rating of 0? Might that cause a divide-by-zero error somewhere?)

Thank you!!

Comments

hickory’s picture

Project: jRating » Voting API

You probably need an "OR whatever = NULL" in the filter handler. There's discussion of this somewhere on drupal.org, I think.

ardee-1’s picture

Thanks. I may need just a bit more info on how to do that. Can you help? (I couldn't find the applicable discussion.)

jo1ene’s picture

ardee-1’s picture

Well, now this discussion points to another discussion, which points back here. Both point out the same problem and NEITHER has a solution! :-(

jo1ene’s picture

The other thread was marked as a duplicate. It points to this one to show WHY it's a duplicate.

This thread points to that one FYI.

ardee-1’s picture

I know, but was still hoping for a solution.

[begins whining]
It looks like I'll have to stop using Views and learn how to do the queries "manually." Also how to build a table with the results, with sortable columns, filtering, paging, and theming. So much for saving time using the powerful features of a CMS. One little snag and you're on your own.
[ends whining]

hickory’s picture

Try the fix in comment #7 here: http://drupal.org/node/63430

ardee-1’s picture

hickory, THANKS!!

That patch fixes the problem, plain and simple.

I think it's pretty elegant (the code change is very straightforward and understandable). Now "no votes" shows up in the table in the vote column, which is quite reasonable.

I don't know if it's common for people to customize (patch) their copies of modules; in the past I might have been hesitant to do so because such patches might get lost upon updating modules. But at this point, I'm happy to do it.

THANK YOU for pointing out the applicable discussion; THAT is the discussion that this one (and the other one recently mentioned) should be considered duplicates of. My searches had failed to turn it up. You've done the Drupal world a great service!

eaton’s picture

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!

ardee-1’s picture

Wow, good work late into the night!

I look forward to upgrading, but may hold off until you say it's really "finished."

eaton’s picture

Thanks! Please note that that current version IS a huge improvement over what was there, even if there are still some rough edges to smooth out. Any testing is much appreciated!

ardee-1’s picture

I went to get the latest and test it, but I'm using 4.7.x and I see that it's for 5.x. I thus assume that I can't use it ... right? Will the same improvments be available for 4.7.x?

eaton’s picture

Ardee, once I've established that they work I'll be backporting them to 4.7. Although, I *believe* that the views integration file is actually compatible with both 4.7 and 5.0. You should be able to use the file from the latest 5.0 dev snapshot on your VotingAPI 4.7 installation.

Again, once I get some additional test data back from other users I'll put it into both versions.

Anonymous’s picture

Status: Fixed » Closed (fixed)
sudeoo’s picture

try the following code in votingapi_views.inc in votingapi module for Drupal 5.x-1.x-dev:

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']);
}