Hi, I have searched the issues but couldn't find what i want to achieve. Here it is:

In a block, I want to show an admin if there is a membership request for any of his groups. Example:

Hi Sinan, you have some membership requests for some of your groups. Please follow this link to manage requests.

Or.

You have some membership requests in your group: Group1. Please follow this link to manage requests.
You have some membership requests in your group: Group2. Please follow this link to manage requests.

Is it possible to do something like this by using views??

Thanks,

Sinan

CommentFileSizeAuthor
#17 jason_og_hack.txt1.29 KBtwopointoh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sinan Erdem’s picture

Hey there,

After some hours of trying and examining default og views, I managed to make something as I want. Here it is if anyone needs:

1. Added a view type node...

2. Added a Block view.

3. Fields:
User: name (who wants to be a member)
Organic groups: User's groups (in which gorup)
Organic groups: OG: Approve/Deny/Remove membership link (to approve or deny)

4. Filters:
Organic groups: OG: Is member an admin in a group (I selected "is one of : administrators")
Organic groups: OG: Is membership approved No

The other views settings are up to you. I used Style: HTML list. Then from field's settings I made all of the fields inline. And I added some text from field's option: Rewrite the output of this field.

The result was like that:

The user [user name here] wants to be a member of the [group name here] group. Would you like to Approve or Deny ?

Hope it helps someone... Cheers...

Sinan

Sinan Erdem’s picture

Status: Active » Closed (fixed)
friolator’s picture

Version: 6.x-2.0-rc3 » 6.x-2.0
Status: Closed (fixed) » Active

Not sure if anyone is reading this one anymore, but just in case - I'm unable to get this to work with the recipe above. "User Name" in Views doesn't seem to pull the user name of the person who is making the request, it's only showing the Current User (in this case, me). Has anyone been able to get this to work, and if so, can you be more specific about your recipe?

Sinan Erdem’s picture

Uhm... After some time, I realized that, this view doesnt operate as I expect. After some more effort, I couldn't manage to achieve the desired result. I think I have to do it in a custom block, or with a custom PHP field in the view (using Views Custom Field module http://drupal.org/project/views_customfield). The default view fields coming with OG is a little bit confusing for me.

friolator’s picture

Category: support » feature

I agree - it seems like this would be a really useful field to expose to views. the interesting thing in what I've found is that I can generate an accurate list of approval/deny links but I can't get the names or user pictures associated with those requests. So it's 90% there already, we just need a field for user name!

That is, views can make me a list that has approval links to:

http://my.domain.com/og/approve/859/3/[snip]
http://my.domain.com/og/approve/859/6/[snip]
http://my.domain.com/og/approve/859/7/[snip]

Where 859 is the group nid, and 3, 6 and 7 are all users who have made requests. Unfortunately, there's no apparent way to associate user names with these approve/deny links, so the result looks like "Request: approve or deny." for each line. that's not very helpful when you have no way of knowing who is making the request

I'm changing this issue to a feature request. I think it's an important one that would allow one to build a variety of different group-related lists in Views.

Our current two use cases are:

1) A View for managing the pending requests in a group. Views takes the group nid as an argument and returns a list of approve/deny links along with the user name, picture and maybe even the text of their request message.

2) A View for managing all of the users in a group - pending requests as well as existing members. For pendings, it would be like #1, but for existing members there would be links to remove them from the group, or promote/demote them from admin positions.

I'm sure there are more. But we want to do this in Views, because we use Panels for most of the page layout, and we would need these things to be tweakable in Views.

friolator’s picture

Status: Active » Fixed

Ok, so I'm changing this to fixed as I figured out how to do this. Here's the recipe:

1) Create a new View, of type User
2) Add fields for:
-OG: Approve/Deny/Remove Membership Link
-User Name
3) Add an Argument for:
-Organic groups: Group node
4) Add a Filter for:
-Organic groups: OG: Is membership approved (set to "No")

The result is a view that you can pass a group Node ID to, and get back a list of unapproved members, along with the appropriate approve/deny link. The key here is making the View's base table Users, not Node. Obviously, you could tweak the filters to have it show all members, or just non-admins, or whatever.

Sinan Erdem’s picture

OK, I didnt try it yet, but it seems to work only in a group node. But what I need is a block view that will work on every page. Think you are entering the site's homepage or your profile page, and it states that you have some requests for your groups. You shouldnt go to each groups page to check if there is a request. Making sense?

Sinan Erdem’s picture

Status: Fixed » Active

OK, I didnt try it yet, but it seems to work only in a group node. But what I need is a block view that will work on every page. Think you are entering the site's homepage or your profile page, and it states that you have some requests for your groups. You shouldnt go to each groups page to check if there is a request. Making sense?

friolator’s picture

actually, in my case, I'm approaching this a little differently but i think this view will still work for you, if i'm understanding correctly.

I'm building a management section so that a user can go to: groups/my and see all of his groups. In the ones where he's an admin, there are links to manage the group's users (pending or existing users, at groups/manage/nid), or just the group's pending requests (at groups/manage/nid/requests).

So, I've got an argument in the view outlined in #6 that corresponds to the group node. If you remove this argument from the view, it should show all of the groups for which there are pending requests. I haven't tested this, but I think it would work. you might need to apply a filter to the view to limit it to the current user's groups.

Sinan Erdem’s picture

The problem for me is, for example, when adding a filter to limit a user, will it apply to the user who made the request or the logged in user...

If I add a filter to limit the user to current user, it will not show the other users who made a request...

Confused...

friolator’s picture

I would say try this out without the argument for group node. I'm basically doing the same thing you're doing, only I'm narrowing it down by node. I think if you were to modify this to pass it the UID of the logged in user, you could show only the groups owned by that user. I'd have to play with it to see what the options are, but I'm pretty positive what you're doing isn't that far off from what I'm doing.

Sinan Erdem’s picture

I can show all the pending requests, and the requesters' names. But I can't restrict it with any argument. The user ID from logged in user can be passed to the argument but I don't know how to check if the logged in user is the admin of a group that has a request.

friolator’s picture

I don't have time to test this out today, but I'm pretty sure you can do this with the appropriate combination of relationships and filters.

Sinan Erdem’s picture

I am almost certain that with the current filters or relationships provided by OG, it is not possible to filter the fields related with the group admin. In my opinion there should be a filter provided by OG:

Is currently logged in user group admin?

And this functionality, I believe, is needed for many module users. I mean who doesn't want to show pending requests to the groups admins?

magpie5212’s picture

Did you find a recipe which reduced the list of groups to the ones where the request was pending?

Sinan Erdem’s picture

I am trying to reduce the results where the user is admin to no avail...

twopointoh’s picture

Issue tags: +block, +notifications, +og_notifications, +Organic Groups, +OG, +pending, +pending requests, +requests, +group join, +join group, +join, +hack
FileSize
1.29 KB

Hi everyone.

As others have said. I believe it is impossible with default views etc. However, I have managed to get it working by looking at the OG module code and then writing my own code in user-profile.tpl.php for example to display it on the user's notifications area.

If someone wants to wrap this up into a block or something...

Code is as follows (bit of a hack but it works and I really needed it to work as for some reason you do not get email notifications when someone requests to be a member of a group!):

	/* OG pending requests hack by Jason Mayes 2009*/

	global $user;

	//get all groups users is a member of
	$ogKeys = array_keys($user->og_groups);
	$ogPending = "<ul>";
	$pendFound = false;
	$x = 0;

	while($x < sizeof($user->og_groups))
	{
		// check if current user is admin of joined group
		if($user->og_groups[$ogKeys[$x]]['is_admin'])
		{
			$node->nid = $user->og_groups[$ogKeys[$x]]['nid'];
			// check for pending requests in that group
			$result = db_query(og_list_users_sql(0, 0, NULL), $node->nid);
			$cntpending = $cntall = 0;

			while ($row = db_fetch_object($result)) {
				$cntall++;
				if ($row->is_active == 0) {
					$cntpending++;
				}
			}
			if($cntpending  > 0)
			{
				$ogPending .= '<li><a href="/og/users/' . $user->og_groups[$ogKeys[$x]]['nid'] . '" title="Click to manage user join requests for this group!">' .$user->og_groups[$ogKeys[$x]]['title'] . '</a> (' . $cntpending . ' new)</li>';
				$pendFound = true;
			}
		}
		$x++;
	}

	$ogPending .= "</ul>";


	// now display the results:

	if($pendFound)
	{
		print('<h3>Pending group member requests</h3>
		<p>There are users who want to join groups you are an admin of. Please manage their join requests by clicking on the groups shown below</p>
		<p>' .  $ogPending .'</p>');
	}

Hope that helps people! Cheers.

metastate’s picture

Thanks for posting your code Jason. Even with an email alert, pending requests for moderated groups often get missed. This is a nice workaround.

bryancasler’s picture

#17's code worked great, thanks a million!

Caligan’s picture

Many many thanks! I modified this into a hook_block addition so it can be tossed up on one of my sites, and it's precisely what we've been needing. This would be an awesome addition to the actual module, IMHO.

AllanDummer’s picture

For og7.x-2.3 on D7.23 you can try this.

<?php
function YOURMODULE_og_pending_requests($group_type = 'node') {

  //Get all the groups the user belongs to
  $user_groups = og_get_groups_by_user();

  // Load the whole shebang as entities so we have everything
  $groups = entity_load($group_type,$user_groups[$group_type]);

  $og_pending = '';

  foreach($groups as $gid=>$group) {
    // Check if the user can approve subscriptions
    if (og_user_access($group_type, $gid, 'approve and deny subscription ')) {

      $query = db_query('SELECT etid
                            FROM {og_membership}
                            WHERE gid = :gid
                            AND state = 2',
          array(':gid' => $gid));

      $result = $query->fetchAllKeyed();

      if (!empty($result)) {
        $link = l($groups[$gid]->title. ' ('.count($result).')', 'group/node/'.$gid.'/admin/people');
        $og_pending = '<li>'. $link .'</li>';
      }
    }
  }

  if(!empty($og_pending)) {
    return '<ul>'. $og_pending .'</ul>';
  }
}
?>

Change the return format to your needs. Hope it helps someone. Cheers!

drummondf’s picture

Version: 6.x-2.0 » 7.x-2.3

This thread leads me to believe there used to be Approve, Deny, and Block links in the D6 version that could just be clicked and make those actions occur - if this is the case, where are these for D7, or how do we make them?? This seems to be an extremely important yet overlooked feature for OG

I have little dev skills but am happy to contribute in any way to make this happen - thank you!