You are here

function _og_subgroups_get_group_children_recursive in Subgroups for Organic groups 6

Recursive callback to help determine the children of a group

1 call to _og_subgroups_get_group_children_recursive()
og_subgroups_get_group_children in includes/tree.inc
Determine the children of a given group

File

includes/tree.inc, line 217
Functions to generate and use the group hierarchy trees

Code

function _og_subgroups_get_group_children_recursive($group, $branch, &$children, $nested, $add = FALSE) {

  // Iterate the branch
  foreach ($branch as $gid => $child) {

    // If we want to nest the children and the parent is already set
    // skip this
    if ($nested && isset($children[$child->parent])) {
      continue;
    }

    // If set to add, meaning this was called once we've reach the group
    // add the child
    if ($add) {
      $object = drupal_clone($child);

      // Children of the children are only kept if we're nesting
      if (!$nested) {
        unset($object->children);
      }
      $children[$gid] = $object;
    }

    // If we've reached the group, begin adding
    if ($group->nid == $gid) {
      _og_subgroups_get_group_children_recursive($group, $child->children, $children, $nested, TRUE);
    }
    else {
      if (!empty($child->children)) {
        _og_subgroups_get_group_children_recursive($group, $child->children, $children, $nested, $add);
      }
    }
  }
}