function votingapi_generate_votes in Voting API 7.2
Same name and namespace in other branches
- 8.3 votingapi.drush.inc \votingapi_generate_votes()
- 6.2 votingapi.admin.inc \votingapi_generate_votes()
- 7.3 votingapi.drush.inc \votingapi_generate_votes()
Utility function to generate votes.
2 calls to votingapi_generate_votes()
- drush_votingapi_generate_votes in ./
votingapi.drush.inc - Command callback. Generate a number of votes.
- votingapi_generate_votes_form_submit in ./
votingapi.admin.inc - Submit handler for votingapi_generate_votes_form.
File
- ./
votingapi.devel.inc, line 11 - Generate fake votingapi votes for development testing.
Code
function votingapi_generate_votes($entity_type = 'node', $vote_type = 'percent', $options = array()) {
module_load_include('inc', 'devel_generate');
$options += array(
'age' => 36000,
'types' => array(),
'kill' => FALSE,
);
if (!empty($options['kill_votes'])) {
db_truncate('votingapi_vote');
db_truncate('votingapi_cache');
}
if (($schema = drupal_get_schema($entity_type)) && ($entity_id_column = array_shift($schema['primary key']))) {
// oh look we found a schema yay
}
else {
$entity_type = 'node';
$entity_id_column = 'nid';
}
$uids = devel_get_users();
$query = db_select($entity_type, 'e')
->fields('e', array(
$entity_id_column,
));
if ($entity_type == 'node' && !empty($options['types'])) {
$query
->condition('e.type', $options['types'], 'IN');
}
$results = $query
->execute()
->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $entity) {
_votingapi_cast_votes($entity_type, $entity[$entity_id_column], $options['age'], $uids, $vote_type);
}
}