function tripal_vocabulary_lookup_vocab_page

3.x tripal.term_lookup.inc tripal_vocabulary_lookup_vocab_page($vocabulary)

Provides the content for a single controlled vocabulary.

1 string reference to 'tripal_vocabulary_lookup_vocab_page'
tripal_menu in tripal/tripal.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal/includes/tripal.term_lookup.inc, line 53

Code

function tripal_vocabulary_lookup_vocab_page($vocabulary) {

  // set the breadcrumb
  $breadcrumb = array();
  $breadcrumb[] = l('Home', '<front>');
  $breadcrumb[] = l('Controlled Vocabularies', 'cv/lookup');
  drupal_set_breadcrumb($breadcrumb);

  $vocab = tripal_get_vocabulary_details($vocabulary);
  if ($vocab['description']) {
    drupal_set_title($vocabulary . ': ' . $vocab['description']);
  }
  else {
    drupal_set_title($vocabulary);
  }

  // If we can't find the term then just return a message.
  if (!$vocab) {
    drupal_set_message('The vocabulary cannot be found on this site', 'error');
    return '';
  }

  $headers = array();
  $rows = array();
  $vocab_name = $vocab['name'];
  $short_name = $vocab['short_name'];
  if ($vocab['url']) {
    $short_name = l($vocab['short_name'], $vocab['url'], array('attributes' => array('target' => '_blank')));
  }
  $vocab_desc = $vocab['description'];
  $rows[] = array(
    array(
      'data' => 'Short Name',
      'header' => TRUE,
      'width' => '20%',
    ),
    $short_name,
  );
  $rows[] = array(
    array(
      'data' => 'Vocabulary Name(s)',
      'header' => TRUE,
      'width' => '20%',
    ),
    $vocab_name,
  );
  $rows[] = array(
    array(
      'data' => 'Description',
      'header' => TRUE,
      'width' => '20%',
    ),
    $vocab_desc,
  );
  $rows[] = array(
    array(
      'data' => 'Number of Terms Loaded on This Site',
      'header' => TRUE,
      'width' => '20%',
    ),
    number_format($vocab['num_terms']),
  );

  $table = array(
    'header' => $headers,
    'rows' => $rows,
    'attributes' => array(),
    'sticky' => FALSE,
    'caption' => '',
    'colgroups' => array(),
    'empty' => '',
  );

  $has_root = TRUE;
  $root_terms = tripal_get_vocabulary_root_terms($vocabulary);
  // If this vocabulary doesn't have root terms then it's either not an
  // ontology or not all of the terms are loaded. In this case, let's get
  // a paged list of all terms
  if (count($root_terms) == 0) {
    $root_terms = tripal_get_vocabulary_terms($vocabulary, 25);
    $has_root = FALSE;
  }
  $items = tripal_vocabulary_lookup_term_children_format($root_terms);

  if (count($root_terms) == 0) {
    $items = '<p>This vocabulary has no terms loaded</p>';
  }
  else {
    $items = '<p>Click the + icon (if present) to expand the tree. If ' .
      'the full ontology or the term heirarchy is not loaded into this site, ' .
      'then the tree will consist of all terms at the same level. ' .
      'For some vocabularies, only a subset of terms are loaded</p>' . $items;
  }

  drupal_add_js(array(
    'tripal' => array(
      'cv_lookup' => array(
        'vocabulary' => $vocabulary,
      ),
    ),
  ), 'setting');

  $content = array(
    'vocab_table' => array(
      '#type' => 'item',
      '#title' => 'Details',
      '#markup' => '<p>A vocabulary is always identified by its short name and sometimes it may offer multiple sub-vocabularies with different names. Both are listed below.</p>' . theme_table($table),
    ),
    'vocab_browser' => array(
      '#type' => 'item',
      '#title' => 'Term Browser',
      '#markup' => $items,
    ),
  );
  if (!$has_root) {
    $content['pager'] = array(
      '#type' => 'markup',
      '#markup' => theme('pager'),
    );
  }

  // Add support for our custom tree viewer
  drupal_add_css(drupal_get_path('module', 'tripal') . '/theme/css/tripal.cv_lookup.css');
  drupal_add_js(drupal_get_path('module', 'tripal') . '/theme/js/tripal.cv_lookup.js', 'file');

  return $content;
}