function poll_insert

poll_insert($node)

Implements hook_insert().

File

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

Code

function poll_insert($node) {
  if (!user_access('administer nodes')) {
    // Make sure all votes are 0 initially
    foreach ($node->choice as $i => $choice) {
      $node->choice[$i]['chvotes'] = 0;
    }
    $node->active = 1;
  }

  db_insert('poll')
    ->fields(array(
      'nid' => $node->nid,
      'runtime' => $node->runtime,
      'active' => $node->active,
    ))
    ->execute();

  foreach ($node->choice as $choice) {
    if ($choice['chtext'] != '') {
      db_insert('poll_choice')
        ->fields(array(
          'nid' => $node->nid,
          'chtext' => $choice['chtext'],
          'chvotes' => $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->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_insert/7.x