function tripal_cv_obo_form

2.x tripal_cv.obo_loader.inc tripal_cv_obo_form($form, &$form_state)
1.x obo_loader.inc tripal_cv_obo_form(&$form_state = NULL)

Provides the form to load an already existing controlled Vocabulary into chado

Parameters

$form: The form array

$form_state: The form state array

Return value

The form array with new additions

Related topics

1 string reference to 'tripal_cv_obo_form'
tripal_cv_menu in tripal_cv/tripal_cv.module
Implements hook_menu(). Registers all menu items associated with this module

File

tripal_cv/includes/tripal_cv.obo_loader.inc, line 29
Functions to aid in loading ontologies into the chado cv module

Code

function tripal_cv_obo_form($form, &$form_state) {

  // get a list of db from chado for user to choose
  $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY name";
  $results = db_query($sql);

  $obos = array();
  $obos[] = 'Select a Vocabulary';
  foreach ($results as $obo) {
    $obos[$obo->obo_id] = $obo->name;
  }

  $obo_id = '';
  if (array_key_exists('values', $form_state)) {
    $obo_id = array_key_exists('obo_id', $form_state['values']) ? $form_state['values']['obo_id'] : '';
  }

  $form['instructions'] = array(
    '#type' => 'fieldset',
    '#title' => 'instructions',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['instructions']['info'] = array(
    '#type' => 'item',
    '#markup' => t('This page allows you to load vocabularies and ontologies
      that are in OBO format. Once loaded, the terms from these
      vocabularies can be used to categorize data in the database.
      You may use the form below to either reload a vocabulary that is already
      loaded (as when new updates to that vocabulary are available) or load a new
      vocabulary.'),
  );

  $form['obo_existing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Use a Saved Ontology OBO Reference'),
    '#prefix' => '<span id="obo-existing-fieldset">',
    '#suffix' => '</span>'
  );

  $form['obo_existing']['existing_instructions'] = array(
    '#type' => 'item',
    '#markup' => t('The vocabularies listed in the select box below have bene pre-populated
      upon installation of Tripal or have been previously loaded.  Select one to edit
      its settings or submit for loading.  You may reload any vocabulary that has
      already been loaded to retrieve any new updates.'),
  );

  $form['obo_existing']['obo_id'] = array(
    '#title' => t('Ontology OBO File Reference'),
    '#type' => 'select',
    '#options' => $obos,
    '#ajax' => array(
      'callback' => 'tripal_cv_obo_form_ajax_callback',
      'wrapper' => 'obo-existing-fieldset',
    ),
  );

  // If the user has selected an OBO ID then get the form elements for
  // updating.
  if ($obo_id) {
    $uobo_name = '';
    $uobo_url = '';
    $uobo_file = '';

    $vocab = db_select('tripal_cv_obo', 't')
      ->fields('t', array('name', 'path'))
      ->condition('obo_id', $obo_id)
      ->execute()
      ->fetchObject();
    $uobo_name = $vocab->name;
    if (preg_match('/^http/', $vocab->path)) {
      $uobo_url = $vocab->path;
    }
    else {
      $uobo_file = trim($vocab->path);
      $matches = array();
      if (preg_match('/\{(.*?)\}/', $uobo_file, $matches)) {
        $modpath = drupal_get_path('module', $matches[1]);
        $uobo_file = preg_replace('/\{.*?\}/', $modpath, $uobo_file);
      }
    }
    // We don't want the previous value to remain. We want the new default to
    // show up, so remove the input values
    unset($form_state['input']['uobo_name']);
    unset($form_state['input']['uobo_url']);
    unset($form_state['input']['uobo_file']);

    $form['obo_existing']['uobo_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Vocabulary Name'),
      '#description' => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
                           list above for use again later.'),
      '#default_value' => $uobo_name,
    );

    $form['obo_existing']['uobo_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Remote URL'),
      '#description' => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
                           (e.g. http://www.obofoundry.org/ro/ro.obo'),
      '#default_value' => $uobo_url,
    );

    $form['obo_existing']['uobo_file'] = array(
      '#type' => 'textfield',
      '#title' => t('Local File'),
      '#description' => t('Please enter the file system path for an OBO
        definition file. If entering a path relative to
        the Drupal installation you may use a relative path that excludes the
        Drupal installation directory (e.g. sites/default/files/xyz.obo). Note
        that Drupal relative paths have no preceeding slash.
        Otherwise, please provide the full path on the filesystem.  The path
        must be accessible to the web server on which this Drupal instance is running.'),
      '#default_value' => $uobo_file,
    );
    $form['obo_existing']['update_obo_details'] = array(
      '#type' => 'submit',
      '#value' => 'Update Ontology Details',
      '#name' => 'update_obo_details'
    );
    $form['obo_existing']['update_load_obo'] = array(
      '#type' => 'submit',
      '#value' => 'Load Vocabulary',
      '#name' => 'update_load_obo'
    );
  }

  $form['obo_new'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add a New Ontology OBO Reference'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['obo_new']['path_instructions'] = array(
    '#value' => t('Provide the name and path for the OBO file.  If the vocabulary OBO file
                   is stored local to the server provide a file name. If the vocabulry is stored remotely,
                   provide a URL.  Only provide a URL or a local file, not both.'),
  );

  $form['obo_new']['obo_name'] = array(
    '#type' => 'textfield',
    '#title' => t('New Vocabulary Name'),
    '#description' => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
                           list above for use again later.'),
  );

  $form['obo_new']['obo_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Remote URL'),
    '#description' => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
                           (e.g. http://www.obofoundry.org/ro/ro.obo'),
  );

  $form['obo_new']['obo_file'] = array(
    '#type' => 'textfield',
    '#title' => t('Local File'),
    '#description' => t('Please enter the file system path for an OBO
        definition file. If entering a path relative to
        the Drupal installation you may use a relative path that excludes the
        Drupal installation directory (e.g. sites/default/files/xyz.obo). Note
        that Drupal relative paths have no preceeding slash.
        Otherwise, please provide the full path on the filesystem.  The path
        must be accessible to the web server on which this Drupal instance is running.'),
  );

  $form['obo_new']['add_new_obo'] = array(
    '#type' => 'submit',
    '#value' => t('Add this vocabulary'),
    '#name' => 'add_new_obo',
  );

  $form['#redirect'] = 'admin/tripal/tripal_cv/obo_loader';

  return $form;
}