You are here

function advpoll_ranking_node_view in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_node_view()
  2. 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_node_view()

File

advpoll_ranking/advpoll_ranking.module, line 19

Code

function advpoll_ranking_node_view($node, $view_mode) {
  if ($node->type == 'advpoll') {
    $data = advpoll_get_data($node);
    if ($data->behavior == 'borda' || $data->behavior == 'runoff') {
      drupal_add_css(drupal_get_path('module', 'advpoll') . '/css/advpoll.css', array(
        'group' => CSS_DEFAULT,
        'every_page' => TRUE,
      ));

      // replace the markup for choices with appropriate markup.
      unset($node->content['advpoll_choice']);

      // check for eligibility to vote
      if (advpoll_user_eligibility($node)) {

        // print out voting form
        $voteform = '<div class="advpoll-ranking-wrapper">' . drupal_render(drupal_get_form('advpoll_ranking_choice_form', $node)) . '</div>';
        $node->content['advpoll_choice'] = array(
          '#markup' => $voteform,
          '#weight' => 1,
        );
      }
      else {

        // 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($node->nid, $node->nid);
        }

        // Depending upon the reasons that the user is ineligible to vote,
        // select the appropriate theme.
        if ($data->state == 'close' && $data->show_results != 'afterclose' || ($data->start_date > time() || $data->end_date < time())) {
          $results = theme('advpoll_closed', array(
            'data' => $data,
          ));
        }
        else {
          if ($data->electoral && $data->show_results != 'aftervote') {
            $results = theme('advpoll_ineligible', array(
              'data' => $data,
            ));
          }
          else {
            if ($data->behavior == 'borda') {
              $results = advpoll_display_borda_results($node->nid, $data);
            }
            else {
              $results = advpoll_display_runoff_results($node->nid, $data);
            }
          }
        }
        $node->content['advpoll_choice'] = array(
          '#markup' => $results,
          '#weight' => 1,
        );
      }
    }

    // JS needs to be present for any ranking poll in case form is re-rendered by vote cancellation.
    drupal_add_js(drupal_get_path('module', 'advpoll_ranking') . '/js/advpoll-ranking.js', 'file');
    drupal_add_js(array(
      'advpoll_ranking' => array(
        'display' => 'true',
      ),
    ), 'setting');
  }
}