Hi all,

I'm theming Fivestar for my forum topic nodes, and am having a slight problem... when a user votes on the node, everything works and the vote is saved, however they can go back and re-vote, essentially changing their vote. I want it to behave in such a way that once a vote is made, the widget display is static. What's the best way of going about doing this? If not a function, perhaps a combination of condition statements?

Current Fivestar code I'm using:
<?php print $node->content['fivestar_widget']['#value'] . fivestar_widget_form($node); ?>

Thanks in advance!

Comments

creamneuron’s picture

i 'm having the same problem. there is an option " alow user to undo vote", but this is not activated, but still the user can switch from 1 to five stars all the time.
1 click = 1 vote - and then no fuurther voting alowed should be the way, as i understand it. is it a bug? or is there something i miss?

greets
cream

lmakarov’s picture

Issue tags: +re-voting

I used this patch for version 5.x-1.13:

in fivestar.module:

Find fivestar_vote function and comment the following lines:

  drupal_set_header("Content-Type: text/xml");
  exit($output);

Below add

  print fivestar_static($type, $cid);
  exit();

in fivestar.js

look for

$("input.fivestar-path", $obj).each(function () { $.ajax({ type: 'GET', dataType: 'xml', url: this.value + '/' + currentValue, success: voteHook }); });

replace with

            $("input.fivestar-path", $obj).each(function () { 
              //show static rating image after voting
              nid = this.value.substring(this.value.lastIndexOf('/') + 1);
              $.ajax({ type: 'GET', dataType: 'html', url: this.value + '/' + currentValue, success: function (data){ $('#rating-container-' + nid).empty();$('#rating-container-' + nid).append(data); } }); 
            });

Works fine so far.

There should be definitely an option to disable re-voting in the module core.
So I'm also looking forward to see it.

dddave’s picture

I strongly second that re-voting should be preventable by module core (better yet:by default). Re-voting kills Fivestar to an certain degree because its results loose "credibility".

I personally am not very good in patching. Argh.... I will give it a try (and ruin my day ;( ).

However Fivestar is a really cool module.

foaad’s picture

hi inqui,

I tried this patch but it's not working for me. In Drupal 5.16, using IE7, I can duplicate the problem of endless re-voting by the same registered user.
After applying your patch to both .module and .js files and refreshing the page, when I click to re-vote it still lets me do it, i.e. the widget is clickable. But it also hangs forever saying "Saving your vote" until I reload the page.

any ideas?

Thanks.

quicksketch’s picture

I strongly second that re-voting should be preventable by module core (better yet:by default). Re-voting kills Fivestar to an certain degree because its results loose "credibility".

I don't know why this isn't clear: each user only gets one vote no matter how many times they click the widget. They're not repeatedly voting, they're just changing their vote. Even anonymous duplicate votes are prevented, despite the widget loosing it's value for anonymous users.

dddave’s picture

Hi quicksketch,

I am very sorry but I really did not get it in the first place. I was testing it exstensivly and I could swear the text beneath the widget counted each vote.
At that time I was wondering how such a thing could be missed. Sorry for causing any inconvinience. I am going to change my vote at drupalmodules.

Thanks for this perfect module. :)

Apollo610’s picture

Quick - I think the whole point of the thread (well, MY intent when I started the thread) was to find a way PREVENT the user from revoting - meaning prevent them from changing their vote (thus, voting again). I never referred to multiple votes for a single user...

Is there a way to just display a static version of the fivestar widget with the current statistics? It's probably just as simple as throwing an IF statement in the formatting.

quicksketch’s picture

Is there a way to just display a static version of the fivestar widget with the current statistics? It's probably just as simple as throwing an IF statement in the formatting.

Yes, you could easily do this in the current system by overriding theme_fivestar and then calling theme('fivestar_static') if the user has already voted.

Apollo610’s picture

Thanks quick - when I originally posted my inquiry I was a little greener to Drupal. Slowly getting there.

Now, in your opinion what's the best way to check to see if the user has voted? I've already themed the node in its own tpl.php, so that's where I'm adding my condition.

<?php if ((user voted on this node) || ($node->uid == $user->uid)): ?>
        <div class="fivestar"> <?php print fivestar_static('node', $node->nid, $node->type); </div>
<?php else: ?>
	<div class="fivestar"> <?php print fivestar_widget_form($node); ?> </div>
<?php endif; ?>

I did a DSM on the entire page and don't see any stored variables that I would be able to use for this condition, is that correct? Ideally I'd want to pull something like $node->content['fivestar_widget']['myvote']['#value'] .

Thanks!

mapcuk’s picture

Assigned: Unassigned » mapcuk

I wrote a patch for fix that.
And patched module here.

marvs’s picture

Add this in template.php

if (!votingapi_select_votes(array('uid'=> $vars['user']->uid))) {
$vars['fivestar_widget'] = $vars['node']->content['fivestar_widget']['#value'];
}
else {
$vars['fivestar_widget'] = fivestar_static('node', $vars['node']->nid, NULL, $vars['node']->type);
}

halfabrain’s picture

Dear all

I tried your solution and while it worked it was confusing as the comment still showed the vote option, only that they couldn't use it. I'm looking for a real rough and ready solution...

What I'm looking for is to write some PHP that will look to see if a user has already commented and/or voted on a node (in my site you have to vote when commenting, so either can be used) and if they have, echo '

.box{display:none;}

' thereby removing the comment box completely.

However, my woeful PHP skills are letting me down and I can't make it work. Please can someone provide me with the code that I would need to make this happen?

Cheers

H

halfabrain’s picture

Hello again everyone. Well I got my rough and ready solution to work by inserting this into the top of my comment.tpl.php file.

 global $user;
if($user->uid == $comment->uid){
  echo '<style>.box{display:none;}</style>';
}

I know this is bad form for two reasons:
1. I have hacked a core module;
2. Using CSS is not ideal as it can be turned off and the site abused.

So if anyone can help me improve I would really appreciate it. Please can you tell me how I can amend the comment.tpl.php without hacking core and also can you tell me how I can simple say "comments not displayed" in Drupal if the above if statement is true?

Any help much appreciated,

Thanks

H

fhoubart’s picture

Title: How to Set Manual Fivestar to Prevent Revoting » Don't let user to change his vote or re-vote
Version: 6.x-1.13 » 6.x-1.19
Category: support » feature

+1 subscribing.

Very important for me to add this feature. Anyone?

fhoubart’s picture

Assigned: mapcuk » Unassigned
cepiat’s picture

i need to this request it's very very important for me , i try different solution but nothing really good.

deith’s picture

+1 subscribing.

Luciuz’s picture

i have the same issue

jghyde’s picture

Version: 6.x-1.19 » 6.x-2.x-dev
StatusFileSize
new3.83 KB

Here is a patch rolled against the latest CVS 6.x-2.x-dev. It does the following:

If the admin UNchecks the $settings['unvote_enable'] ---> 'Allow users to undo their votes. If this is not checked, the user will be presented with a static widget if they return to the page after previously submitting their vote,' the users who have already voted will be presented with the static widget.

The title of the widget is also changed to 'Thank You for Your Rating."

The code may be a little heavy, since it is required to lookup the vote for each $tag. But that's the only way I could make it work without more radical refactoring.

Joe aka Texas on irc
http://www.hydeinteractive.com/

wrd’s picture

I don't know why this isn't clear: each user only gets one vote no matter how many times they click the widget. They're not repeatedly voting, they're just changing their vote.

I realize it's still in development, but just in case it hasn't been noticed yet, this is not the case in 7.x-2.x-dev. I can click the widget a dozen times, and see twelve additional votes tallied up on the node. I can see a tally of eleven votes on a single node, with an average rating of 47.2727 percent, on a system that has only two users (and is currently impossible for anonymous users to reach, as it's only accessible from my desktop).

Taxoman’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Category: feature » bug

Sounds like a bug (..?!), and should be done for 7.x and then perhaps backported.

ericduran’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev

@taxonman, Is this a bug in the 7.x branch? If not it shouldn't be switch version also if it is please create a new issue for the 7.x branch.

pbuyle’s picture

ericduran’s picture

Category: bug » feature
Status: Active » Needs review

This is at best a feature request.

Later in the day I'll check out the patch.

Has anyone reviewed this patch? Does it apply cleanly?

Taxoman’s picture

@ericduran: initially a feature request, yes, but then #1 states "i 'm having the same problem. there is an option " alow user to undo vote", but this is not activated, but still the user can switch from 1 to five stars all the time."

Therefore I assume it is perhaps also (combined with?) a bug?

ericduran’s picture

Hey @ Taxoman,

If thats the case then comment #1 should open a new issue with his problem. The origin issue is for a feature request.

So we'll just leave it as a feature request for now. The allow users to undo their votes is a completely different topic which works as far as I can tell.

bojanz’s picture

I ran into this on 7.x
I have fivestar on comments, pointing to fivestar on the node. I can add 5 different comments with five different ratings. The node rating will only display the last one.
Makes sense to me that the widget is no longer present after the first vote (comment).

Sylense’s picture

subscribe - D7.

i would like to prohibit a user from changing his/her vote. Possibly display a system error message that indicates that they have already voted or just replace the widget all together.

ramlev’s picture

I have made a patch for 7.x-2.0-alpha1 which adds a admin field setting to set if you want users to be able to changes the vote. If the user cannot re-vote, then the fivestar_static theme is fired, otherwise the fivestar_select theme function is fired.

Let me know if this works.

I will make a patch later on, which will work with the 7.x-2.x dev branch.

Status: Needs review » Needs work

The last submitted patch, dont-let-user-to-change-his-vote-or-revote-356605-29.patch, failed testing.

ramlev’s picture

Status: Needs work » Needs review
StatusFileSize
new9.37 KB

Heres the patch that works for 7.x-2.x dev branch.

Status: Needs review » Needs work

The last submitted patch, dont-let-user-to-change-his-vote-or-revote-356605-30.patch, failed testing.

ramlev’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

Changed version, since we're on 7.x now

ramlev’s picture

Status: Needs work » Needs review
Issue tags: -re-voting

Status: Needs review » Needs work
Issue tags: +re-voting

The last submitted patch, dont-let-user-to-change-his-vote-or-revote-356605-30.patch, failed testing.

danihobbs’s picture

#31 THANK YOU for this patch - you saved the day! It works perfectly.

ericduran’s picture

If we could get the test passing I'll love to commit this.

BeaPower’s picture

Is this committed now?

ericduran’s picture

This breaks the "User can cancel his vote" test. The test needs to be fixed. Once this is fixed then I have no problem committing this.

ramlev’s picture

New patch created and added a test to test if re-voting is possible.

ramlev’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, dont-let-user-to-change-his-vote-or-revote-356605-40.patch, failed testing.

ramlev’s picture

Status: Needs work » Needs review
StatusFileSize
new9.73 KB

New try, removed a bunch of warnings.

BeaPower’s picture

will this option be committed soon?

lhugg’s picture

After patching the dev version and replacing the fivestar alpha2 release with the patched dev code, the application threw the following errors when caches were cleared or existing fivestar fields were edited:
Warning: Cannot use a scalar value as an array in form_builder() (line 1800 of D:\xampp\htdocs\readerrap714\includes\form.inc).
Warning: Cannot use a scalar value as an array in form_builder() (line 1820 of D:\xampp\htdocs\readerrap714\includes\form.inc).
Warning: Cannot use a scalar value as an array in form_builder() (line 1825 of D:\xampp\htdocs\readerrap714\includes\form.inc).
Warning: Cannot use a scalar value as an array in form_builder() (line 1829 of D:\xampp\htdocs\readerrap714\includes\form.inc).
Warning: Cannot use a scalar value as an array in form_builder() (line 1725 of D:\xampp\htdocs\readerrap714\includes\form.inc).

Do we have to strip out everything we've already built using fivestar and redo the rating fields with the patched version?

lhugg’s picture

This patch doesn't seem to work for fivestar ratings on comments that refer to a parent node.
The final decision on edit/noedit looks like it's make in "fivestar_allow_revote", but the $element array passed in does not contain $element['#settings']['content_id'] or $element['#settings']['content_type'], so the final boolean returned is TRUE meaning editing is allowed.

$criteria = array(
    'entity_id' => isset($element['#settings']['content_id']) ? $element['#settings']['content_id'] : FALSE,
    'entity_type' => isset($element['#settings']['content_type']) ? $element['#settings']['content_type'] : FALSE,
    'uid' => $user->uid,

  );
lhugg’s picture

The errors in #45 were caused by '+'s and some other extra characters that were inserted into the patched code. Could have been caused by my patch utility, since no one else seems to be having this problem. If you do, just edit your final code to clean up.

lhugg’s picture

Status: Needs review » Active

Sorry for not understanding the protocol, but did I need to remark this 'active' when I posted #46 above in order to get someone to look at it? Setting to 'active' here.

I've tested the patch, and it doesn't seem to work - see #46.

ramlev’s picture

Have created a path which works with the alpha-2 release

ramlev’s picture

Status: Active » Needs review
StatusFileSize
new7.33 KB

New patch to alpha-2 with some fixes.

Status: Needs review » Needs work
ramlev’s picture

Patch for alpha-1

ramlev’s picture

Status: Needs work » Needs review
StatusFileSize
new9.45 KB

Fixed bug in patch for alpha-1

Status: Needs review » Needs work
Issue tags: -re-voting
teami’s picture

Status: Needs work » Needs review
Issue tags: +re-voting
DevneelLoki’s picture

Has there been an update for this patch? Currently, leaving the "Allow users to cancel their ratings" unchecked still allows users to change their ratings.

cptlonestar’s picture

Following +1. I'm having the same issue as well. Unfortunately I'm a beginner in php and therefore cannot come up with a solution. Really looking forward to the updated module change that allows only one comment/rating per user.

cptlonestar’s picture

For those of you who may not be PHP savy like me, I found a module that works great to limit a user vote AND comment to only once.

Comment Limit

It obviously doesn't upgrade Fivestar but it solves the immediate issue. See Issues - Where's the UI to configure the actual comment limit for individual nodes.

mxt’s picture

In replay to Bojanz in #27:

I have fivestar on comments, pointing to fivestar on the node. I can add 5 different comments with five different ratings. The node rating will only display the last one.
Makes sense to me that the widget is no longer present after the first vote (comment).

I've found a workaround for this, take a look to: http://drupal.org/node/211517#comment-7263148

This is useful for situations where you want people do comment more than one time but allow only and only one vote for pointed node.

Hope this help

matt.rad’s picture

Subscribing.

whiteph’s picture

Issue summary: View changes
Status: Needs review » Fixed

Re #45 - this was a typo in the patch, in function theme_fivestar_preview_widget($variables). 'allow_revote' => TRUE, instead of '#allow_revote' => TRUE. That typo was fixed in later versions of the patch, but there was confusion due to naming of …alpha1 instead of …alpha2.

I've applied the patch from #50, as that was the one pertaining to alpha2, the latest version at the time the patch was created. I've fixed the typo.

I've also added fivestar_update_7206(). This sets all existing fivestar widgets to have re-voting allowed, otherwise 20,000+ sites running fivestar may get a surprise to find that the existing behaviour of allowing re-voting is now being blocked.

So, be sure to run the update program before you edit your fivestar widgets in the admin system, otherwise when the update program runs you'll lose any changes you make allowing re-voting.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Status: Closed (fixed) » Needs review

Status: Needs review » Needs work