1

I installed the modules "rate (voting widget)" and "voting api". These modules work very well. I use views to get a list of nodes, and I added the voting results. Now I get a row for each vote, not for each node...

Views rows:

Node 1  --  angry: 1  happy: 1
Node 1  --  angry: 1  happy: 1

Node 2  --  angry: 1  happy: 0

Node 3  --  angry: 0  happy: 1

I want to group the results by node id, but this doesn't seem to work. what would be the easiest solution for this problem?

1

You can use hook_query_alter() in your custom module. Your code should look like this:

function MODULENAME_query_alter(&$query) {
  if(!empty($query->alterMetaData['view']->name) && $query->alterMetaData['view']->name == 'VIEWNAME'){
    $query->groupBy("node.nid");
  }
}
  • Hmm, this sounds like a very good idea, thanks in advance! – screaming SiLENCE Oct 28 '13 at 14:57
0

Easiest way is to use the built in aggregation functions in views / voting api. Select 'Relationships' under the 'Advanced' tab and add a relationship based on vote results:

Content: Vote results
Aggregate results of votes cast on Node.

The settings page lets you select whether you are aggregating for total votes, total score or even looking for an average.

  • But I want to show ALL results (emotions in my case). So I want to show: "node Angry:1 - Happy:1", but because of the two votes I get 2 results in views. I don't want the total of all votes... – screaming SiLENCE Jul 25 '13 at 15:27
  • ok - maybe all you need is to add a distinct setting to your view to get views to clear up the confusion. Try this under 'Advanced: Query Options' and check the 'distinct' checkbox. If that doesn't work, you might want to try posting your view because there's something in the view configuration that is causing it to repeat these. – schnippy Jul 25 '13 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.