You are here

function advpoll_voting_binary_form_submit in Advanced Poll 6

Same name and namespace in other branches
  1. 5 modes/binary.inc \advpoll_voting_binary_form_submit()
  2. 6.3 modes/binary.inc \advpoll_voting_binary_form_submit()
  3. 6.2 modes/binary.inc \advpoll_voting_binary_form_submit()

Registers the vote as a key for this node using votingapi_set_vote().

File

modes/binary.inc, line 176
Handle binary (true/false) votes.

Code

function advpoll_voting_binary_form_submit($form, &$form_state) {
  $votes = array();
  $node = $form['#node'];

  // Do submission specific to writeins.
  _advpoll_writeins_voting_form_submit($node, $form_state, $votes, 1);
  if ($node->max_choices == 1) {

    // Plurality voting
    // Ignore write-in choice that has already been taken care of.
    if (!$node->writeins || !isset($form_state['values']['choice'][$form_state['values']['writein_key']])) {
      $vote['value'] = 1;
      $vote['tag'] = $form_state['values']['choice'];
      $vote['value_type'] = 'option';
      $vote['content_id'] = $node->nid;
      $vote['content_type'] = 'advpoll';
      $votes[] = $vote;
    }
  }
  else {

    // Approval voting
    foreach ($form_state['values']['choice'] as $choice => $selected) {
      $vote = array();

      // Ignore write-in choice that has already been taken care of.
      if (!$node->writeins || $choice != $form_state['values']['writein_key']) {
        $vote['value'] = $choice;
        if ($selected) {
          $vote['value_type'] = 'option';
          $vote['tag'] = $choice;
          $vote['value'] = 1;
          $vote['content_id'] = $node->nid;
          $vote['content_type'] = 'advpoll';
          $votes[] = $vote;
        }
      }
    }
  }

  // Need to pass a blank array as the second parameter so that existing votes aren't deleted......
  $results = votingapi_set_votes($votes, array());
  _advpoll_vote_response($node, $form_state);
}