How to Set Manual Fivestar to Prevent Revoting

Apollo610 - January 9, 2009 - 17:40
Project:Fivestar
Version:6.x-1.13
Component:Code
Category:support request
Priority:normal
Assigned:mapcuk
Status:active
Issue tags:re-voting
Description

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!

#1

creamneuron - January 29, 2009 - 23:47

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

inqui - February 6, 2009 - 00:21

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

dddave - February 10, 2009 - 00:04

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

foaad - March 3, 2009 - 00:45

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

quicksketch - March 3, 2009 - 03:03

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.

#6

dddave - March 3, 2009 - 07:31

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

Apollo610 - March 3, 2009 - 12:00

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

quicksketch - March 4, 2009 - 04:29

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.

#9

Apollo610 - March 4, 2009 - 14:14

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

mapcuk - August 14, 2009 - 01:57
Assigned to:Anonymous» mapcuk

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

#11

marvs - August 28, 2009 - 09:44

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

halfabrain - October 13, 2009 - 19:21

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

halfabrain - October 14, 2009 - 10:22

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.

<?php
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

 
 

Drupal is a registered trademark of Dries Buytaert.