You are here

public static function VotingApi_Vote::saveMultiple in Voting API 7.3

Save a collection of votes to the database.

This function does most of the heavy lifting for VotingAPI the main votingapi_set_votes() function, but does NOT automatically triger re-tallying of results. As such, it's useful for modules that must insert their votes in separate batches without triggering unecessary recalculation.

Remember that any module calling this function implicitly assumes responsibility for calling votingapi_recalculate_results() when all votes have been inserted.

Parameters

$votes array of VotingApi_Vote instances:

Return value

The same votes, with vote_id keys populated.

See also

votingapi_set_votes()

votingapi_recalculate_results()

4 calls to VotingApi_Vote::saveMultiple()
VotingAPITestCase::testAddMultipleVotes in tests/votingapi.test
Add multiple votes and ensure that the vote calculations are working.
VotingAPITestCase::testAddVote in tests/votingapi.test
Add a vote and ensure that the vote was stored properly.
VotingAPITestCase::testMinimalAdd in tests/votingapi.test
Ensure that the optional fields are truly optional.
votingapi_set_votes in ./votingapi.module
Cast a vote on a particular piece of content.

File

./votingapi.module, line 53
A generalized voting API for Drupal.

Class

VotingApi_Vote
Model class for votingapi_vote table.

Code

public static function saveMultiple(&$votes) {
  if (is_object($votes)) {
    $votes = array(
      $votes,
    );
  }
  foreach ($votes as $key => $vote) {
    $vote
      ->save();
  }
  module_invoke_all('votingapi_insert', $votes);
  return $votes;
}