3

我正在编写一个自定义模块,我想要它做的一部分是创建与节点关联的投票,我试图弄清楚如何从我的模块调用投票 API。我查看了文档,但它有点稀疏。

4

2 回答 2

3

这是我不久前写的一个模块的一个例子。

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);
  }
}
于 2011-02-26T07:50:48.447 回答
0

只是另一个使用这个的例子:

function _ept_set_vote($nid, $status, $uid = NULL) {
  global $user;

  $vote = array(
    array(
      'entity_type' => 'node',
      'value' => 1,
      'entity_id' => $nid,
      'uid' => (!$uid) ? $user->uid : $uid,
      'tag' => $status
    )
  );

  votingapi_set_votes($vote, array());
}

我这样称呼它:

switch($task_status){
      case('start'):
        _ept_set_vote($nid, "Start");
        break;
      case('completed'):
        _ept_set_vote($nid, "Completed");
        break;
    }
于 2016-04-15T16:19:42.460 回答