poll_load

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

Implementation of hook_load().

Code

modules/poll.module, line 226

<?php
function poll_load($node) {
  global $user;

  // Load the appropriate choices into the $node object
  $poll = db_fetch_object(db_query("SELECT runtime, active FROM {poll} WHERE nid = %d", $node->nid));

  $result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid = %d ORDER BY chorder", $node->nid);
  while ($choice = db_fetch_array($result)) {
    $poll->choice[$choice['chorder']] = $choice;
  }

  // Determine whether or not this user is allowed to vote
  $poll->allowvotes = FALSE;
  if (user_access('vote on polls') && $poll->active) {
    if ($user->uid && db_num_rows(db_query('SELECT uid FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid)) == 0) {
      $poll->allowvotes = TRUE;
    }
    else if ($user->uid == 0 && db_num_rows(db_query("SELECT hostname FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, $_SERVER['REMOTE_ADDR'])) == 0) {
      $poll->allowvotes = TRUE;
    }
  }
  return $poll;
}
?>
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.