function theme_fivestar_summary in Fivestar 6.2
Same name and namespace in other branches
- 5 fivestar.module \theme_fivestar_summary()
- 6 fivestar.module \theme_fivestar_summary()
- 7.2 includes/fivestar.theme.inc \theme_fivestar_summary()
Display the text associated with a static star display.
Note that passing in explicit data types is extremely important when using this function. A NULL value will exclude the value entirely from display, while a 0 value indicates that the text should be shown but it has no value yet.
All ratings are from 0 to 100.
Parameters
$user_rating: The current user's rating.
$average: The average rating.
$votes: The total number of votes.
$stars: The number of stars being displayed.
$feedback: A toggle that enables AJAX indicator message when a vote is being saved.
Return value
A themed HTML string representing the star widget.
3 theme calls to theme_fivestar_summary()
- fivestar_custom_widget in ./
fivestar.module - Form builder; Build a custom Fivestar rating widget with arbitrary settings.
- fivestar_static in ./
fivestar.module - Retreive and print out a static display of stars for a piece of content.
- fivestar_vote in ./
fivestar.module - Callback function for fivestar/vote.
File
- ./
fivestar.module, line 1118 - A simple n-star voting widget, usable in other forms.
Code
function theme_fivestar_summary($user_rating, $average_rating, $votes, $stars = 5, $feedback = TRUE) {
$output = '';
$div_class = '';
if (isset($user_rating)) {
$div_class = isset($votes) ? 'user-count' : 'user';
$user_stars = round($user_rating * $stars / 100, 1);
$output .= '<span class="user-rating">' . t('Your rating: <span>!stars</span>', array(
'!stars' => $user_rating ? $user_stars : t('None'),
)) . '</span>';
}
if (isset($user_rating) && isset($average_rating)) {
$output .= ' ';
}
if (isset($average_rating)) {
$div_class = isset($votes) ? 'average-count' : 'average';
$average_stars = round($average_rating * $stars / 100, 1);
$output .= '<span class="average-rating">' . t('Average: <span>!stars</span>', array(
'!stars' => $average_stars,
)) . '</span>';
}
if (isset($user_rating) && isset($average_rating)) {
$div_class = 'combo';
}
if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
$output .= ' <span class="total-votes">' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . '</span>';
$div_class = 'count';
}
elseif (isset($votes)) {
$output .= ' <span class="total-votes">(' . format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') . ')</span>';
}
if ($votes === 0) {
$output = '<span class="empty">' . t('No votes yet') . '</span>';
}
$output = '<div class="fivestar-summary fivestar-summary-' . $div_class . ($feedback ? ' fivestar-feedback-enabled' : '') . '">' . $output . '</div>';
return $output;
}