function advpoll_load in Advanced Poll 6.2
Same name and namespace in other branches
- 5 advpoll.module \advpoll_load()
- 6.3 advpoll.module \advpoll_load()
- 6 advpoll.module \advpoll_load()
Implementation of hook_load().
Load the votes and poll-specific data into the node object.
File
- ./
advpoll.module, line 676 - Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.
Code
function advpoll_load($node) {
$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);
$poll->choice = array();
$poll->writein_choices = 0;
while ($choice = db_fetch_array($result)) {
$poll->choice[$choice['cid']] = $choice;
if ($choice['writein'] == 1) {
$poll->writein_choices++;
}
}
$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 ($cache = db_fetch_object($result)) {
// Found total votes in the cache.
$poll->votes = $cache->value;
}
else {
$poll->votes = 0;
}
list($poll->voted, $poll->cancel_vote) = _advpoll_user_voted($node->nid);
return $poll;
}