You are here

function votingapi_generate_votes_form_submit in Voting API 5

Same name and namespace in other branches
  1. 6.2 votingapi.admin.inc \votingapi_generate_votes_form_submit()
  2. 7.3 votingapi.admin.inc \votingapi_generate_votes_form_submit()
  3. 7.2 votingapi.admin.inc \votingapi_generate_votes_form_submit()

File

./votingapi_generate.module, line 117

Code

function votingapi_generate_votes_form_submit($form_id, $form_values) {
  if ($form_values['vote_clear']) {
    db_query("DELETE FROM {votingapi_vote}");
    db_query("DELETE FROM {votingapi_cache}");
    db_query("UPDATE {sequences} SET id = '0' WHERE name = '{votingapi_vote}'");
    db_query("UPDATE {sequences} SET id = '0' WHERE name = '{votingapi_cache}'");
  }
  if (!empty($form_values['vote_tags'])) {
    $tags = split(',', $form_values['vote_tags']);
  }
  else {
    $tags = array();
  }
  $coverage = is_numeric($form_values['node_coverage']) ? max(min($form_values['node_coverage'], 100), 0) : 100;
  $user_chance = is_numeric($form_values['user_chance']) ? max(min($form_values['user_chance'], 100), 0) : 50;
  $nodes = array();
  $result = db_query("SELECT nid FROM {node} WHERE RAND() <= %f", $coverage / 100);
  while ($node = db_fetch_object($result)) {
    $nodes[] = $node->nid;
  }
  $output = votingapi_generate_create_votes($nodes, $form_values['vote_type'], $user_chance, $tags);
  drupal_set_message($output);
}