Download & Extend

"log in to rate it" message for non connected user

Project:Fivestar
Version:5.x-1.11
Component:Code
Category:feature request
Priority:minor
Assigned:Unassigned
Status:closed (won't fix)

Issue Summary

On youtube, only connected users can vote, and when a user is not connected he gets the java script message "Log in to rate".

Is it possible to have this behavior with five star ?

Thanks

Comments

#1

Title:"Youtube like" behavior for non connected user» I should have named this issue "log in to rate it" message for non connected user

Youtube is still a good example of this feature.

#2

Title:I should have named this issue "log in to rate it" message for non connected user» "log in to rate it" message for non connected user

#3

Category:support request» feature request

#4

This behavior is possible, but can't really be implemented by default. The reason being it's possible to have multiple roles, and even if the user was logged in they still couldn't vote. So we can't make that message part of the default Fivestar install because it'd be inaccurate in a lot of cases.

Instead, what you can do is over ride the theme_fivestar_static_element() function in your template.php, to make it include this message for your particular site.

<?php
/**
* Display a static fivestar value as stars with a title and description.
*/
function [nameofyourtheme]_fivestar_static_element($value, $title = NULL, $description = NULL) {
 
$output .= '<div class="fivestar-static-form-item">';
 
$element = array(
   
'#type' => 'item',
   
'#title' => $title,
  );

 
$output .= theme('form_element', $element, $value);
 
$output .= '<div class="description">'. t('Login or register to vote.') .'</div>';
 
$output .= '</div>';
  return
$output;
}
?>

#5

Is this possible in D6?

#6

+1 for D6 implementation.

#7

subscribe

#8

The solution provided in #4 works in D6.

#9

How would I modify the above code to make the text a link to my registration page?

Thanks!

#10

Priority:normal» minor
Status:active» closed (won't fix)

Just override the display of the fivestar 'block' or widget to add an if statement checking whether or not the user is logged in. This would require custom theming but not much else.

#4 covers some of this, but it doesn't mention any check of user login status. In the example, all widgets display the same message, whether you're logged in or not. You can easily fix this in your template files by adding something like this:

<?php
function [nameofyourtheme]_fivestar_static_element($value, $title = NULL, $description = NULL) {
 
$output .= '<div class="fivestar-static-form-item">';
 
$element = array(
   
'#type' => 'item',
   
'#title' => $title,
  );

 
$output .= theme('form_element', $element, $value);
  if (!
$user->uid) {
   
$output .= '<div class="description">'. t('Login or register to vote.') .'</div>';
  }
 
$output .= '</div>';
  return
$output;
}
?>

If I'm missing the point, tell me, but otherwise, I consider this issue resolved. Keep in mind, however, that I use D6 and may not understand some limitation of D5. If the above code has anything wrong with it, let me know.

nobody click here