Closed (won't fix)
Project:
Vote Up/Down
Version:
6.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Mar 2009 at 22:29 UTC
Updated:
8 Jun 2010 at 20:25 UTC
Jump to comment: Most recent file
Comments
Comment #1
pfoucher commentedI am actually trying to achieve the same thing. ( thumbs up, thumbs down kind of thing)
I think that one way to do it would be to rate negative votes as "0 point" whereas positive votes are equal to "1 point".
Then, the negative votes count could be the difference between total votes count and sum of points.
Your positive votes count will be the sum of points.
To do this, I had a look at votingapi in order to hook before inserting the vote in database and modify the value of negative vote from "-1" to "0".
The only thing is that the hook_insert happens after the insert in database.
One other way to do it would be to alter vote up/down module so that you can choose the points value for each positive or negative vote.
Anyway, i am still testing, will let you know if i have any success.
:)
Comment #2
poloparis commentedHey lafouch
for what it's worth, i've kind of dabbled with that module and voting_api to write a small module to promote nodes to front page based on voting results of the vote_up_down module and i have used the following hook to do so, on line 397 of the votingapi.module :
// Give other modules a chance to act on the results of the vote totaling.
module_invoke_all('votingapi_results', $cached, $content_type, $content_id);
and found out the following to use in my module :
$cached[0]['value'] returns the total number of votes
$cached[1]['value'] returns the average result, bet 0 & 1 (or if you want , in percentage, the sum of + & - votes div by total votes)
$cached[2]['value'] returns the sum of + and - votes
hope that helps
Comment #3
jefftrnr commentedHi lafouch,
I have had success with the following theme override. Just paste it into the template.php file in your theme's folder.
poloparis shows you can get three different results from the results array, but actually, the key was to switch the votingapi function to select_votes rather than select_result_value. I then used php to tally up the votes for either 1 or -1 values. Anyway, the code below should be close to what you're looking for.
Comment #4
pfoucher commentedThanks to both of you,
i finally used the hook_votingapi_results_alter in the following way to get :
- negative votes, positive votes and percentage of positive votes among all votes
then the values are available with the votingapi_select_results($criteria);
Comment #5
tommytom commentedCan somebody help me with one function.
I want to implement hook_voingapi_results_alter() in vote up down module.
I have this code for votingapi version 1.x , I'm trying to change it to version 2.x .
I don't know how to check the current vote value : if ($vote->value == -1) -this doesn't work in votingapi 2.x
please help.
In version 2.x it doesn't get the $vote->value .
This hook_votingapi_calculate(&$cache, $votes, $content_type, $content_id) has changed to hook_votingapi_results_alter(&$cache, $content_type, $content_id) .
What happen with the $votes array ? How can I get the current vote value ?
Comment #6
totaldrupal commenteddid you get this to work?
Comment #7
tommytom commentedyes but not with this hook. I had some problems with the implementation so I modified the voting api module.
I added this 3 lines to votingapi:
and it works fine for me. However, it's not a good idea to do it this way. It should be done with this hook:
hook_voingapi_results_alter() in vote up down module !!!!!!!!!!!!!!!!!
Now it calculates the values everytime somebody votes.
To see the result you have to add this to the theme function of vote up down module:
and you have to edit this file: vote_up_down_points.tpl.php
The up point are stored now in $points_up_labelled.
For example you can add this 2 lines to the tpl file:
You also may want to edit the css file.
Comment #8
tommytom commentedif you have the voting counts and sum, you can calculate the ups and downs :
downpoints = (count - sum) /2
uppoints = count - downpoints
Comment #9
socialnicheguru commentedsubscribing
Comment #10
totaldrupal commentedTried to get this to work but I'm not a programmer and good with code so I'm sure I screwed it up. Do you only add the code or do you need to modify the existing code? Maybe you could dumb it down for me so I can get this working. Thanks.
Comment #11
mcload commentedsubscribing
Comment #12
aac commentedPlus vote = Number of Plus votes
Minus vote = Number of Minus votes
count = Plus vote + Minus vote
sum = Plus vote - Minus vote
Solving these equations give the following results for Plus and Minus votes-
Plus vote = (count + sum)/2
Minus vote = (count - sum)/2
Now these can be used in the vote up down module to get the desired results. I think it does not require to alter votingapi module.
Comment #13
socialnicheguru commentedsubscribing
Comment #14
davedg629 commentedI got this to work with one small problem. When I view a node that his this voting enabled, the results say 0 up 0 down. Then when I vote "up" I see 1 up 0 down 0 down. The extra "0 down" is the problem. If I switch the order of the results it does the same thing. Obviously the second result that is being shown is not getting cleared. When I print only the up results or only the down results everything works fine. So there must be some place in the code where you have to tell it to clear both values instead of just one.
Dave
Comment #15
davedg629 commentedHere is where I put the code in the votingapi.module file:
Here is where I put the code in vote_up_down.module:
Then just modify vote_up_down_points.tpl.php the way tommy said so. Just a little clarification for those who don't know exactly where to put this code.
Comment #16
davedg629 commentedI am still having trouble with the results not being cleared after a new vote is cast.
I've attached two images that show what is going on.
The first image shows a node for Derek Jeter where one person has voted "up". As you can see it is working correctly - showing 1 up vote, and 0 down votes.
The second image shows what happens after I change this vote to "down". As you can see here, there is an extra "0 down" appended to the end of the results.
It should also be noted that the same thing occurs if I click the "up arrow" after I have already cast a vote. The results aren't effected (so its not like I am voting again), it just displays the "0 down" to the right a second time.
Comment #17
davedg629 commentedI think some of the ajax code needs to be changed to get rid of this problem.
Comment #18
davedg629 commentedo yea, changing this to beta6
Comment #19
khanz commentedIs there any way of doing, without hacking the core mod. i am not a programmer so plz be easy on the step of doing it.
Comment #20
davedg629 commentedOkay, fixed my problem detailed in #16.
Changes need to be made to the code in the vote_up_down.module file and the vote_up_down_points.tpl.php.
Here is the correct code for the vote_up_down.module file:
With this change to the variables['points_labelled'], the tpl file must be changed to this:
But like khan said, a solution needs to be outlined where hacking the module is not needed. Don't know much about overriding functions, but if someone does help is appreciated. Until then I'm just gonna go with this hack.
Comment #21
aac commentedI would like to know, how can i write a module to promote the nodes on the front page based on number of votes.
Thanks for your any help.
Comment #22
john.kenney commentedI'd really like to get this to work, but have tried a few times and not getting it. Or maybe I am getting it, but I don't know how to print the result?
I have tried to follow the directions above - largely #7, #15, and #20 as follows:
1. Modify votingapi.module with code inserted as shown here:
2. Modify vote_up_down.module as shown here:
3. Modify vote_up_down_points.tpl.php as shown here:
davedg629 or others, can you confirm this code is correct? I've put it all in place - but not getting a result. Not getting any errors, either, so if it is working, I guess next question is how do I get at the data? What variables do I use to print them to my pages?
I am using on a page with CCK variables. From Contemplate, I got this for printing the widget:
<?php print $node->content['vote_up_down']['#value'];?>This works fine - votes are being recorded, but there are no variables shown in Contemplate to display the up / down results - perhaps that is because the above bits aren't working or perhaps because they are to be found elsewhere. I tried various things, but nothing worked - which isn't surprisingly cause I haven't got a clue what I'm doing.
Can someone offer advice how to get this working?
Thank you!
Comment #23
HunterElliott commentedThis may not be what you want since it uses an external 3rd party system, but the easiest way I've found to implement this is to use the Nero Rating System from polldaddy.com. You will need to sign up for an account there, but you can do this with the basic/free account.
Just log in to your acct at polldaddy.com. Under the Account tab, there will be an item called "Ratings" (at this point in time, it has a 'beta' label on it). Click on Ratings and then click on the button that says Create New Rating. Choose a "Nero" style for thumbs up/down. Give the rating a name that you'll remember - you do NOT need to create a separate rating for everything on your site, you only need to create one, really.
Once you create a rating, it will give you some embed code for your site. Copy this code and put it in your relevant .tpl file. The DIV in the code will have an ID in it - keep the ID, but you may want to give it a CLASS for your own styling. The only line you *really* need to change here is the line that has the Unique ID; here I just plopped in the Node ID for it, but you can put something else text-wise at the front/end/both of it to make sure: "unique_id" : " (use the php tags around the following) $node->nid; "
If you want different images for the thumbs, polldaddy.com gives you the option list an image of your own (you'll need to host the image on your site).
(and no, I am in no way affiliated with polldaddy - just letting people know about it as so many people want to use this kind of thing)
Comment #24
HunterElliott commentedAfter playing around with the polldaddy code, which BTW did NOT work as "published" from their site, I did find out what was needed to change.
If you do use said code, this is what you need to do to get it to work if you're displaying say a list of 10 items from a blog post via a query...
The code they give you needs to be modified as follows:
< div id="pd_rating_holder_Number_identifyingText(nodeID)" >< / div>
< script language=" javascript" > //remove the "text=" value that is in the PD generated code
PDRTJS_settings_Number_identifyingText(nodeID) = ({ //IMPORTANT - make sure to add a "(" before the brace
"id" : "Number",
"unique_id" : "value", // here I used a value of the userID, a comma, and then the nodeID - this *cannot* be the same as the item_id
"title" : "", // if you use a value here, like the node Title, make sure that it is NOT linked to the node - create another Title value in your query and make sure it's not linked
"permalink" : "",
"item_id" : "_identifyingText(nodeID)"
}); // IMPORTANT - make sure to add a ")" after the brace -- the parentheses are not in the PD generated code
I hope this helps someone - it was a PITA to figure out since the info from PollDaddy was not correct. FWIW, PD says they're planning on releasing a Drupal module for their rating system sometime this year.
Comment #25
Gabriel R. commentedI am looking for a clean solution that only involves Views.
I have a a hunch that the answer could be in the Other option for Aggregation function. See the attached image. Is there any documentation I could use for it?
Comment #26
trevorleenc commentedwill any of this work with 2.x-dev ?
Comment #27
szadok commentedI have used jefftrnr (#3) solution with version 1.0 and it worked for me perfectly, thanks a lot !
Comment #28
gausarts commentedSubscribing. Thanks
Comment #29
kscheirerI think you guys are making this way harder than it needs to be - the solution aac posted in #12 is correct.
Vote Up/Down normally just tells you the Count (total number of votes) and Sum (# positive votes - # negative votes). Based on only those 2 values, you can get the total number of up votes and total number of down votes. So it just requires a little extra logic in the template preprocess function which is easily overridable, and should not need any changes to the module or votingapi.module.
The total number of down votes is (Count - Sum) / 2. Once you know that, the total number of up votes is (Count - # of down votes).
I'll post the theme override function I used. Honestly I think this should be the core way of displaying vote totals. Or possibly provide these values to the theme functions by default, and make it easier for folks to display what they want.
Comment #30
kscheirerThis is the override function. Really I just added the lines in the middle - the rest are standard from the modulel.
and then in my theme's vote_up_down_points.tpl.php
Comment #31
kerberos commented@ #30:
Very helpful, thanks!
-Daniel
Comment #32
sotiris commentedIn which version do we have to apply the #30 code? I did with beta-6 but it does not work as well as expected. It counts every like vote for 0.5 point, and it doesn't count dislikes at all... (In the voting details tab, i have correct counting of votes +1 -1)
Update: I forgot to change $vote_result to $vote_sum, after this change your code worked as expected,
Thank you so much!
Comment #33
ccshannon commentedSubscribe from my iPhone so I can implement this when I get home.
Comment #34
ccshannon commentedAnd it worked beautifully.
Many thanks!
Comment #35
ckreutz commentedDoes anybody has a solution for the same issue for the 6.x.2.x-dev version? It seems the module has changed a lot and the above version e.g. #30 cannot work.
Comment #36
AntiNSA commentedSubscribe
Comment #37
DomDoze commentedSubscribe
Comment #38
marvil07 commentedjust to mention that there are plans to include this on 6.x-2.x also ;-) #811694: New widget for splitting of votes in positives/negatives (5 voted up, 2 voted down)
Comment #39
marvil07 commentedNo more features to
6.x-1.x, please take a look to the update on the project page.