You are here

function advpoll_load in Advanced Poll 5

Same name and namespace in other branches
  1. 6.3 advpoll.module \advpoll_load()
  2. 6 advpoll.module \advpoll_load()
  3. 6.2 advpoll.module \advpoll_load()

Implementation of hook_load().

Load the votes and poll-specific data into the node object.

File

./advpoll.module, line 631
Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.

Code

function advpoll_load($node) {
  global $user;
  $poll = db_fetch_object(db_query('SELECT * FROM {advpoll} WHERE nid = %d', $node->nid));
  $result = db_query('SELECT cid, weight, label, writein FROM {advpoll_choices} WHERE nid = %d ORDER BY weight', $node->nid);
  while ($choice = db_fetch_array($result)) {
    $poll->choice[$choice['cid']] = $choice;
  }
  $poll->choices = count($poll->choice);
  $result = db_query("SELECT value FROM {votingapi_cache} WHERE content_type = 'advpoll' AND content_id = %d AND tag = '_advpoll' AND function = 'total_votes'", $node->nid);
  if (db_num_rows($result) > 0) {
    $cache = db_fetch_object($result);
    $poll->votes = $cache->value;
  }
  else {
    $poll->votes = 0;
  }
  list($poll->voted, $poll->cancel_vote) = _advpoll_user_voted($node->nid);
  return $poll;
}