Search code examples
apidrupalmodulevoting

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.


Solution

  • 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);
      }
    }