function votingapi_generate_create_votes in Voting API 5
1 call to votingapi_generate_create_votes()
File
- ./
votingapi_generate.module, line 3
Code
function votingapi_generate_create_votes($nodes, $vote_type = 'percent', $user_chance = 50, $tags = array()) {
$users = votingapi_generate_get_users();
$original_state = variable_get('votingapi_calculation_schedule', 'immediate');
variable_set('votingapi_calculation_schedule', 'cron');
foreach ($nodes as $nid) {
foreach ($users as $uid) {
if (mt_rand(0, 100) <= $user_chance) {
if (empty($tags)) {
$vote = '';
$vote->value_type = $vote_type;
$vote->tag = 'vote';
$vote->value = mt_rand(0, 100);
votingapi_set_vote('node', $nid, $vote, $uid);
}
else {
$votes = array();
$total = 0;
foreach ($tags as $tag) {
$vote = '';
$vote->value_type = $vote_type;
$vote->tag = $tag;
$vote->value = mt_rand(0, 100);
$total += $vote->value;
$votes[] = $vote;
}
$vote = '';
$vote->value_type = $vote_type;
$vote->tag = 'vote';
$vote->value = intval($total / count($tags));
$votes[] = $vote;
votingapi_set_vote('node', $nid, $vote, $uid);
}
}
}
}
variable_set('votingapi_calculation_schedule', $original_state);
foreach ($nodes as $nid) {
votingapi_recalculate_results('node', $nid, TRUE);
}
return t('Votes generated for %count nodes.', array(
'%count' => count($nodes),
));
}