I`d like to have a option to only display the results in percent instead percents and counts. This is essential to don`t let the user know the exact ammount of votes while showing the result.

Comments

BigMike’s picture

Component: Code » Code - Base Decisions module

Hello Gork,

I just got Decisions up and running and I was also unhappy with the number of votes being displayed for all to see. Here is what I did to change this:

Open file decisions.module, and navigate to line 363 where you'll find the following function:

363: function theme_decisions_bar($title, $vote, $total_votes, $max_votes) {
364:   $output = '<div class="text">'. $title .'</div>';
365:   $output .= '<div class="bar"><div style="width: '. round(100 * $vote / $max_votes, 0) .'%;" class="foreground"></div></div>';
366:   $output .= '<div class="percent">'. round(100 * $vote / $total_votes, 0) .'% ('. format_plural($vote, '1 vote', '@count votes') .')</div>';
367:   return $output;
368: }

You can see on line 366 that the vote count is being added after the percentage of votes. Here is how I resolved this:

363: function theme_decisions_bar($title, $vote, $total_votes, $max_votes) {
364:   $votecounts='';
365:   if (user_access('administer decisions'))
366:     $votecounts=' ('. format_plural($vote, '1 vote', '@count votes') .')';
367:   $output = '<div class="text">'. $title;
368:   $output .= '<div class="bar"><div style="width: '. round(100 * $vote / $total_votes, 0) .'%;" class="foreground"></div></div>';
369:   $output .= '<div class="percent">'. round(100 * $vote / $total_votes, 0) .'%'. $votecounts .'</div></div>';
370:   return $output;
371: }

I added lines 364-366 & modified my line 369. What I did was I created an empty variable called $votecounts to which the number of votes will be added to ONLY if the user has permissions to administrator Decisions. Then on my line 369, you can see where I inserted this variable after the vote percentage is displayed. If the user is not able to administrator Decisions, then this variable is blank so nothing is displayed on the browser. But if the user does have the permission to administrator Decisions, then he/she will also see the number of votes placed per choice.

Another thing I did is I added style="float: right; font-size: 0.9em;" to the "percent" div and moved this div above the "bar" div. This way my results are displayed above each results bar, with the choice at the left, and the % at the right. Now my results for each choice only take up 2 lines on the users browser screen instead of 3 lines, which made it easier (more compact) to theme my Decisions block.

So here is my exact theme_decisions_bar function:

function theme_decisions_bar($title, $vote, $total_votes, $max_votes) {
  $votecounts='';
  if (user_access('administer decisions'))
    $votecounts=' ('. format_plural($vote, '1 vote', '@count votes') .')';
  $output = '<div class="text">'. $title;
  $output .= '<div class="percent" style="float: right; font-size: 0.9em;">'. round(100 * $vote / $total_votes, 0) .'%'. $votecounts .'</div></div>';
  $output .= '<div class="bar"><div style="width: '. round(100 * $vote / $total_votes, 0) .'%;" class="foreground"></div></div>';
  return $output;
}

You can see it in action at http://www.marlincrawler.com

Good luck,
BigMike