function starrating_field_formatter_execute in Star Rating 7.2
Convert integer value to star rating HTML code
@input $rate - integer value of rating $min - minimum possible value like 0 or 1 Stars $max - maximum possible value like 10 or 5 Stars @output HTML code for star rating icons <div class="(icon_type)(icon_color)-on"></div> ...
it is possible that min is 0 or 1 and rate can be NULL or 0 1 2 3 4 ..
//TODO use theme function for this?
2 calls to starrating_field_formatter_execute()
- starrating_field_formatter_settings_summary in ./
starrating.module - Implements hook_field_formatter_settings_summary(). Displays infos here /admin/structure/types/manage/node_type_name/display
- starrating_field_formatter_view in ./
starrating.module - Implements hook_field_formatter_view().
File
- ./
starrating.module, line 255 - Provides star rating field, formatter and widget using Field API. star rating field is based on integer value and convert it to the HTML code that displays series of icons. The formatter supports not only star rating field type but also…
Code
function starrating_field_formatter_execute($rate, $min, $max, $icon_type, $icon_color, $fill_blank) {
// if the rate value is not set meaning NULL, then return 'No Rating'
if ($rate === NULL) {
return "<span class='starrating-no-rating'>" . t('No rating') . "</span>";
}
//if the user has chosen 0-10 we have 11 values so we fix it for the for-loop to work correctly
if ($min == 0) {
$min = 1;
}
$out = "\n";
$out .= '<div class="starrating">';
// add hidden text to support copy/paste and voice reading
$out .= '<span style="position:absolute;left:-9999px">' . $rate . '</span>';
for ($i = $min; $i <= $max; $i++) {
if ($i == $rate && !$fill_blank) {
break;
}
if ($i > $rate) {
$class = $icon_type . '-off';
}
else {
$class = $icon_type . $icon_color . '-on';
}
if ($i % 2) {
$class .= ' odd';
}
else {
$class .= ' even';
}
$class .= ' s' . ($i + 1);
$out .= '<div class="rate-image ' . $class . '"></div>';
}
$out .= "</div>\n";
return $out;
}