You are here

function fivestar_views_widget_handler in Fivestar 5

Same name and namespace in other branches
  1. 6.2 fivestar.module \fivestar_views_widget_handler()
  2. 6 fivestar.module \fivestar_views_widget_handler()
2 calls to fivestar_views_widget_handler()
fivestar_views_widget_compact_handler in ./fivestar.module
fivestar_views_widget_normal_handler in ./fivestar.module

File

./fivestar.module, line 1614
A simple n-star voting widget, usable in other forms.

Code

function fivestar_views_widget_handler($op, $filter, $value, &$query, $summary) {
  global $user;

  // If the user can't rate, use the display handler.
  if (!user_access('rate content')) {
    return fivestar_views_value_display_handler($op, $filter, $value, $query);
  }
  $content_type = 'node';
  $content_id = $query->nid;
  $node_type = isset($query->node_type) ? $query->node_type : db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $query->nid));
  $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count');
  if ($user->uid) {
    $user_vote = votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid);
  }
  else {
    $user_vote->value = 0;
  }
  $values = array(
    'average' => (int) $value,
    'user' => (int) $user_vote->value,
    'count' => (int) $current_count->value,
  );
  $settings = array(
    'stars' => variable_get('fivestar_stars_' . $node_type, 5),
    'allow_clear' => variable_get('fivestar_unvote_' . $node_type, FALSE),
    // If the user has setup this content type to use smart stars, display
    // the smart version instead of just the average.
    'style' => variable_get('fivestar_style_' . $node_type, 'average') != 'smart' ? 'average' : 'smart',
    'text' => $summary ? variable_get('fivestar_text_' . $node_type, 'dual') : 'none',
    'content_type' => $content_type,
    'content_id' => $content_id,
    'autosubmit' => TRUE,
    'title' => FALSE,
    'tag' => 'vote',
    'feedback_enable' => $summary ? variable_get('fivestar_feedback_' . $node_type, 1) : FALSE,
    'labels_enable' => $summary ? variable_get('fivestar_labels_enable_' . $node_type, 1) : FALSE,
    'labels' => $summary ? variable_get('fivestar_labels_' . $node_type, array()) : array(),
  );
  return drupal_get_form('fivestar_custom_widget', $values, $settings);
}