function fivestar_views_value_text_handler in Fivestar 6.2
Same name and namespace in other branches
- 6 fivestar.module \fivestar_views_value_text_handler()
VotingAPI Views formatter for displaying number of stars as text.
File
- ./
fivestar.module, line 1384 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_views_value_text_handler($value, $field, $columns) {
if ($field->view->base_table == 'node') {
// Find the VotingAPI tag for this field.
foreach ($field->query->table_queue as $table) {
if (!empty($table['join']->extra)) {
foreach ($table['join']->extra as $extra) {
if ($extra['field'] == 'tag') {
$tag = $extra['value'];
}
}
}
}
}
if (empty($tag)) {
$tag = 'vote';
}
// Get the number of stars for this node type.
$node_type = isset($columns->node_type) ? $columns->node_type : db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $columns->nid));
$settings = fivestar_get_settings($node_type, $tag);
$stars = $settings['stars'];
// If displaying a user's vote, always display a whole value.
if ($field->table == 'votingapi_vote') {
return ceil($value / 100 * $stars);
}
else {
if ($field->options['set_precision']) {
return round($value / 100 * $stars, $field->options['precision']);
}
return $value / 100 * $stars;
}
}