You are here

function og_subgroups_tree in Subgroups for Organic groups 5

Same name and namespace in other branches
  1. 5.4 og_subgroups.module \og_subgroups_tree()
  2. 5.3 og_subgroups.module \og_subgroups_tree()

Returns an array of titles and groups nids in tree hiearachy order.

Parameters

$groups: All the accessibale groups.

$exclude: The current group id that shouldn't appear in the subgroups.

$inaccessibale: All the inaccessibale groups.

$indent: The indention to be used.

2 calls to og_subgroups_tree()
og_subgroups_outline in ./og_subgroups.module
Implementation of function og_subgroups_outline() Handles all subgroups outline operations.
og_subgroups_set_hierarchy in ./og_subgroups.module
API function to set/ update groups hierarchy.

File

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

Code

function og_subgroups_tree($groups, $exclude, $inaccessibale, $indent = '') {
  $tree = array();
  $tree[0] = '<' . t('top-level') . '>';
  foreach ($groups as $key => $group) {

    // Start recurse only from top level groups.
    $parent = og_subgroups_get_all_family($key, 'up');

    // Get the top level parent of a group.
    if ($parent[0]->gid) {
      $gid = $parent[0]->gid;
      $title = $parent[0]->title;
    }
    else {
      $gid = $key;
      $title = $group;
    }

    // Set the top level group. Make sure the gid is part of the accessible groups.
    if (empty($tree[$gid]) && $gid != $exclude) {
      !in_array($gid, $inaccessibale) ? $tree[$gid] = $title : ($tree[$gid] = t('<private group>'));
      $tree = og_subgroups_tree_recurse($gid, $exclude, $inaccessibale, $tree, $indent . '--');
    }
  }
  return $tree;
}