Hi,

I would like to know if it's possible to attach a fivestar rating on a comment without the node comments module.

As said on the module page, the module is not actively supported and will disappear soon. Maybe we will have a d6 version with some luck, and surely a 7.x version will never come.

In addition, it's a little an heavy step to radically transform comments as node, just to add the possibility to attach rate on them.

That's why it would be cool to see that feature implemented in fivestar without the need to make comments as node.

What's your opinion about it ?

Comments

quicksketch’s picture

Fivestar already supports comments in a limited fashion. You can create simple "single axis" ratings by turning on the option for rating through comments when you configure a content type. Additionally, you can use node reference fields to create "multi axis" reviews using CCK. The Node Reviews module also has support for Fivestar. So even if nodecomments pass away, it's only a single way of doing reviews.

zmove’s picture

Status: Active » Fixed

Excellent thank you

The new comment options are a greeeat feature ;)

thank you very much !

darthsuo’s picture

Status: Fixed » Active

I was wondering, is it possible to rate the comments themselves? The comment options when you configure content type only supports rating the parent node through the comments, but is there an option that allows users to rate how good the comment is?

TIA

quicksketch’s picture

No, Fivestar has no support for rating comments themselves. Most sites (not particularly Drupal ones) use either a vote up/down mechanism or a simple point system to rate comments instead of a star rating system.

mcurry’s picture

*subscribing*

CompShack’s picture

>> Most sites (not particularly Drupal ones) use either a vote up/down mechanism or a simple point system to rate comments instead of a star rating system.

Do you know if a module is out there to rate a comment? I've looked but no luck. It would be great if this could be added as a feature to this module.

Thanks!

quicksketch’s picture

For voting on comments, http://drupal.org/project/vote_up_down is the best hope, though it is seeking a new maintainer.

Richard Blackborder’s picture

Status: Active » Needs review
StatusFileSize
new4.75 KB
new357 bytes

I've written this module "Fivestar Ratecomments" that enables Fivestar voting on comments.

It mostly runs without interference with Fivestar, but the function _fivestar_validate_target() blocks the comment votes, so I had to hack fivestar.module to make this module work.

Would you consider integrating the attached patch so that Fivestar widgets can be used for the rating of comments?

As for the "Fivestar Ratecomments" module itself, I'd appreciate your feedback on how best I should handle it. I've coded it because I need it myself, but I'm more than happy to share it. I've never submitted a module to Drupal, but I read in the contributors guide that it is better to integrate with existing modules than create new projects.

So I'd like to handle "Fivestar Ratecomments" in a way that suits the maintainers of Fivestar. I'm willing to rework it in a way that suits you if it means integration it is possible.

Any other feedback or opinions on the module are also welcome.

quicksketch’s picture

Hi, I'd love to add the functionality needed to make this possible. I didn't even realize how close Fivestar comes to enabling you to use it on other content types. After reviewing your module, I have to say I really like the approach you've taken. Configuration and the API usage looks great.

I'll need to think on how to make this a bit more flexible though. Hardcoding another module's variable into _fivestar_validate_target() doesn't feel right. We need some way of letting modules define their own validation (possibly via hook).

Let's say we call this hook "hook_fivestar_access()"? We could follow the same convention as Drupal's node hook_access(), where modules return NULL if they have no preference on the access, TRUE if it should be allowed, or FALSE if it absolutely should not be allowed.

So for fivestar_ratecomments it would be:

function fivestar_ratecomments_fivestar_access($type, $cid) {
  if ($type == 'comment' && variable_get('fivestar_ratecomments', FALSE) {
    return TRUE;
  }
}

Fivestar would use _fivestar_content_validate() as the default if nothing else was specified, so we can keep this function as "internal" for Fivestar's personal use. How does this all sound?

Richard Blackborder’s picture

That sounds great. I agree it's more elegant to use a hook than to have variables crossing between modules.

I'd like to suggest another place where a hook would be welcome, which is in fivestar_forms(). As you can see, I'm generating widgets like this:

drupal_get_form('fivestar_form_comment_'.$comment->cid,'added to avoid triggering fivestar_forms','comment',$comment->cid)

A similar hook at the top of fivestar_forms() would avoid me having to include this unnecessary string (and would generally improve clarity). Similarly to hook_fivestar_access(), hook_fivestar_forms() would either return an array of callbacks keyed on form_ids, or else execution would pass to fivestar_forms() as normal.

Alternatively, drupal_alter() could be used on the $forms array returned by fivestar_forms().

It's not so high priority as the hook you suggested, as fivestar_ratecomments is working without it, but it would allow me to clean up some mess in the code :-)

quicksketch’s picture

StatusFileSize
new3.37 KB

Here's a patch that adds hook_fivestar_access(). It also makes fivestar_validate_target() a "public" function and adds an argument for $uid.

As for changing fivestar_forms(), perhaps there are other changes that could be made to accommodate for this. "fivestar_form_*_*" is sort of "owned" by Fivestar module itself, while you module should use "fivestar_ratecomments_*" for its forms.

Richard Blackborder’s picture

StatusFileSize
new4.78 KB

Okay, I applied that patch, and updated my module to use your hook, and it's working.

I was able to change the form id as you suggested. I thought it would break the widget, but it didn't.

I've renamed my module fivestarcommentsusers to avoid namespace clashes with fivestar and fivertar comments. I think it's mostly clean, but one area where I have not been able to use the fivestarcommentsusers namespace is in the variable names. When I tried to change like this:

fivestar_stars_comment -> fivestarcommentsusers_stars_comment

..it caused the preview widget on the admin page to break. I tried to fix that by moving more fivestar code across and altering it, but too much code was needed, and one thing I always wanted to avoid was using so much fivestar code in fivestarcommentsusers that it turned into a fork.

If you're happy with how things stand, I'll apply for CVS access for this module now. If you want to fix the variables issue first, let me know.

Oh, and I added support for rating users too.

quicksketch’s picture

I've committed the patch from #11. I'm not sure where you mean when you say "it caused the preview widget on the admin page to break". Just let me know what needs to be updated in Fivestar and I'd be glad to make the change.

Btw, could you possibly rename the module to something that doesn't include "comment" in the title? It's confusing looking between "Fivestar Comments" and "Fivestar Comments User". Perhaps something like "fivestar_extensions" or "fivestar_extended"?

chandrabhan’s picture

+

zilla’s picture

so will this new 'rate comments' utility be coming as a separate module? it's very nice work, just unclear about how it's going to flow to the project page....

Richard Blackborder’s picture

I take your point on the name. I was finding that a bit of a hindrance too. I'm calling it fivestarextra now (no underscores to avoid namespace clashes with fivestar).

I have resolved the major issue with the variable names. It did not require any changes to fivestar.

One flaw in fivestarextra voting is that the current vote returned on the widget is always returned as a number out of 5, not based on the correct number of stars. I think it is happenning here:

683 and 684 of fivestar.module:

function fivestar_vote($type, $cid, $value, $tag = 'vote') {

  $result = _fivestar_cast_vote($type, $cid, $value, $tag, NULL, TRUE);
  votingapi_recalculate_results($type, $cid);

  if ($type == 'node') {
    $node = node_load($cid);
  }
  $stars = variable_get('fivestar_stars_'. (!isset($node) ? 'default' : $node->type), 5);
  $feedback_enable = variable_get('fivestar_feedback_'. (!isset($node) ? 'default' : $node->type), 1);

  $output = '';

To patch this to return the correct number, I need or a hook or some way to override the variables being fetched in those places. Perhaps if $type is not node, call a hook for these values, or just call a hook and then use the fivestar variables if the hook returns nothing?

Richard Blackborder’s picture

StatusFileSize
new4.64 KB

As all namespace collisions have been resolved, I'm applying for the contributor CVS account now. I'm also uploading the latest version here for the Drupal.org CVS administrators.

quicksketch’s picture

My 2¢ for any d.o Administrators: This module Likeless has posted is well-written and doesn't duplicate any of the functionality of Fivestar. Rather, it uses Fivestar as an API and provides a frequently requested feature (rating on comments) that Fivestar would have never provided directly. I give this a wholehearted thumbs-up.

Likeless: I'll review the problem you noted in #16. Seems like we could use a generic "fivestar_get_settings($content_type, $content_id)" function that pulls in settings for a particular content type/id combination. I wouldn't be surprised to find a few more places in Fivestar where the variables have been hard-coded like that.

Richard Blackborder’s picture

I think that's a great approach as I agree we may well hit other similar instances of variable hard-coding blocking extra functionality.

zilla’s picture

@likeless and @quicksketch:

one HUGELY important thing: this is an awesome addon - but admins must remember to not confuse users when it comes to workflow...there may be a need for an intuitive "if this module is enabled, disable fivestar within comments feature of regular fivestar" - why? here's a classic example:

i've got a content type called 'vendor profile' all tweaked out with CCK, users can vote on the 'vendor' up top via a widget and also can vote within a comment - so they can express their opinions in isolation (i give it five stars as part of the 'group vote' and within my comment i give it 'five stars' and explain why i gave it this rating...

now add this module up above: a user sees the review in which commenter rates vendor five stars and rates the comment itself with 3 stars, as do others...

what will a reader think those votes reflect? are the 3 stars with 'new average' an override of the 5 stars within the comment, or are they ratings on the quality of the comment itself and not the vendor?

...there can be only one, one star to rule them all...

Richard Blackborder’s picture

Zilla, if I understand your point correctly, I think it would most easily be resolved by labelling and/or theming. If the fivestarextra set of ratings is positioned differently and labelled as "Rate this review", perhaps then users would intuitively know the difference.

That said, the module may need to help you out with that.

zilla’s picture

@likeless, that would probably do it - just some kind of default text to that effect, maybe more generic like "rate this comment" and then somebody could change the string output as desired (rate this feedback, rate this review)

Richard Blackborder’s picture

The module is now listed on drupal.org.

http://drupal.org/project/fivestarextra

CompShack’s picture

Nice! - now here is what we need. Another tab on the comments that sorts comments, with the highest rated on the top of all other comments! Could this be easily done?

zilla’s picture

@compshack - exactly - like a mini-view for the comments thread, so a user could click to sort by 'top rated comments' *without* having to turn on that horribly ugly comment filtering thing that's offered within the content type comments options set....

oh, OR a block for 'top rated comments' that is node-specific (like cck's "tags for this node") and it could show X number of short titles for top rated comments that relaly just jump down the page when clicked...

Richard Blackborder’s picture

quicksketch: For fivestar_get_settings($content_type, $content_id), here is another place where it is needed:

line 1061, inside fivestar_static():

  // Possibly add other content types here (comment, user, etc).
  else {
    $stars = 5;
    $star_value = $votes['average']['value'];
    $user_value = $votes['user']['value'];
    $average_value = $votes['average']['value'];
    $count_value = $votes['count']['value'];
  }

I came across this whilst trying to implement a fix for this issue to print a non-interactive rating form in some situations.

Thanks.

Off topic: Kudos on the book. I'll be getting a copy.

avw’s picture

hi just wanted to say great stuff and i was wondering if there is ever going to be a fivestarextra for D5 ??? anyways have a good one.

Richard Blackborder’s picture

Thanks avw. I'm only familiar with D6 personally, so I won't be making a D5 version, sorry.

quicksketch’s picture

Status: Needs review » Closed (fixed)

Any further questions can be posted to the Fivestar Extra issue queue.