You are here

function theme_og_subgroups_menu_tree in Subgroups for Organic groups 6

Theme a group hierachy tree

Parameters

$group: Optionally supply a group to focus

Return value

An HTML-rendered tree of group links

1 theme call to theme_og_subgroups_menu_tree()
_og_subgroups_hierarchy_block in ./og_subgroups.module
Generate the group hierarchy block

File

includes/theme.inc, line 11

Code

function theme_og_subgroups_menu_tree($group) {
  og_subgroups_include('tree');

  // Fetch the group tree
  if (!($tree = og_subgroups_get_group_tree($group))) {

    // If no tree, then no menu
    return NULL;
  }

  // Fetch settings for the treeview and controls
  $treeview = variable_get('og_subgroups_block_use_treeview', 1);
  $controls = variable_get('og_subgroups_block_use_treeview_controls', 1);
  $ajax = variable_get('og_subgroups_block_use_treeview_ajax', 0);

  // Add treeview externals
  if ($treeview) {
    $path = drupal_get_path('module', 'og_subgroups');
    drupal_add_css($path . '/theme/og_subgroups.css');
    drupal_add_css($path . '/theme/jquery.treeview.css');
    drupal_add_js($path . '/scripts/jquery.treeview.min.js');

    // Determine which additional JS settings we need
    $js_settings = array();
    if ($controls) {
      $js_settings[] = "control: '#og-subgroups-tree-controls-{$group->nid}'";
    }
    if ($ajax) {
      $js_settings[] = "url: Drupal.settings.basePath + 'subgroups/tree/{$group->nid}'";
      drupal_add_js($path . '/scripts/jquery.treeview.async.js');
    }

    // Add the declaration for treeview
    drupal_add_js("\n      \$(document).ready(function() {\n        \$('ul.og-subgroups-menu-tree').treeview({ \n          collapsed: true,\n          animated: 'fast',\n          " . (!empty($js_settings) ? implode(",\n\t", $js_settings) : '') . "\n        });\n      });\n    ", 'inline');
  }

  // Wrap the entire block in a div
  $content .= "<div id=\"og-subgroups-tree-{$group->nid}\" class=\"og-subgroups-tree\">";

  // If we're using the treeview, and controls are desired, add them
  if ($treeview && $controls) {
    $content .= "<div id=\"og-subgroups-tree-controls-{$group->nid}\" class=\"og-subgroups-tree-controls\">";
    $content .= '<a title="' . t('Collapse the entire tree below') . '" href="#">' . t('Collapse') . '</a> | ';
    $content .= '<a title="' . t('Expand the entire tree below') . '" href="#">' . t('Expand') . '</a>';
    $content .= '</div>';
  }

  // Generate a list of the groups parents
  $parents = og_subgroups_get_group_parents($group);

  // Wrap the list
  $content .= "<ul id=\"og-subgroups-menu-tree-{$group->nid}\" class=\"og-subgroups-menu-tree\">";

  // If we're using treeview with AJAX, we do not need to generate the tree here
  if (!($treeview && $ajax)) {

    // Iterate the tree to begin generating nested links
    foreach ($tree as $branch) {

      // If the branch has no children, end here
      if (empty($branch->children)) {
        return NULL;
      }
      $content .= '<li class="open og-subgroups-tree-active-trail">';
      $content .= theme('og_subgroups_menu_tree_link', $group, $branch);

      // Recursively add the rest of the tree
      if (!empty($branch->children)) {
        $content .= '<ul>' . theme('og_subgroups_menu_tree_branch', $group, $branch->children, $parents) . '</ul>';
      }
      $content .= '</li>';
    }
  }
  $content .= '</ul>';
  $content .= '</div>';
  return $content;
}