Index: fivestar.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v retrieving revision 1.13.2.65 diff -u -r1.13.2.65 fivestar.module --- fivestar.module 1 Jul 2009 03:02:11 -0000 1.13.2.65 +++ fivestar.module 1 Jul 2009 03:26:36 -0000 @@ -1627,16 +1627,23 @@ } } +/** + * Implementation of hook_votingapi_views_formatters(). + */ function fivestar_votingapi_views_formatters($details = array()) { if ($details->field == 'value') { return array( 'fivestar_views_value_display_handler' => t('Fivestar Stars (display only)'), + 'fivestar_views_value_text_handler' => t('Fivestar Stars (text star count)'), 'fivestar_views_widget_compact_handler' => t('Fivestar Stars (clickable, no text)'), 'fivestar_views_widget_normal_handler' => t('Fivestar Stars (clickable, with text)'), ); } } +/** + * VotingAPI Views formatter for displaying static stars. + */ function fivestar_views_value_display_handler($value, $field, $columns) { // Determine number of stars to display if ($field->view->base_table == 'node') { @@ -1663,14 +1670,40 @@ return theme('fivestar_static', $value, $stars, $tag); } +/** + * VotingAPI Views formatter for displaying number of stars as text. + */ +function fivestar_views_value_text_handler($value, $field, $columns) { + // 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)); + $stars = variable_get('fivestar_stars_'. $node_type, 5); + + // If displaying a user's vote, always display a whole value. + if ($field->table == 'votingapi_vote') { + return ceil(($value / 100) * $stars); + } + else { + return round(($value / 100) * $stars, 1); + } +} + +/** + * VotingAPI Views formatter for displaying rating widget without text. + */ function fivestar_views_widget_compact_handler($value, $field, $columns) { return fivestar_views_widget_handler($value, $field, $columns, FALSE); } +/** + * VotingAPI Views formatter for displaying rating widget with text. + */ function fivestar_views_widget_normal_handler($value, $field, $columns) { return fivestar_views_widget_handler($value, $field, $columns, TRUE); } +/** + * Generic VotingAPI Views formatter for displaying rating widget. + */ function fivestar_views_widget_handler($value, $field, $columns, $summary) { // If the user can't rate, use the display handler.