You are here

function votingapi_add_votes in Voting API 6

Same name and namespace in other branches
  1. 6.2 votingapi.module \votingapi_add_votes()
  2. 7.2 votingapi.module \votingapi_add_votes()

Save a single vote to the database.

Parameters

$vobj: An array of vote objects with the following properties: $vote->content_type (Optional, defaults to 'node') $vote->content_id (Required) $vote->value_type (Optional, defaults to 'percent') $vote->value (Required) $vote->tag (Optional, defaults to 'vote') $vote->uid (Optional, defaults to current user) $vote->vote_source (Optional, defaults to current IP) $vote->timestamp (Optional, defaults to time())

Return value

The same vote objects, with vote_ids property populated.

1 call to votingapi_add_votes()
votingapi_set_vote in ./votingapi.module
Cast a vote on a particular piece of content. If a vote already exists, its value is changed. In most cases, this is the function that should be used by external modules.

File

./votingapi.module, line 195

Code

function votingapi_add_votes($votes = array()) {
  if (is_object($votes)) {
    $votes = array(
      $votes,
    );
  }
  foreach ($votes as $vobj) {
    $vobj = _votingapi_prep_vote($vobj);
    db_query("INSERT INTO {votingapi_vote} (content_type, content_id, value, value_type, tag, uid, timestamp, vote_source) VALUES ('%s', %d, %f, '%s', '%s', %d, %d, '%s')", $vobj->content_type, $vobj->content_id, $vobj->value, $vobj->value_type, $vobj->tag, $vobj->uid, $vobj->timestamp, $vobj->vote_source);
    $vobj->vote_id = db_last_insert_id('votingapi_vote', 'vote_id');
  }
  module_invoke_all('votingapi_insert', $votes);
  return $votes;
}