function fivestar_views_widget_handler in Fivestar 6
Same name and namespace in other branches
- 5 fivestar.module \fivestar_views_widget_handler()
- 6.2 fivestar.module \fivestar_views_widget_handler()
Generic VotingAPI Views formatter for displaying rating widget.
2 calls to fivestar_views_widget_handler()
- fivestar_views_widget_compact_handler in ./
fivestar.module - VotingAPI Views formatter for displaying rating widget without text.
- fivestar_views_widget_normal_handler in ./
fivestar.module - VotingAPI Views formatter for displaying rating widget with text.
File
- ./
fivestar.module, line 1724 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_views_widget_handler($value, $field, $columns, $summary) {
// If the user can't rate, use the display handler.
if (!user_access('rate content')) {
return fivestar_views_value_display_handler($value, $field, $columns);
}
if ($field->view->base_table == 'node') {
// Find the VotingAPI tag for this field.
foreach ($field->query->table_queue[$field->relationship]['join']->extra as $votingapi_setting) {
if ($votingapi_setting['field'] == 'tag') {
$tag = $votingapi_setting['value'];
}
}
$content_type = 'node';
$content_id = $columns->nid;
$node_type = isset($columns->node_type) ? $columns->node_type : db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $columns->nid));
$values = array(
'user' => 0,
'average' => 0,
'count' => 0,
);
if ($field->table == 'votingapi_vote') {
$values['user'] = $value;
}
if ($field->table == 'votingapi_cache') {
$values['average'] = $value;
}
// Only pull in all the votes if we need to display the summary text.
if ($summary) {
$votes = fivestar_get_votes($content_type, $content_id, $tag);
if ($field->table != 'votingapi_vote') {
$values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0;
}
if ($field->table != 'votingapi_cache') {
$values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0;
}
$values['count'] = isset($votes['count']['value']) ? $votes['count']['value'] : 0;
}
$settings = array(
'stars' => variable_get('fivestar_stars_' . $node_type, 5),
'allow_clear' => variable_get('fivestar_unvote_' . $node_type, FALSE),
'style' => $field->table == 'votingapi_vote' ? 'user' : 'average',
'text' => $summary ? variable_get('fivestar_text_' . $node_type, 'dual') : 'none',
'content_type' => $content_type,
'content_id' => $content_id,
'tag' => $tag,
'autosubmit' => TRUE,
'title' => FALSE,
'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);
}
else {
return theme('fivestar_static', $value, 5);
}
}