Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal Creating Votes in Voting API Through Code

I have a custom module I'm writing, part of what I want it to do is create a vote associated with a node, I'm trying to figure out how to call the voting API from my module. I loookd in the documentation but it's a little sparse.

like image 921
user379468 Avatar asked Sep 25 '26 17:09

user379468


1 Answers

Here is an example from a module I wrote a while ago.

while ($data = db_fetch_object($result)) {
  $node = node_load($data->nid);
  $node_terms = taxonomy_node_get_terms($node);
  $vote['value'] = 0;
  $vote['value_type'] = 'points';
  foreach ($node_terms as $term) {
    $vote['value'] = $vote['value'] + $users_tags[$term->name];
  }
  $vote['content_id'] = $node->nid;
  if (isset($vote['content_id'])) {
    votingapi_set_votes($vote);
  }
}
like image 171
Matt V. Avatar answered Sep 28 '26 21:09

Matt V.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!