I have a decisions node displayed in a panel pane on the front page of a site, and when the results are displayed, they show one vote (see attached image), regardless of how many votes have actually been cast (51 in this particular case, as seen in the votingapi_vote table). The AJAX voting option is enabled. It can be seen at http://www.canadianblackbook.com/news-reviews.

I'm still investigating, but I wanted to get this out there in case anyone knew the answer off the top of their heads.

Thanks.

CommentFileSizeAuthor
decision_one_vote.gif11.34 KBwonder95

Comments

wonder95’s picture

The code in question is in selection_decisions_view_results($node, $teaser, $page, $this_vote = array()), and after stepping through it, I'm befuddled as to how it works in the first place. The issue is that it never even touches the variable data that holds the vote counts.

Here's the code in question:

function selection_decisions_view_results($node, $teaser, $page, $this_vote = array()) {
  global $user;
  $output = "";
  $results = votingapi_select_results(array('content_id' => $node->nid, 'content_type' => 'decisions'));
  // Count the votes for each choice
  $votes = array();

  foreach ($results as $result) {

    // approval
    $voteval = $result['tag'];

    if (!array_key_exists($voteval, $votes)) {
      $votes[$voteval] = 0;
    }
    // the value is the position chosen in this case, we just want to increment
    $votes[$voteval]++;
  }

  foreach ($node->choice as $i => $ch) {
    if (!array_key_exists($i, $votes)) {
      $votes[$i] = 0;
    }
  }

When $results is filled (from the call to votingapi_select_results(array('content_id' => $node->nid, 'content_type' => 'decisions'));), it is an array with one array for each option in the poll. Each option contains a tag value that is the total of votes (which I verified with a query in votingapi_vote and also looking at the votingapi_cache table), so that when looping through $results with

 foreach ($results as $result) {

$result['value'] contains the total votes for that option. However, that value is never accessed in the ensuing code. Instead, it sets $voteval as the item number of the option in the poll (1 - 5 in this case), and then sets $vote[$voteval] to the item number instead of the actual total number of votes. Then, it looks for a match for $voteval in $votes and sets $votes[$voteval] to 0 if there is no match in $votes (which there won't be since $votes was just initialized a few lines above). After that, it's increased to 1 (I'm not sure why), and that result is what's displayed. At no point is the actual vote could accessed.

I'm working on a patch and will post it as soon as I have it.

wonder95’s picture

Status: Active » Closed (fixed)

AAAARRGGGGGHHHHH!! After all that work figuring this out, I realized I had an old HEAD version installed, and that this is correct in 6.x-1.7.