Is it possible to add a role to the whole group after 1 member buys access to a specific role?

My scenario is: An organization buys 1 quiz (access is granted per role), adds this role to other members of the group via the "Configure member roles" and makes the quiz therefore available to these members.

How could that be done?

Comments

somebodysysop’s picture

Status: Active » Closed (won't fix)

You'd have to write your own code to do this. The function to add a role to a user in a group is:

/**
 * Add role to og_users_roles table.
 *
 * @param $uid the user ID
 * @param $rid the role ID
 * @param $gid node ID of the group for the user in this role
 *
 * There is no return parameter, but "hook_og()" is invoked with args:
 * 'rid' (role ID) and 'ogr_id' (og_users_roles table ID for the newly created record).
 */
function og_user_roles_role_join($uid, $rid, $gid) {
go7’s picture

Thanks a lot SomebodySysop. Do I just add this code to the module, or where should I put that?

somebodysysop’s picture

I'm sorry, this is not the entire code. It's the header information for the function which actually adds a ogur role to a user. If you know how to code, you will need to do this:

1. Identify the users in the group for which you wish to add the role. This will be a list of user ids ($uid) who belong to a particular group id ($gid).
2. Identify the role id ($rid) that you wish to add to the group.
3. Create a function which will add the group role to each user in the group. Something like:

// Let's assume that $user_array() is an array of the ids of the users in the group
// This code will add the role $rid to each user $uid in the group $gid
foreach ($user_array as $uid) {
  og_user_roles_role_join($uid, $rid, $gid);
}

You'll need to code this up in a separate custom module designed for this purpose.

go7’s picture

Unfortunately I'm not a programmer, so I'm a bit at a loss here.

The only role that would buy the "quiz role", is the "organization role". After the purchase, the "quiz role" should be visible in the "Configure member roles" section, where the organization will be able to add the quiz role to any member they want. If this is the case, would I need to add point 3 to the code? Or is point 3 needed so every member will have the check box for this role?

How would I be able to identify the specific user, that just bought the quiz access?

Thanks for the help.

somebodysysop’s picture

I'm sorry. It sounds like I may not fully understand your question.

It sounds like this is the scenario you are describing:

User A is an administrator for Group A. He has the OGUR group role "organization" in Group A. This role allows him to "Configure member roles" in OGUR.

The "quiz" role, by default, is NOT visible to User A when he is in the "Configure member roles" screen.

What you want to happen is for User A to purchase the "quiz" role, so that it will be available in the "Configure member roles" screen and he will be able to assign it to all users in Group A.

Is this correct?

somebodysysop’s picture

Status: Closed (won't fix) » Postponed (maintainer needs more info)
go7’s picture

That is exactly what I would like to accomplish.

somebodysysop’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

This isn't possible in OGUR today because it is not possible to restrict roles by group. Using the "Configure restricted member roles" feature, you can restrict what roles a particular role can assign, but this would apply to any user in any group, so long as he has this group role.

What you want to do is say that User A with the "organization" role in Group A now can add the "quiz" role to users in Group A.

However, User B with the "organization" role in Group B will also now be able to add the "quiz" role to users in Group B.

What we need to be able to do is to restrict assignment of the "quiz" role to Group A. There is currently no way to do this in OGUR except in the case where Group A and Group B belong to different group content types. Or, if you have a different "organization" role for each Group. But then, this becomes messy and difficult to maintain.

We would need another rule to allow/disallow a particular role from being used in a group. There is no logic for this right now.

go7’s picture

Thanks for all the help.

I think I found a different and easier way to restrict the access to the quizzes, and still allow the organization to grant specific users access to it. I will use a password protection. This way I can make the quiz role available, but only users that have the quiz role and the password can access the quizzes. It's one more step for the organization, but this way I can sell multiple quizzes and the organization doesn't have automatically access to all of them.