Tripal v1.0 (6.x-1.0)
DB Module

Functions

 tripal_db_admin_page ()
 tripal_db_select_form ()
 tripal_ajax_db_edit ()
 tripal_db_form (&$form_state=NULL, $action= 'Update')
 tripal_db_form_validate ($form, &$form_state)
 tripal_db_form_submit ($form, &$form_state)
 tripal_db_init ()
 tripal_db_menu ()
 tripal_db_perm ()
 tripal_db_views_api ()
 tripal_db_theme ()
 tripal_cv_theme ()

Function Documentation

tripal_ajax_db_edit ( )

Definition at line 26 of file tripal_db.admin.inc.

                               {
  $status = TRUE;

  // prepare and render the form
  $form = tripal_core_ahah_prepare_form();   
  $data = drupal_render($form);  

  // bind javascript events to the new objects that will be returned 
  // so that AHAH enabled elements will work.
  $settings = tripal_core_ahah_bind_events();

  // return the updated JSON
  drupal_json(
    array(
      'status'   => $status, 
      'data'     => $data,
      'settings' => $settings,
    )  
  );
}
tripal_cv_theme ( )

We need to let drupal know about our theme functions and their arguments. We create theme functions to allow users of the module to customize the look and feel of the output generated in this module

Definition at line 247 of file tripal_cv.module.

                           {
  return array(    
    'tripal_cv_admin' => array(
      'template' => 'tripal_cv_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_cv') . '/theme', 
    ),
  );
}
tripal_db_admin_page ( )

Definition at line 7 of file tripal_db.admin.inc.

                                {
  $add_url = url("admin/tripal/tripal_db/add_db");
  $output = "<a href=\"$add_url\">Add a new external database</a>";
  $output .= drupal_get_form('tripal_db_select_form');
  $output .= '<div id="db-edit-div">Please select a database above to view or edit</div>';
  return $output;
}
tripal_db_form ( &$  form_state = NULL,
action = 'Update' 
)

Definition at line 51 of file tripal_db.admin.inc.

                                                                 {
  
  $dbid = $form_state['values']['dbid'];
  
  
  if (strcmp($action,'Update')==0) {
    // get a list of db from chado for user to choose
    $sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
    $results = chado_query($sql);
  
    $dbs = array();
    $dbs[] = '';
    while ($db = db_fetch_object($results)) {
      $dbs[$db->db_id] = $db->name;
    }
  
    $form['dbid'] = array(
      '#title' => t('External Database Name'),
      '#type' => 'select',
      '#options' => $dbs,
      '#ahah' => array(
        'path' => 'admin/tripal/tripal_db/edit/js',
        'wrapper' => 'db-edit-div',
        'effect' => 'fade',
        'event' => 'change',
        'method' => 'replace',
      ),
      '#prefix' => '<div id="db-edit-div">',
      '#suffix' => '</div>',
      '#default_value' => $dbid,
      '#description' => t('Please select a database to edit'),
    );
  }   
  else {
    $default_db = $form_state['values']['name'];
    $default_desc = $form_state['values']['description'];
    $default_url = $form_state['values']['url'];
    $default_urlprefix = $form_state['values']['urlprefix']; 
  }
  
  // get this requested database
  if ($dbid) {
    $values = array('db_id' => $dbid);
    $result = tripal_core_chado_select('db', array('*'), $values);
    $db = $result[0];
    $prev_dbid = $form_state['values']['prev_dbid'];
    // if the database has changed then repopulate the fields with the databaes values
    if ($prev_dbid != $dbid) {
      $default_db        = $db->name;
      $default_desc      = $db->description;
      $default_url       = $db->url;
      $default_urlprefix = $db->urlprefix;
    }
    // if the database did not change then keep the values in the form values
    else {
      $default_db = $form_state['values']['name'];
      $default_desc = $form_state['values']['description'];
      $default_url = $form_state['values']['url'];
      $default_urlprefix = $form_state['values']['urlprefix'];      
    }
  }
  
  $form['form_action'] = array(
    '#type' => 'hidden',
    '#value' => $action, 
  );  

  // we need to distinguish between edits in a field that may have failed
  // and when the user selects a different database from the list.  
  $form['prev_dbid'] = array(
    '#type' => 'hidden',
    '#value' => $dbid, 
  );  
  
  // if we want to update a database but the user has not
  // yet selected a database then return so we don't show the other fields
  // the rest of the fields will be added with the AHAH callback. 
  if (strcmp($action,'Update')==0 and !$dbid) {
    return $form;
  }

  $form['name']= array(
    '#type'          => 'textfield',
    '#title'         => t("Database Name"),
    '#description'   => t('Please enter the name for this external database.'),
    '#required'      => TRUE,
    '#default_value' => $default_db,
    '#weight'        => 1
  );

  $form['description']= array(
    '#type'          => 'textarea',
    '#title'         => t('Description'),
    '#description'   => t('Please enter a description for this database'),
    '#default_value' => $default_desc,
    '#weight'        => 2
  );
  $form['url']= array(
    '#type'          => 'textfield',
    '#title'         => t('URL'),
    '#description'   => t('Please enter the web address for this database.'),
    '#default_value' => $default_url,
    '#weight'        => 3
  );
  $form['urlprefix']= array(
    '#type'          => 'textfield',
    '#title'         => t('URL prefix'),
    '#description'   => t('Tripal can provide links to external databases when accession numbers or unique identifiers are known.  Typically, a database will provide a unique web address for each accession and the accession usually is the last component of the page address.  Please enter the web address, minus the accession number for this database.  When an accession number is present, Tripal will combine this web address with the accession and provide a link to the external site.'),
    '#default_value' => $default_urlprefix,
    '#weight'        => 4
  );


  if (strcmp($action, 'Update')==0) {
    $form['update'] = array(
      '#type'         => 'submit',
      '#value'        => t('Update'),
      '#weight'       => 5,
      '#executes_submit_callback' => TRUE,
    );
    $form['delete'] = array(
      '#type'         => 'submit',
      '#value'        => t('Delete'),
      '#weight'       => 6,
      '#executes_submit_callback' => TRUE,
    );
  }
  else {
    $form['add'] = array(
      '#type'         => 'submit',
      '#value'        => t('Add'),
      '#weight'       => 5,
      '#executes_submit_callback' => TRUE,
    );
  }

  return $form;
}
tripal_db_form_submit ( form,
&$  form_state 
)

Definition at line 213 of file tripal_db.admin.inc.

                                                    {

  $name =  trim($form_state['values']['name']);
  $desc =  trim($form_state['values']['description']);
  $url  =  trim($form_state['values']['url']);
  $urlp =  trim($form_state['values']['urlprefix']);
  $dbid =  trim($form_state['values']['dbid']);
  $op   =  trim($form_state['values']['op']);

  $values = array(
    'name' => $name,
    'description' => $desc,
    'url' => $url,
    'urlprefix' => $urlp,
  );
  if ($dbid) {
    if (strcmp($op, 'Update')==0) {      
      $match = array('db_id' => $dbid);
      $success = tripal_core_chado_update('db', $match, $values);
      if ($success) {
        drupal_set_message(t("External database updated"));
      }
      else {
        drupal_set_message(t("Failed to update external database."));
      }
    }
    if (strcmp($op, 'Delete')==0) {
      $match = array('db_id' => $dbid);
      $success = tripal_core_chado_delete('db', $match);
      if ($success) {
        drupal_set_message(t("External database deleted"));
      }
      else {
        drupal_set_message(t("Failed to delete external database."));
      }
    }
  }
  else {
    $success = tripal_core_chado_insert('db', $values);
    if ($success) {
      drupal_set_message(t("External database added"));
    }
    else {
      drupal_set_message(t("Failed to add external database."));
    }
  }
}
tripal_db_form_validate ( form,
&$  form_state 
)

Definition at line 193 of file tripal_db.admin.inc.

                                                      {
  $name =  trim($form_state['values']['name']);
  $desc =  trim($form_state['values']['description']);
  $url  =  trim($form_state['values']['url']);
  $urlp =  trim($form_state['values']['urlprefix']);
  $dbid =  trim($form_state['values']['dbid']);
  $op   =  trim($form_state['values']['op']);
  $action =  $form_state['values']['form_action'];
 
  // make sure the database name is unique
  $values = array('name' => $name);
  $results = tripal_core_chado_select('db', array('db_id'), $values);   
  if (count($results) > 0 and $results[0]->db_id != $dbid) {
    form_set_error('name', 'The database name must be unique');
  }
}
tripal_db_init ( )

Definition at line 15 of file tripal_db.module.

                          {

  // add the tripal_db JS and CSS
  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_db.css');
  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_db.js');
}
tripal_db_menu ( )

Definition at line 25 of file tripal_db.module.

                          {
  $items = array();

  $items['admin/tripal/tripal_db'] = array(
    'title' => 'Databases',
    'description' => 'Basic Description of Tripal DB Module Functionality',
    'page callback' => 'theme',
    'page arguments' => array('tripal_db_admin'),
    'access callback' => 'user_access',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/tripal_db/edit_db'] = array(
    'title' => 'Edit a Database',
    'description' => 'Manage Databases ',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_db_form', 'Update'),
    'access callback' => 'user_access',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/tripal_db/add_db'] = array(
    'title' => 'Add a Database',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_db_form', 'Add'),
    'access callback' => 'user_access',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/tripal/tripal_db/edit/js'] = array(
    'page callback' => 'tripal_ajax_db_edit',
    'access callback' => 'user_access',
    'access arguments' => array('access administration pages'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}
tripal_db_perm ( )

Set the permission types that the chado module uses. Essentially we want permissionis that protect creation, editing and deleting of chado data objects

Definition at line 73 of file tripal_db.module.

                          {
  return array(
    'administer db cross-references',
  );
}
tripal_db_select_form ( )

Definition at line 19 of file tripal_db.admin.inc.

                                 {
  return $form;
}
tripal_db_theme ( )

We need to let drupal know about our theme functions and their arguments. We create theme functions to allow users of the module to customize the look and feel of the output generated in this module

Definition at line 112 of file tripal_db.module.

                           {
  return array(    
    'tripal_db_admin' => array(
      'template' => 'tripal_db_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_db') . '/theme', 
    ),
  );
}
tripal_db_views_api ( )

Implements hook_views_api() Purpose: Essentially this hook tells drupal that there is views support for for this module which then includes tripal_db.views.inc where all the views integration code is

Definition at line 87 of file tripal_db.module.

                               {
  return array('api' => 2.0);
}
 All Classes Files Functions Variables