Voting API doesn't show nodes with no votes in Views 2

dwees - October 16, 2008 - 13:29
Project:Voting API
Version:6.x-2.x-dev
Component:Code
Category:task
Priority:critical
Assigned:Unassigned
Status:closed
Description

So after looking a lot, I finally realized what the problem is. This issue made me realize the solution #284292: Where's Views Argument Handling Code

The votingapi_cache table is inner joined to the node table. This means that the intersection of the nodes in the node table and the nodes in the votingapi_cache table are shown. What I really wanted instead was all of the possible nodes + the fields from the nodes which had been voted on. This is a left join instead.

So I created a very, very small module to do this, and I need feedback to make sure this will work as I expect it to.

In a module, I called it site_tweaks.module I put the following:

<?php
// $Id$

/**
* @file
* Makes minor tweaks in a few modules
*/

/**
* Implementation of hook_views_query_alter().
*/
function site_tweaks_views_query_alter(&$view, &$query) {
 
// note here: if you want to affect your views, you need to put your view names in there.
 
if ($view->name === 'My_Resources' || $view->name === 'All_Resources') {
   
$query->table_queue['votingapi_cache_node_percent_vote_average']['join']->type = 'left';
  }
}
?>

(include the php tags).

In another file called site_tweaks.info, I put the following:

; $Id$
name = Site Tweaks
description = Modify other modules in here.
package = Pedagogle
core = 6.x

I placed both of these inside a folder called site_tweaks in my modules folder. Enabled the module. Navigate to my view, and voila, all of my nodes of the appropriate type, including ones without any votes, are included.

If this is the right way to do this (and I tried every possible way I could think of using the Views UI), can we add this to the documentation for this module?

#1

moshe weitzman - October 22, 2008 - 00:03

Usually this table gets joined using a relationship. The INNER JOIN happens if you check the box 'require this relatonship'. At least thats my first thought upon reading this ...

#2

dwees - October 22, 2008 - 05:02

Hrmm, well let me test it and confirm you are right. I do see I have checked "require this relationship".

Dave

#3

drewish - January 9, 2009 - 19:00

subscribing. my problem seems similar but may be a separate issue. i've got require this relationship disabled but i need the sum of votes and for nodes without votes they aren't included.

#4

drewish - January 9, 2009 - 20:29
Status:active» needs review

talked to merlin on irc and he suggested using COALESCE(field, 0) to force the NULL values to zero so the could be compared. i extended views_handler_filter_numeric to force the operators to coalesce. all-in-all a pretty simple fix that works like a charm.

AttachmentSize
votingapi_322088.patch 2.86 KB

#5

drewish - January 9, 2009 - 20:42

[12:36pm] merlinofchaos:
drewish: Smaller patch: Override $query instead of the operators, and change $field directly
[12:36pm] drewish:
merlinofchaos: well the thing i like about this is that i still allows is null
[12:36pm] drewish:
if you want it
[12:36pm] drewish:
or is not null
[12:37pm] drewish:
merlinofchaos: would that work overriding query?
[12:37pm] merlinofchaos:
OH I see.
[12:37pm] merlinofchaos:
Hm.
[12:37pm] merlinofchaos:
You're right that would break those operators.
[12:37pm] merlinofchaos:
Carry on then!

#6

computer_jin - January 23, 2009 - 12:48

Hi every one,
I am using votint module and its working fine at my local pc but when i use this from my server its working but voting images not showing to vote some onee....please tell me how can i solve this issue .....

#7

eaton - January 23, 2009 - 17:43
Status:needs review» fixed

Just committed this to the dev branch. Thanks, drewish!

#8

System Message - February 6, 2009 - 17:50
Status:fixed» closed

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

#9

Büke Beyond - March 7, 2009 - 06:15
Component:Documentation» Code
Priority:normal» critical
Status:closed» needs work

"votingapi_views_handler_filter_value.inc" is missing on the Dev release.

#10

lelizondob - May 15, 2009 - 17:12

I'm also getting this error

#11

eaton - August 15, 2009 - 17:53
Status:needs work» fixed

This has been fixed for a while in the official supported releases.

#12

System Message - August 29, 2009 - 18:00
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.