You are here

function _votingapi_cast_votes in Voting API 7.2

Same name and namespace in other branches
  1. 8.3 votingapi.drush.inc \_votingapi_cast_votes()
  2. 6.2 votingapi.admin.inc \_votingapi_cast_votes()
  3. 7.3 votingapi.drush.inc \_votingapi_cast_votes()

Utility function to generate votes on a node by a set of users.

1 call to _votingapi_cast_votes()
votingapi_generate_votes in ./votingapi.devel.inc
Utility function to generate votes.

File

./votingapi.devel.inc, line 47
Generate fake votingapi votes for development testing.

Code

function _votingapi_cast_votes($etype, $eid, $timestamp = 0, $uids = array(), $style = 'percent') {
  $votes = array();
  static $tags;
  if (!isset($tags)) {
    $tags = explode(' ', devel_create_greeking(30));
  }
  foreach ($uids as $uid) {
    switch ($style) {
      case 'percent':
        $votes[] = array(
          'uid' => $uid,
          'entity_type' => $etype,
          'entity_id' => $eid,
          'value_type' => 'percent',
          'timestamp' => REQUEST_TIME - mt_rand(0, $timestamp),
          'value' => mt_rand(1, 5) * 20,
          'tag' => $tags[mt_rand(0, 20)],
        );
        break;
      case 'points':
        if (rand(0, 3)) {
          $votes[] = array(
            'uid' => $uid,
            'entity_type' => $etype,
            'entity_id' => $eid,
            'value_type' => 'points',
            'timestamp' => REQUEST_TIME - mt_rand(0, $timestamp),
            'value' => rand(0, 1) ? 1 : -1,
          );
        }
        break;
    }
  }
  votingapi_set_votes($votes, array());
}