poll_load
function poll_load
poll_load($nodes)
Implements hook_load().
File
- modules/poll/poll.module, line 488
- Enables your site to capture votes on different topics in the form of multiple choice questions.
Code
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(); if (empty($poll)) { $poll = new stdClass(); } // 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) { // If authenticated, find existing vote based on uid. $poll->vote = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField(); if (empty($poll->vote)) { $poll->vote = -1; $poll->allowvotes = TRUE; } } elseif (!empty($_SESSION['poll_vote'][$node->nid])) { // Otherwise the user is anonymous. Look for an existing vote in the // user's session. $poll->vote = $_SESSION['poll_vote'][$node->nid]; } else { // Finally, query the database for an existing vote based on anonymous // user's hostname. $poll->allowvotes = !db_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname AND uid = 0", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField(); } } foreach ($poll as $key => $value) { $nodes[$node->nid]->$key = $value; } } }
© 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_load/7.x