You are here

function og_subgroups_propogate_user in Subgroups for Organic groups 5

Same name and namespace in other branches
  1. 5.4 og_subgroups.module \og_subgroups_propogate_user()

Propagates members and admins along the subgroups tree.

Parameters

$gid: The group id.

$uid: The propagated user id.

$args: Array with the updated action, as returned from hook_og()

1 call to og_subgroups_propogate_user()
og_subgroups_og in ./og_subgroups.module
Implementation of hook_og().

File

./og_subgroups.module, line 595
Maintains subgroups hierarchy created by the orgainc groups module.

Code

function og_subgroups_propogate_user($gid, $uid, $args) {
  $demote = variable_get('og_subgroups_propagate_demote', array());

  // User's membership was approved.
  // User was promoted to group admin.
  // User was demoted from admin and demote action should occur.
  if ($args['is_active'] == 1 || $args['is_admin'] == 1 || $args['is_admin'] == 0 && $demote['remove_admin']) {
    $tree = _og_subgroups_propogate_user_get_tree($gid);
    $user = user_load(array(
      'uid' => $uid,
    ));
    $args['is_admin'] ? $is_admin = 1 : ($is_admin = 0);
    foreach ($tree as $gid => $foo) {

      // Check user isn't already subscribed with same rights.
      if (empty($user->og_groups[$gid]) || $user->og_groups[$gid]['is_active'] != 1 || $user->og_groups[$gid]['is_admin'] != $is_admin) {

        // Pass in the $args info about propogation done by og_subgroups module.
        og_save_subscription($gid, $uid, array(
          'is_active' => 1,
          'is_admin' => $is_admin,
          'og_subgroups' => TRUE,
        ));
      }
    }
  }
}