Found that no results were being returned from votingapi_select_votes() and votingapi_select_results() when specifiying timestamp as part of criteria array. The API comments suggested that specifying a timestamp would return all records with a time larger than specified timestamp, however the resulting SQL query tried to do an '=' instead of a '>' resulting in an empty set. Proposed fix:

foreach ($criteria as $key => $value) {
if($key == 'timestamp' && !empty($value)) {
$query->condition($key, $value, is_array($value) ? 'IN' : '>');
} else {
$query->condition($key, $value, is_array($value) ? 'IN' : '=');
}
}

votingapi_select_votes() and votingapi_select_results() now return results when using timestamp in criteria array.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guldi’s picture

Status: Active » Needs review

I can confirm this issue.
Solves the problem.

cannona’s picture

I can confirm as well. Thanks tons for the patch!

torotil’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of http://drupal.org/node/997092

GuyPaddock’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

This is not a duplicate of #997092: Anonymous vote rollover not working. This issue still remains.

GuyPaddock’s picture

Attached is a patch that corrects how the timestamp criterion is handled. It also corrects a few other places where the $criteria parameter was not being handled as described in the PHPdoc for the functions.

It seems like a more in-depth review of how Voting API functions relative to its docs is in order, but at least this is a start.

Status: Needs review » Needs work
GuyPaddock’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Status: Needs work » Needs review

Correct version.