views:

573

answers:

1

(Also posted as http://drupal.org/node/596860)

I would like to create a view showing only those groups of which I am not already a member (or a pending member). However, the obvious way of doing this (take the og_my view and change the filter "Organic groups: Group member" to false) does not work.

The reason is that the SQL query essentially returns one row for every user in the group that matches your conditions. If you're searching for yourself (as in og_my), each group node will only show up once; if you're not searching for yourself, each group node shows up N times, where N is the number of other group members. Thus the groups of which I'm already a member continue to be displayed as long as there's at least one other member.

Does anyone have a way around this?

Thanks, Adrian

+1  A: 

You may not be able to achieve this in Views directly as it does not support subqueries. My SQL came out like so:

SELECT node.nid AS nid, node.title AS node_title  FROM node node   LEFT JOIN og_uid og_uid ON node.nid = og_uid.nid  WHERE (node.type IN ('campaign','setting','system')) AND node.nid NOT IN (select nid from og_uid where uid = 1);

It is said you can programmatically forward the results of such a query into the Views system for theming.

Maybe a special handling of the argument Organic Groups:Member of a Group, Exclude Argument option?

I also posted to d.o in hopes of pushing the issue conversation onward.

Grayside
My views knowledge is pretty fuzzy - do you think you could define that subquery in an og_views handler and get it into the Views query that way?
Adrian
I have no idea. Views itself doesn't handle subqueries, so this would be a patch job until that is resolved. I would try the programmatic invocation of the view with that SQL query first.
Grayside
You can use hook_views_query_alter to modify a view so that it produces the result you want. See http://www.nicklewis.org/hook-views-query-alter-how-programatically-alter-views-queries for an example.
David Wees

related questions