4

I'm having a very difficult time figuring this out, and I'm wondering if it's even possible. I'm using organic groups 7.x-2.x, and I have two "group" types: a student group type and a faculty group type. I also have a "group content" type called blog posts which can post in either group type. What I would like to do is create two views, one to show all blog posts that got posted in all student groups, and another to show the same for faculty groups.

Can anyone provide me insight into how to do this?

Side note: Since OG has switched to using entity reference to assign group membership, I thought it would easy to use this relationship in views to accomplish this, but it looks like it is only using entity reference for the widget, and does not store the data as a normal entity reference field would. Everything I tried with the og_membership relationship seemed to fail, so I'm at a loss here. Any help would be appreciated!

3

Wow, I actually figured this out. Basically you need to do the following:

  • Add the "OG Membership: OG membership from Node" relationship to the view.
  • Add the "OG Membership: Group Node from OG membership" relationship, assigning the above relationship.
  • Add a Filter Criteria of "Content: Type" = the group content type you want to show, and (here is the trick) assign the above relationship for this.

Here is a screenshot that might be more helpful:

enter image description here

enter image description here

2

I have no idea how to do it using views gui but I can tell you how to write your own query which you can use to override the query from views to display it.

All the data you need will be stored in 2 tables

field_data_group_audience.entity_id   // node id of the content you are looking for
field_data_group_audience.bundle      // type of content in your case blog posts

JOIN
node -> type // equal to student group or faculty group

because nid of a group is not the same as gid of a group you have to join the two tables using og table

JOIN
og 
WHERE
og.etid = node.nid
AND
og.gid = field_data_group_audience.group_audiance_gid

This should result in something similar to this:

$query = db_select('field_data_group_audience');
$query->join('og', 'og', 'og.gid = field_data_group_audience.group_audiance_gid'); 
$query->join('node', 'node', 'og.etid = node.nid'); 
$query->addfield('field_data_group_audience','entity_id','tricky_name_expected_by_views');
$query->condition('field_data_group_audience.bundle', blog post,'=');
$query->condition('node.type', 'student group','=');
$view->build_info['query'] = $query;

Once you have a working query you plug it into views using hook_views_pre_execute. https://drupal.stackexchange.com/a/56322/12153

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.