You are here

function poll_update in Drupal 4

Same name and namespace in other branches
  1. 5 modules/poll/poll.module \poll_update()
  2. 6 modules/poll/poll.module \poll_update()
  3. 7 modules/poll/poll.module \poll_update()

Implementation of hook_update().

File

modules/poll.module, line 483
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_update($node) {
  db_query('UPDATE {poll} SET runtime = %d, active = %d WHERE nid = %d', $node->runtime, $node->active, $node->nid);
  db_query('DELETE FROM {poll_choices} WHERE nid = %d', $node->nid);
  $total_votes = 0;
  foreach ($node->choice as $choice) {
    $chvotes = (int) $choice['chvotes'];
    $chtext = $choice['chtext'];
    $total_votes += $chvotes;
    if ($chtext != '') {
      db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $chtext, $chvotes, $i++);
    }
  }
  if (!$total_votes) {
    db_query('DELETE FROM {poll_votes} WHERE nid = %d', $node->nid);
  }
}