You are here

function advpoll_remove_voter in Advanced Poll 7

Same name and namespace in other branches
  1. 5 advpoll.module \advpoll_remove_voter()
  2. 6.3 advpoll.admin.inc \advpoll_remove_voter()
  3. 6 advpoll.admin.inc \advpoll_remove_voter()
  4. 6.2 advpoll.admin.inc \advpoll_remove_voter()
  5. 7.3 includes/advpoll.pages.inc \advpoll_remove_voter()
  6. 7.2 includes/advpoll.pages.inc \advpoll_remove_voter()

Remove an individual voter from the electoral list.

1 string reference to 'advpoll_remove_voter'
advpoll_menu in ./advpoll.module
Implements hook_menu()

File

includes/advpoll.pages.inc, line 302

Code

function advpoll_remove_voter() {
  $nid = arg(1);
  $uid = arg(3);
  if (is_numeric($nid) && is_numeric($uid)) {
    if ($uid && ($node = node_load($nid))) {
      $user = db_query('SELECT name FROM {users} WHERE uid = :uid', array(
        ':uid' => $uid,
      ))
        ->fetchField();
      if ($user) {
        $and = db_and()
          ->condition('nid', $nid)
          ->condition('uid', $uid);
        $items_deleted = db_delete('advpoll_electoral_list')
          ->condition($and)
          ->execute();
        drupal_set_message(t('%user removed from the electoral list.', array(
          '%user' => $user,
        )));
      }
      else {
        drupal_set_message(t('No user found with a uid of %uid.', array(
          '%uid' => $uid,
        )));
      }
    }
  }
  drupal_goto('node/' . $node->nid . '/electoral_list');
}