You are here

function og_subgroups_get_all_family in Subgroups for Organic groups 5.4

Same name and namespace in other branches
  1. 5 og_subgroups.module \og_subgroups_get_all_family()

Given a node, this function returns an array of 'group node' objects representing the path in the subroups tree.

Parameters

$node: A group node object for which to compute the path.

Return value

An array of group node objects representing the path nodes root to parent of the given node. Returns an empty array if the node does not exist or is not part of a subgroup.

4 calls to og_subgroups_get_all_family()
og_subgroups_menu_tree in ./og_subgroups.module
Returns an HTML nested list (wrapped in a menu-class div) representing the group nodes as a tree.
og_subgroups_propogate_content in ./og_subgroups.module
Propagates content along the subgroups tree.
og_subgroups_tree in ./og_subgroups.module
Returns an array of titles and groups nids in tree hiearachy order.
_og_subgroups_propogate_user_get_tree in ./og_subgroups.module
Helper function for og_subgroups_propogate_user().

File

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

Code

function og_subgroups_get_all_family($gid, $direction, $nodes = array()) {

  // Get the syblings by getting the group parent and then its children.
  if ($direction == 'side') {
    $family = og_subgroups_get_family($gid, 'up');
    $family = og_subgroups_get_family($family[0]->gid, 'down');
  }
  else {
    $family = og_subgroups_get_family($gid, $direction);
  }
  if ($family[0]->gid) {
    if ($direction == 'up') {
      $nodes = og_subgroups_get_all_family($family[0]->gid, $direction, $nodes);
      $nodes[] = $family[0];
    }
    else {
      foreach ($family as $group) {

        // We get the result for syblings, no need to recurse.
        $nodes[] = $group;
        if ($direction == 'down') {
          $nodes = og_subgroups_get_all_family($group->gid, $direction, $nodes);
        }
      }
    }
  }
  return $nodes;
}