Hi wonderful drupal community,

I want to create a block for organic groups pages which displays "last five documents posted in group" or similar. Basically, I want to create an alternative layout for the groups pages wich has blog posts as "river of news" and then other content as "group by content" in blocks or otherwise on the side. I understand that I need to use the views function to create block, but have no idea how I filter content by "in current group". Is arguments the solution? Any guidance or ideas are appreciated.

Thanks,
Espen

Comments

espry’s picture

http://drupal.org/node/90149

But there are no answers

somebodysysop’s picture

First, you'll want to create the view as a block, so don't forget to check "Provide Block" box in "Block" section of admin>>views>>add view

In the "Filters" section, you'll want to add "Node Type" (select the node types you want listed in the block) as well as "Og: Post in User Subbed Groups".

So far, you now have a block which will list all node types from groups that the current user is subscribed to.

Now, if you want only the last 5 posts listed, then in "Sort Criteria" section you'll need to add "Node Created Time" in descending order. In the "Block" section you should enter "5" in the "Nodes per Block" field. Click on the "More" checkbox if you want the option to see more posts than the last 5.

Does this answer the question?

espry’s picture

Hmmm, thanks for the attempt, but I do not think you are addressing exactly what I want.

Basically, I want to change the layout of the group homepage, not depending on what the user subscribes to, but what is posted in the current group. The filter I would need is something like "Og: Post in Current Group". I thought maybe I could get "current groupid" through an argument, and filter that way, but I have not sorted that out.

Since I last posted, I have seen the following two posts which describes exactly what I want, and go some way in addressing the issue, but does not provide an answer.

> http://drupal.org/node/87352
> http://drupal.org/node/88250

Contacted sodani about these poste directly, but he has not figured it out.

Do you have any idea how to do this? Or work around it with blocks, as I suggested?

espry’s picture

The answers you just posted at
http://drupal.org/node/90149#comment-168744
seems more along the lines of what I want...

somebodysysop’s picture

Sounds like I'm already doing what you wish to do. You just need to figure out how to tell if you're in a group or if the nodeID is an OG group.

  $group_node = og_get_group_context();
  $gid02 = $group_node->nid;
  $gid = (int)$gid02;
  if ($gid02 === null) $gid = 0;
  $output .= "<li>You are currently in group : " .  $gid;

Another way to determine if this is a group node:

$nodeID = (int)arg(1); // as in http://www.mysite.com/node/70
$result = db_query("select node_access.gid from node_access INNER JOIN og_uid ON node_access.gid = og_uid.nid WHERE node_access.realm = 'og_subscriber' AND node_access.nid = $nodeID AND og_uid.uid = $userID");
 while($t = db_fetch_object($result)) {
      $output .= "<br>The groupID is : " . $t->gid;
 }

Here's some code I created to see if this is the group home page:

<code>
            // This function is designed to bring back an array of groups for this $nodeID
            // It assumes that arg(0) = 'node' and arg(1) = node number

	if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
                  $nodeID = (int)arg(1);
	     $gid = array();
	     $gidNode = "n";
	     $x1 = 0;
	//
	// First let's see if this nodeID is a group itself
	//
	      $result = db_query("select og.nid from og WHERE og.nid = $nodeID");
	      while($t = db_fetch_object($result)) {
    		$gidNode = "y";
    		$gid[x1] = $t->nid;
		$x1++;
	      } // end while
// If $gidNode equals "y", then this is a group home page and the gid is $gid[0]
             } // end if


Also, you may have an issue with keeping the group context, in which case you should look at og_tracker: http://drupal.org/node/66145