You are here

function og_get_hierarchy in Subgroups for Organic groups 7

Get hierarchy tree.

Parameters

$entity_type:

$etid:

$options:

File

./og_subgroups.module, line 178
Enable defining hierarchy of groups for organic groups.

Code

function og_get_hierarchy($entity_type, $etid, $options = array(), &$tree = array(), $depth = 0) {
  $options += array(
    'direction' => 'up',
    'type' => 'single',
    'sanitize' => TRUE,
  );
  $wrapper = entity_metadata_wrapper($entity_type, $etid);
  if ($depth == 0 && ($group = $wrapper->group
    ->value())) {
    if ($options['type'] == 'single') {
      $tree[$group->gid] = og_label($group->gid, $options['sanitize']);
    }
    else {
      $tree[$depth][$group->gid] = og_label($group->gid, $options['sanitize']);
    }
  }
  if ($options['direction'] == 'up' && $options['type'] == 'single') {
    $group = FALSE;

    // Get the first group associated with the entity.
    if ($wrapper->og_membership
      ->get(0)
      ->value()) {
      $group = $wrapper->og_membership
        ->get(0)->group
        ->value();
      $tree[$group->gid] = og_label($group->gid, $options['sanitize']);
      og_get_hierarchy($group->entity_type, $group->etid, $options, $tree, $depth + 1);
    }
  }
  return $tree;
}