You are here

function votingapiactivity_token_values in Activity 5.4

Same name and namespace in other branches
  1. 5.3 contrib/votingapiactivity/votingapiactivity.module \votingapiactivity_token_values()
  2. 6 contrib/votingapiactivity/votingapiactivity.module \votingapiactivity_token_values()

File

contrib/votingapiactivity/votingapiactivity.module, line 63

Code

function votingapiactivity_token_values($type, $data = NULL, $options = array()) {
  if ($type == 'votingapiactivity' && !empty($data)) {
    $data['content-link'] = l($data['content-title'], 'node/' . $data['content-nid'], array(), NULL, 'comment-' . $data['content-cid']);
    $data['content-link'] = l($data['content-title'], 'node/' . $data['content-nid']);
    $author_vote = db_fetch_object(db_query('SELECT value FROM {votingapi_vote} WHERE uid = %d AND content_id = %d', $data['uid'], $data['content-id']));
    $data['author-vote'] = $author_vote->value;
    $content_votes = db_query('SELECT value, function FROM {votingapi_cache} WHERE content_id = %d', $data['content-id']);
    while ($row = db_fetch_object($content_votes)) {
      $content_vote[$row->function] = $row->value;
    }
    $data['content-vote-avg'] = $content_vote['average'];
    $data['content-vote-count'] = $content_vote['count'];
    $data['content-type'] = $data['content-type'] == t('comment') ? $data['content-type'] : theme('activity_node_type', $data['content-type']);
    $link_fragment = NULL;
    if ($data['content-type'] == t('comment')) {
      $link_fragment = 'comment-' . $data['content_id'];
    }
    $data['content-link'] = l($data['content-title'], 'node/' . $data['content-nid'], array(), NULL, $link_fragment);
    return $data;
  }
}