function poll_update

poll_update($node)

Implements hook_update().

File

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

Code

function poll_update($node) {
  // Update poll settings.
  db_update('poll')
    ->fields(array(
      'runtime' => $node->runtime,
      'active' => $node->active,
    ))
    ->condition('nid', $node->nid)
    ->execute();

  // Poll choices with empty titles signifies removal. We remove all votes to
  // the removed options, so people who voted on them can vote again.
  foreach ($node->choice as $key => $choice) {
    if (!empty($choice['chtext'])) {
      db_merge('poll_choice')
        ->key(array('chid' => $choice['chid']))
        ->fields(array(
          'chtext' => $choice['chtext'],
          'chvotes' => (int) $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->insertFields(array(
          'nid' => $node->nid,
          'chtext' => $choice['chtext'],
          'chvotes' => (int) $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->execute();
    }
    else {
      db_delete('poll_vote')
        ->condition('nid', $node->nid)
        ->condition('chid', $key)
        ->execute();
      db_delete('poll_choice')
        ->condition('nid', $node->nid)
        ->condition('chid', $choice['chid'])
        ->execute();
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!poll!poll.module/function/poll_update/7.x