function advpoll_voting_binary_form in Advanced Poll 5
Same name and namespace in other branches
- 6.3 modes/binary.inc \advpoll_voting_binary_form()
- 6 modes/binary.inc \advpoll_voting_binary_form()
- 6.2 modes/binary.inc \advpoll_voting_binary_form()
Implementation of the view_voting hook for the poll module.
This creates a list of choices to allow the user to vote on choices.
File
- modes/
binary.inc, line 20
Code
function advpoll_voting_binary_form(&$node, $teaser, $page, $status) {
static $binary_form_count = 0;
$form = array(
'#id' => 'advpoll-voting-binary-form-' . $binary_form_count++,
'#attributes' => array(
'class' => 'advpoll-vote',
),
);
$form['ajax'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => 'ajax',
),
);
if ($node->choice) {
$list = array();
// If previewing check the format against the current users permissions.
$check = $node->in_preview;
foreach ($node->choice as $i => $choice) {
// Don't show blank choices or write-in votes if the setting is disabled.
if ($choice['label'] && ($node->show_writeins || !$choice['writein'])) {
$list[$i] = _advpoll_choice_markup($choice['label'], $node->format, $check) . ($choice['writein'] ? ' ' . t('(write-in)') : '');
}
}
// Add write-in checkbox/radio if write-ins are enabled and user has permission.
if ($node->writeins && user_access('add write-ins')) {
$list[$i + 1] = t('(write-in)');
$form['writein_key'] = array(
'#type' => 'value',
'#value' => $i + 1,
);
}
$form['choice'] = array(
'#options' => $list,
'#prefix' => '<div class="vote-choices">',
'#suffix' => '</div>',
);
$max_choices = $node->in_preview ? $node->settings['max_choices'] : $node->max_choices;
if ($max_choices == 1) {
// Plurality voting
$form['choice']['#type'] = 'radios';
$form['choice']['#default_value'] = -1;
}
else {
// Approval voting
$form['choice']['#type'] = 'checkboxes';
}
}
// Add write-in text field if write-ins are enabled and user has permission.
if ($node->writeins && user_access('add write-ins')) {
$form['writein_choice'] = array(
'#prefix' => '<div class="writein-choice">',
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('Write-in vote'),
'#size' => 25,
);
}
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
'#attributes' => array(
'class' => 'edit-nid',
),
);
// Hide vote button if user can't vote and instead display appropriate message.
if (!$node->in_preview && advpoll_eligible($node) && $status == 'open') {
static $binary_vote_count = 0;
$form['vote'] = array(
'#type' => 'submit',
'#value' => t('Vote'),
'#attributes' => array(
'id' => 'edit-vote-binary-' . $binary_vote_count++,
),
);
}
elseif ($node->in_preview) {
// Display nothing.
}
elseif ($status == 'pending') {
$form['message']['#value'] = t('This poll opens @time.', array(
'@time' => format_date($node->start_date),
));
}
else {
global $user;
$login_message = t('<a href="@login">Login</a> to vote in this poll.', array(
'@login' => url('user/login', drupal_get_destination()),
));
$form['message']['#value'] = $user->uid ? t('You are not eligible to vote in this poll.') : $login_message;
}
$form['#action'] = url('node/' . $node->nid);
return $form;
}