Posted by Apollo610 on January 9, 2009 at 5:40pm
| Project: | Fivestar |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | re-voting |
Issue Summary
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
#1
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
#2
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.
#3
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.
#4
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.
#5
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.
#6
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. :)
#7
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.
#8
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.
#9
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!
#10
I wrote a patch for fix that.
And patched module here.
#11
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);
}
#12
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
#13
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.
<?phpglobal $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
#14
+1 subscribing.
Very important for me to add this feature. Anyone?
#15
#16
i need to this request it's very very important for me , i try different solution but nothing really good.
#17
+1 subscribing.
#18
i have the same issue
#19
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/
#20
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).
#21
Sounds like a bug (..?!), and should be done for 7.x and then perhaps backported.
#22
@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.
#23
Maybe this issue the 6.x version of #1155036: The module allows multiple vote from the same user for the same node ?
#24
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?
#25
@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?
#26
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.
#27
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).
#28
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.