Download & Extend

Getting a view to sort from positive to negative

Project:Vote Up/Down
Version:6.x-2.x-dev
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:comments + views, comments up down voting, sort comments

Issue Summary

I can only get a view to sort total votes and not the average from going from positive to negative. Anyone know how to do this?

Comments

#1

Got it to work but doesn't make sense. Had to sort the view based on the field (title, picture etc.) not by votes. I don't know why but it works.

Could not get the view to show vote total though, only a -1 or 1.

#2

lost again. cloned the view, changed the node type and again it does not sort right.

#3

Subscribe - Any progress? - can't get views to sort by vote total

#4

Subscribe - I am at a loss. I've been playing around with this for a couple of days any the only thing I can conclude is that views will not sort unless it is in a field format as opposed to node format. I can get the vote up/down to sort by value if I have the view formatted as a field, but as soon as I switch to node, no dice.

Has anyone had any luck sorting nodes through views? If so what settings are you using? Is it possible to create a view block displaying nodes (not fields) with vote up/down enabled on it, and have it sort? This is a similar questions, but it seems vote up/down is treated differently as a block.

***Apologies, I switched to version 2.0 dev of voting API and this issue is fixed. If anyone is still having this problem with this version subscribe and I can post my views setting to get the ranking to work.

#5

Status:active» fixed

This is a votingapi issue, and it's fixed. :)

#6

Status:fixed» closed (fixed)

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

#7

Can you tell me how it is fixed?

#8

Hey, guys. I'm posting to let you guys know how I solved my issue.

My problem was I'm making a playlist site, and the playlist sorts by vote percentage. Of course, songs that have not been voted on = NULL, so the sorting returns +1, -1, then 0. For a playlist, it would make sense that songs that have not been voted on are treated as "indifferent", so -1 should fall below these.

They way I solved this was by (gasp!) adding a function to the module. Technically, you should make a separate module for this, but c'mon...

I posted this on the very bottom of vote_up_down.views.inc. I hope it's somehow useful to other people on this forum:

/**
* Implementation of hook_views_query_alter()
*/
function vote_up_down_views_query_alter(&$view, &$query) {
$query->fields['votingapi_cache_node_points_vote_average_value']['table'] = 'IFNULL(votingapi_cache_node_points_vote_average';
$query->fields['votingapi_cache_node_points_vote_average_value']['field'] = 'value, 0)';
}

#9

robobeau: I think you only want to check the checkbox "Require this relationship" on the relationship configuration "Node: Votes" to TRUE ;-)

#10

Here is the fix:

First, update to most recent releases of ctools, views, votingapi and vote_up_down

Make sure there are no database updates (visit update.php)

I am working with comments, so in my view I have the following

Relationships
==========
Add > Comment: Vote Results
Group Type: sum
Require Relations: NOT checked
Data Filters: All set to no filtering

Sort Criteria
===========
Add > Vote Results: Value
Group Type: sum
Relationship: Vote Results
Sort: Desc

Attached is an export to play with.

AttachmentSizeStatusTest resultOperations
comments_sort_desc_with_vote_up_down.txt8.18 KBIgnored: Check issue status.NoneNone
nobody click here