You are here

function advpoll_display_borda_results in Advanced Poll 7.2

Same name and namespace in other branches
  1. 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_display_borda_results()
  2. 7 advpoll_ranking/advpoll_ranking.module \advpoll_display_borda_results()
3 calls to advpoll_display_borda_results()
advpoll_ranking_node_view in advpoll_ranking/advpoll_ranking.module
advpoll_ranking_results_page in advpoll_ranking/advpoll_ranking.module
advpoll_ranking_submit in advpoll_ranking/advpoll_ranking.module

File

advpoll_ranking/advpoll_ranking.module, line 609

Code

function advpoll_display_borda_results($nid, $data) {
  $output = '';
  $form = NULL;
  if (user_access('cancel own vote') && advpoll_get_user_votes($nid)) {
    $rendered_form = drupal_get_form('advpoll_ranking_cancel_form', $nid);
    $form = drupal_render($rendered_form);
  }

  // get user's votes if they're logged in and if voting is normal
  $votes = array();
  if ($data->mode == 'normal') {
    $votes = advpoll_get_user_votes($nid);
  }
  if (!user_access('administer polls') && ($data->show_results == 'never' || $data->show_results == 'afterclose' && $data->end_date > time())) {
    $output .= theme('advpoll_noresults', array(
      'data' => $data,
      'votes' => $votes,
      'nid' => $nid,
      'cancel_form' => $form,
    ));
  }
  else {
    $results = advpoll_get_votes($nid, $data->behavior);
    $bars = '';
    $final = advpoll_update_choices($data->choices, $results['choices']);
    $reordered = array();
    foreach ($final as $item) {
      $voted = FALSE;
      if (in_array($item['tag'], $votes)) {
        $voted = TRUE;
      }
      if (!isset($reordered[$item['percentage']])) {
        $reordered[$item['percentage']] = array();
      }
      $reordered[$item['percentage']][] = array(
        'title' => $item['title'],
        'votes' => $item['votes'],
        'voted' => $voted,
      );
    }
    foreach ($reordered as $key => $candidates) {
      $titles = array();
      foreach ($candidates as $candidate) {
        $candidate['voted'] ? $class = 'voted' : ($class = 'not-voted');
        $titles[] = '<span class="' . $class . '">' . $candidate['title'] . '</span>';
      }
      $bars .= theme('advpoll_borda_bar', array(
        'title' => implode(', ', $titles),
        'percentage' => $key,
        'votes' => $candidate['votes'],
      ));
    }
    $output .= theme('advpoll_results', array(
      'bars' => $bars,
      'total' => $results['total'],
      'voted' => $votes,
      'nid' => $nid,
      'cancel_form' => $form,
    ));
  }
  return $output;
}