poll_load

Versions
4.6 – 6
poll_load($node)
7
poll_load($nodes)

Implement hook_load().

Code

modules/poll/poll.module, line 437

<?php
function poll_load($nodes) {
  global $user;
  foreach ($nodes as $node) {
    $poll = db_query("SELECT runtime, active FROM {poll} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();

    // Load the appropriate choices into the $poll object.
    $poll->choice = db_select('poll_choice', 'c')
      ->addTag('translatable')
      ->fields('c', array('chid', 'chtext', 'chvotes', 'weight'))
      ->condition('c.nid', $node->nid)
      ->orderBy('weight')
      ->execute()->fetchAllAssoc('chid', PDO::FETCH_ASSOC);

    // Determine whether or not this user is allowed to vote.
    $poll->allowvotes = FALSE;
    if (user_access('vote on polls') && $poll->active) {
      if ($user->uid) {
        $result = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchObject();
      }
      else {
        $result = db_query("SELECT chid FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchObject();
      }
      if ($result) {
        $poll->vote = $result->chid;
      }
      else {
        $poll->vote = -1;
        $poll->allowvotes = TRUE;
      }
    }
    foreach ($poll as $key => $value) {
      $nodes[$node->nid]->$key = $value;
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.