You are here

function votingapi_generate_votes in Voting API 6.2

Same name and namespace in other branches
  1. 8.3 votingapi.drush.inc \votingapi_generate_votes()
  2. 7.3 votingapi.drush.inc \votingapi_generate_votes()
  3. 7.2 votingapi.devel.inc \votingapi_generate_votes()

Utility function to generate votes.

1 call to votingapi_generate_votes()
votingapi_generate_votes_form_submit in ./votingapi.admin.inc
Submit handler for votingapi_generate_votes_form.

File

./votingapi.admin.inc, line 86
Configuration forms and helper functions for VotingAPI module.

Code

function votingapi_generate_votes($node_types, $vote_type, $kill_votes = FALSE) {
  module_load_include('inc', 'devel_generate');
  if ($kill_votes) {
    db_query("TRUNCATE TABLE {votingapi_vote}");
    db_query("TRUNCATE TABLE {votingapi_cache}");
  }
  $uids = devel_get_users();
  $nids = array();
  $sql = "SELECT n.nid, n.created FROM {node} n ";
  $sql .= "WHERE n.type IN (" . db_placeholders($node_types, 'varchar') . ") ";
  $sql .= "ORDER BY n.created DESC";
  $results = db_query($sql, $node_types);
  while ($node = db_fetch_array($results)) {
    $nids[$node['nid']] = $node['created'];
  }
  foreach ($nids as $nid => $timestamp) {
    _votingapi_cast_votes($nid, $timestamp, $uids, $vote_type);
  }
}