Tripal v1.0 (6.x-1.0)
Library

Functions

 tripal_library_admin ()
 get_tripal_library_admin_form_cleanup_set (&$form)
 get_tripal_library_admin_form_taxonomy_set (&$form)
 get_tripal_library_admin_form_reindex_set (&$form)
 get_tripal_library_admin_form_sync_set (&$form)
 tripal_library_admin_validate ($form, &$form_state)
 tripal_library_add_taxonomy ($node, $library_id)
 tripal_library_sync_libraries ($library_id=NULL, $job_id=NULL)
 tripal_library_feature_set_taxonomy ($library_id=NULL)
 tripal_library_reindex_features ($library_id=NULL, $job_id=NULL)
 tripal_library_taxonify_features ($library_id=NULL, $job_id=NULL)
 tripal_library_cleanup ($dummy=NULL, $job_id=NULL)
 tripal_library_help ($path, $arg)
 tripal_library_node_info ()
 tripal_library_perm ()
 chado_library_access ($op, $node, $account)
 tripal_library_menu ()
 tripal_library_views_api ()
 tripal_library_nodeapi (&$node, $op, $teaser, $page)
 tripal_library_theme ()
 theme_tripal_library_search_index ($node)
 theme_tripal_library_node_libraries ($node)
 tripal_library_cron ()
 tripal_library_library_access ($op, $node, $account)
 chado_library_form ($node)
 chado_library_validate ($node)
 chado_library_insert ($node)
 chado_library_update ($node)
 chado_library_load ($node)
 chado_library_view ($node, $teaser=FALSE, $page=FALSE)
 chado_library_delete (&$node)
 tripal_library_block ($op= 'list', $delta= '0', $edit=array())

Detailed Description

Provides functions for managing chado libraries including creating details pages for each library


Function Documentation

chado_library_access ( op,
node,
account 
)

Set the permission types that the module uses.

Definition at line 77 of file tripal_library.module.

                                                    {
  if ($op == 'create') {
    if (!user_access('create chado_library content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'update') {
    if (!user_access('edit chado_library content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'delete') {
    if (!user_access('delete chado_library content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'view') {
    if (!user_access('access chado_library content', $account)) {
      return FALSE;
    }
  }
  return NULL;
}
chado_library_delete ( &$  node)

Delete data from drupal and chado databases when a node is deleted

Definition at line 661 of file tripal_library.module.

                                      {

  $library_id = chado_get_id_for_node('library', $node);
  
  // if we don't have a library id for this node then this isn't a node of
  // type chado_library or the entry in the chado_library table was lost.
  if (!$library_id) {
    return;
  }
  
  // Remove data from {chado_library}, {node} and {node_revisions} tables of
  // drupal database
  $sql_del = "DELETE FROM {chado_library} ".
            "WHERE nid = %d ".
            "AND vid = %d";
  db_query($sql_del, $node->nid, $node->vid);
  $sql_del = "DELETE FROM {node_revisions} ".
            "WHERE nid = %d ".
            "AND vid = %d";
  db_query($sql_del, $node->nid, $node->vid);
  $sql_del = "DELETE FROM {node} ".
            "WHERE nid = %d ".
            "AND vid = %d";
  db_query($sql_del, $node->nid, $node->vid);  

  // Remove data from library and libraryprop tables of chado database as well
  chado_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
  chado_query("DELETE FROM {library} WHERE library_id = %d", $library_id);  
}
chado_library_form ( node)

When editing or creating a new node of type 'chado_library' we need a form. This function creates the form that will be used for this.

Definition at line 405 of file tripal_library.module.

                                   {
  $form = array();

  $library = $node->library;

  // get the default values
  $uniquename = $node->uniquename;
  if (!$uniquename) {
    $uniquename = $library->uniquename;
  }
  $library_type = $node->library_type;
  if (!$library_type) {
    $library_type = $library->type_id->cvterm_id;
  }
  $organism_id = $node->organism_id;
  if (!$organism_id) {
    $organism_id = $library->organism_id->organism_id;
  }
  $library_description = $node->library_description;
  if (!$library_description) {
    $libprop = tripal_library_get_property($library->library_id, 'library_description');
    $library_description = $libprop->value;
  }

  // keep track of the library id if we have.  If we do have one then
  // this is an update as opposed to an insert.
  $form['library_id'] = array(
    '#type' => 'value',
    '#value' => $library->library_id,
  );

  $form['title']= array(
    '#type'          => 'textfield',
    '#title'         => t('Library Title'),
    '#description'   => t('Please enter the title for this library. '.
                          'This appears at the top of the library page.'),
    '#required'      => TRUE,
    '#default_value' => $node->title,
    '#weight'        => 1
  );

  $form['uniquename']= array(
    '#type'          => 'textfield',
    '#title'         => t('Unique Library Name'),
    '#description'   => t('Please enter a unique name for this library'),
    '#required'      => TRUE,
    '#default_value' => $uniquename,
    '#weight'        => 2
  );
    
  // get the list of library types
  $values = array(
    'cv_id' => array(
      'name' => 'tripal_library_types',
    )
  );
  $columns = array('cvterm_id','name');
  $options = array('order_by' => array('name' => 'ASC'));
  $lib_types = tripal_core_chado_select('cvterm', $columns, $values, $options);
  $types = array();
  $types[''] = '';
  foreach($lib_types as $type) {
    $types[$type->cvterm_id] = $type->name;
  }

  $form['library_type'] = array(
    '#title'       => t('Library Type'),
    '#type'        => t('select'),
    '#description' => t("Choose the library type."),
    '#required'    => TRUE,
    '#default_value' => $library_type,
    '#options'     => $types,
    '#weight'      => 3
  );

  // get the list of organisms
  $sql = "SELECT * FROM {Organism}";
  $org_rset = chado_query($sql);

  $organisms = array();
  $organisms[''] = '';
  while ($organism = db_fetch_object($org_rset)) {
    $organisms[$organism->organism_id] =
    "$organism->genus $organism->species ($organism->common_name)";
  }

  $form['organism_id'] = array(
   '#title'       => t('Organism'),
   '#type'        => t('select'),
   '#description' => t("Choose the organism with which this library is ".
                       "associated."),
   '#required'    => TRUE,
   '#default_value' => $organism_id,
   '#options'     => $organisms,
   '#weight'      => 4,
  );

  $form['library_description']= array(
    '#type'          => 'textarea',
    '#title'         => t('Library Description'),
    '#description'   => t('A brief description of the library'),
    '#required'      => TRUE,
    '#default_value' => $library_description,
    '#weight'        => 5
  );

  return $form;
}
chado_library_insert ( node)

When a new chado_library node is created we also need to add information to our chado_library table. This function is called on insert of a new node of type 'chado_library' and inserts the necessary information.

Definition at line 547 of file tripal_library.module.

                                     {

  if ($node->library_id) {
    $library['library_id'] = $node->library_id;
  }
  else {    
    $values = array(
      'name' => $node->title,
      'uniquename' => $node->uniquename,
      'organism_id' => $node->organism_id,
      'type_id' => $node->library_type,
    );
    $library = tripal_core_chado_insert('library', $values);
  }

  if ($library) {
     // add the description property
    tripal_library_insert_property($library['library_id'], 'library_description', 
      $node->library_description);

    // make sure the entry for this feature doesn't already exist in the chado_library table
    // if it doesn't exist then we want to add it.
    $library_id = chado_get_id_for_node('library', $node) ;
    if (!$library_id) {
       // next add the item to the drupal table
      $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
             "VALUES (%d, %d, %d)";
      db_query($sql, $node->nid, $node->vid, $library['library_id']);
    }
  }
  else {
    drupal_set_message(t('Unable to add library.', 'warning'));
    watchdog('tripal_library',
    'Insert feature: Unable to create library where values: %values',
    array('%values' => print_r($values, TRUE)),
    WATCHDOG_WARNING
    );
  }
}
chado_library_load ( node)

When a node is requested by the user this function is called to allow us to add auxiliary data to the node object.

Definition at line 619 of file tripal_library.module.

                                   {
  // get the feature details from chado
  $library_id = chado_get_id_for_node('library', $node);

  $values = array('library_id' => $library_id);
  $library = tripal_core_generate_chado_var('library', $values);

  $additions = new stdClass();
  $additions->library = $library;
  return $additions;

}
chado_library_update ( node)

Update nodes

Definition at line 591 of file tripal_library.module.

                                     {
  if ($node->revision) {
    // there is no way to handle revisions in Chado but leave
    // this here just to make not we've addressed it.
  }
  
  $library_id = chado_get_id_for_node('library', $node) ;
  // update the library record
  $match = array(
     'library_id' => $library_id,
  );
  $values = array(
     'name' => $node->title,
     'uniquename' => $node->uniquename,
     'organism_id' => $node->organism_id,
     'type_id' => $node->library_type,
  );
  $status = tripal_core_chado_update('library', $match, $values);

  tripal_library_update_property($library_id, 'library_description', $node->library_description, 1);

}
chado_library_validate ( node)

validates submission of form when adding or updating a library node

Definition at line 518 of file tripal_library.module.

                                       {
  $lib = 0;
  // check to make sure the unique name on the library is unique
  // before we try to insert into chado.
  if ($node->library_id) {
    $sql = "SELECT * FROM ".
           "{Library} WHERE ".
           "uniquename = '%s' ".
           "AND NOT library_id = %d";
    $lib = db_fetch_object(chado_query($sql, $node->uniquename, $node->library_id));
  }
  else {
    $sql = "SELECT * FROM ".
           "{Library} ".
           "WHERE uniquename = '%s'";
    $lib = db_fetch_object(chado_query($sql, $node->uniquename));
  }
  if ($lib) {
    form_set_error('uniquename', t('The unique library name already exists. '.
                                  'Please choose another'));
  }
}
chado_library_view ( node,
teaser = FALSE,
page = FALSE 
)

This function customizes the view of the chado_library node. It allows us to generate the markup. This function is required for node [Preview]

Definition at line 637 of file tripal_library.module.

                                                                   {
   // use drupal's default node view:
  if (!$teaser) {

    $node = node_prepare($node, $teaser);

    // If Hook_view() is called by Hook_form(), we'll only have orgnism_id
    // but not genus/species/common_name. We need to get those from chado
    // database so they will show up in preview
    if (!$node->genus) {
      $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
      $data = db_fetch_object(chado_query($sql, $node->organism_id));
      $node->genus = $data->genus;
      $node->species = $data->species;
      $node->common_name = $data->common_name;
    }
  }
  return $node;
}
get_tripal_library_admin_form_cleanup_set ( &$  form)

Definition at line 46 of file tripal_library.admin.inc.

                                                           {
  $form['cleanup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Clean Up')
  );
  $form['cleanup']['description'] = array(
     '#type' => 'item',
     '#value' => t("With Drupal and chado residing in different databases ".
        "it is possible that nodes in Drupal and libraries in Chado become ".
        "\"orphaned\".  This can occur if an library node in Drupal is ".
        "deleted but the corresponding chado library is not and/or vice ".
        "versa. Click the button below to resolve these discrepancies."),
     '#weight' => 1,
  );
  $form['cleanup']['button'] = array(
    '#type' => 'submit',
    '#value' => t('Clean up orphaned libraries'),
    '#weight' => 2,
  );
}
get_tripal_library_admin_form_reindex_set ( &$  form)

Definition at line 116 of file tripal_library.admin.inc.

                                                           {
   // define the fieldsets
  $form['reindex'] = array(
    '#type' => 'fieldset',
    '#title' => t('Reindex Library Features')
  );

  // get the list of libraries
  $sql = "SELECT * FROM {Library} ORDER BY uniquename";
  $lib_rset = chado_query($sql);

  // iterate through all of the libraries
  $lib_boxes = array();
  while ($library = db_fetch_object($lib_rset)) {
    $lib_boxes[$library->library_id] = "$library->name";
  }
  $form['reindex']['description'] = array(
     '#type' => 'item',
     '#value' => t("This option allows for reindexing of only those features that belong to the selected libraries below. All other features will be unaffected.  To reindex all features in the site see the Feature Administration page."),
   '#weight' => 1,
  );

  $form['reindex']['re-libraries'] = array(
   '#title'       => t('Libraries'),
   '#type'        => t('checkboxes'),
   '#description' => t("Check the libraries whoee features you want to reindex. Note: this list contains all libraries, even those that may not be synced."),
   '#required'    => FALSE,
   '#prefix'      => '<div id="lib_boxes">',
   '#suffix'      => '</div>',
   '#options'     => $lib_boxes,
   '#weight' => 2,
  );
  $form['reindex']['re-button'] = array(
    '#type' => 'submit',
    '#value' => t('Reindex Features'),
    '#weight' => 3,
  );
}
get_tripal_library_admin_form_sync_set ( &$  form)

Definition at line 158 of file tripal_library.admin.inc.

                                                        {
   // define the fieldsets
  $form['sync'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sync Libraries')
  );


  // get the list of libraries
  $sql = "SELECT * FROM {Library} ORDER BY uniquename";
  $lib_rset = chado_query($sql);

  // if we've added any libraries to the list that can be synced
  // then we want to build the form components to allow the user
  // to select one or all of them.  Otherwise, just present
  // a message stating that all libraries are currently synced.
  $lib_boxes = array();
  $added = 0;
  while ($library = db_fetch_object($lib_rset)) {
    // check to see if the library is already present as a node in drupal.
    // if so, then skip it.
    $sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
    if (!db_fetch_object(db_query($sql, $library->library_id))) {
      $lib_boxes[$library->library_id] = "$library->name";
      $added++;
    }
  }

  // if we have libraries we need to add to the checkbox then
  // build that form element
  if ($added > 0) {
    $lib_boxes['all'] = "All Libraries";

    $form['reindex']['description'] = array(
     '#type' => 'item',
     '#value' => t("This option allows for the creation of Drupal content for libraries in chado. Only the selected libraries will be synced."),
   '#weight' => 1,
    );


    $form['sync']['libraries'] = array(
      '#title'       => t('Available Libraries'),
      '#type'        => t('checkboxes'),
      '#description' => t("Check the libraries you want to sync.  Drupal content will be created for each of the libraries listed above.  Select 'All Libraries' to sync all of them."),
      '#required'    => FALSE,
      '#prefix'      => '<div id="lib_boxes">',
      '#suffix'      => '</div>',
      '#options'     => $lib_boxes,
    '#weight' => 2,
    );
    $form['sync']['button'] = array(
       '#type' => 'submit',
       '#value' => t('Sync Libraries'),
     '#weight' => 3,
    );
  }
   // we don't have any libraries to select from
  else {
    $form['sync']['value'] = array(
       '#value' => t('All libraries in Chado are currently synced with Drupal.')
    );
  }
}
get_tripal_library_admin_form_taxonomy_set ( &$  form)

Definition at line 72 of file tripal_library.admin.inc.

                                                            {
  $form['taxonify'] = array(
    '#type' => 'fieldset',
    '#title' => t('Assign Drupal Taxonomy to Library Features')
  );

  // get the list of libraries
  $sql = "SELECT * FROM {Library} ORDER BY uniquename";
  $lib_rset = chado_query($sql);

  // iterate through all of the libraries
  $lib_boxes = array();
  while ($library = db_fetch_object($lib_rset)) {
    $lib_boxes[$library->library_id] = "$library->name";
  }

  $form['taxonify']['description'] = array(
     '#type' => 'item',
     '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
                   "nodes. These terms allow for advanced filtering during searching. This option allows ".
                   "for setting taxonomy only for features that belong to the selected libraries below.  All other features will be unaffected.  To set taxonomy for all features in the site see the Feature Administration page."),
   '#weight' => 1,
  );

  $form['taxonify']['tx-libraries'] = array(
   '#title'       => t('Libraries'),
   '#type'        => t('checkboxes'),
   '#description' => t("Check the libraries whose features you want to reset taxonomy.  Note: this list contains all libraries, even those that may not be synced."),
   '#required'    => FALSE,
   '#prefix'      => '<div id="lib_boxes">',
   '#suffix'      => '</div>',
   '#options'     => $lib_boxes,
   '#weight'      => 2
  );
  $form['taxonify']['tx-button'] = array(
    '#type' => 'submit',
    '#value' => t('Set Feature Taxonomy'),
    '#weight'      => 3
  );
}
theme_tripal_library_node_libraries ( node)

This function shows library information on an organism/feature node

Definition at line 310 of file tripal_library.module.

                                                    {
  $content = "";

  // Show library information in a expandable box for a organism page.
  // Make sure we have $node->organism_id. In the case of creating a new
  // organism, the organism_id is not created until we save. This will cause
  // an error when users preview the creation without a $node->organism_id
  if ($node->type == 'chado_organism' && $node->organism_id) {
    $box_status = variable_get("tripal_library-box-libraries", "menu_off");

    if (strcmp($box_status, "menu_off")==0) {
      return get_tripal_library_organism_libraries($node->nid);
    }
  }
  // Provide library names to show in a feature page.
  // Make sure we have $node->feature->feature_id or there will be an error
  // when a feature is previewed at its creation
  elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
    $organism_id = $node->feature->organism_id;
    $sql = "SELECT * FROM {library} L ".
           " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
            "WHERE LF.feature_id = " . $node->feature->feature_id;
    $libraries = array();
    $results = chado_query($sql);
    while ($library = db_fetch_object($results)) {
      $libraries[] = $library;
  }
  if (count($libraries) > 0) {
    $lib_additions = array();
    foreach ($libraries as $library) {
      $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
      $lib_nid = db_result(db_query($sql, $library->library_id));
      if ($lib_nid) {
        $lib_url = url("node/$lib_nid");
      }
      $lib_additions[$lib_url] = $library->name;
    };
    $node->lib_additions = $lib_additions;
  }
  }
  return $content;
}
theme_tripal_library_search_index ( node)

This function is an extension of the chado_feature_view and chado_organism_view by providing the markup for the library object THAT WILL BE INDEXED.

Definition at line 257 of file tripal_library.module.

                                                  {

  if ($node->type == 'chado_organism') {
    $content = "";
    // get the libraries for the organism
    $sql = "SELECT * FROM {library} L ".
            "WHERE L.organism_id = %d";
    $libraries = array();
    $results = chado_query($sql, $node->organism->organism_id);
    while ($library = db_fetch_object($results)) {
      // get the description
      $sql = "SELECT * FROM {libraryprop} LP ".
             "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
            "WHERE LP.library_id = $library->library_id ".
            "  AND CVT.name = 'library_description'";
      $desc = db_fetch_object(chado_query($sql));
      $library->description = $desc->value;
      $libraries[] = $library;
    }
    if (count($libraries) > 0) {
      foreach ($libraries as $library) {
        $content .= "$library->name ";
        $content .= "$library->description";
      };
    }
    // Provide library names to show in a feature page
  }
  elseif ($node->type == 'chado_feature') {
    $content = "";
    $organism_id = $node->feature->organism_id;
    $sql = "SELECT * FROM {library} L ".
           "  INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
            "WHERE LF.feature_id = " . $node->feature->feature_id;
    $libraries = array();
    $results = chado_query($sql);
    while ($library = db_fetch_object($results)) {
      $libraries[] = $library;
    }
    if (count($libraries) > 0) {
      $lib_additions = array();
      foreach ($libraries as $library) {
        $content .= $library->name;
      };
    }
  }
  return $content;
}
tripal_library_add_taxonomy ( node,
library_id 
)

Add the library as a taxonomy term for associating with library_features

Definition at line 307 of file tripal_library.admin.inc.

                                                         {

    //include the file containing the required functions.  We only have to
    // do this because Drupal 6 fails to do this globally for us and
    // the drupal_execute function below won't work
    module_load_include('inc', 'taxonomy', 'taxonomy.admin');

   /*   // get the vocabulary id
    $vocabularies = taxonomy_get_vocabularies();
    $vid = NULL;
    foreach($vocabularies as $vocab){
    if($vocab->name == 'DNA Libraries'){
    $vid = $vocab->vid;
    }
    }

    if(!$vid){  */
   // add the vocabulary
  $vocab_form['values']['name'] = 'DNA Libraries';
  $vocab_form['values']['description'] = 'Allows for associating/searching of library features by library name';
  $vocab_form['values']['help'] = '';
  $vocab_form['values']['module'] = 'taxonomy';
  drupal_execute('taxonomy_form_vocabulary', $vocab_form);
  return;
   //   }

   // make sure this term doesn't already exist.  If it doesn't then add it
  if ($vid) {
    $tree = taxonomy_get_tree($vid);
    $found = 0;
    foreach ($tree as $term) {
      if ($term->name == $node->title) {
        $found = 1;
      }
    }

      // add the term to the vocabulary
    if (!$found) {
      $form_state = array();
      $form_state['values']['name'] = $node->title;
      $form_state['values']['description'] = $library_id;
      drupal_execute('taxonomy_form_term', $form_state, $vid);
    }
  }
}
tripal_library_admin ( )

Administrative settings form

Definition at line 9 of file tripal_library.admin.inc.

                                {
  $form = array();

  // before proceeding check to see if we have any
  // currently processing jobs. If so, we don't want
  // to give the opportunity to sync libraries
  $active_jobs = FALSE;
  if (tripal_get_module_active_jobs('tripal_library')) {
    $active_jobs = TRUE;
  }

  // add the field set for syncing libraries
  if (!$active_jobs) {
    get_tripal_library_admin_form_sync_set($form);
    get_tripal_library_admin_form_reindex_set($form);
    get_tripal_library_admin_form_taxonomy_set($form);
    get_tripal_library_admin_form_cleanup_set($form);
  }
  else {
    $form['notice'] = array(
     '#type' => 'fieldset',
     '#title' => t('Library Management Temporarily Unavailable')
    );
    $form['notice']['message'] = array(
        '#value' => t('Currently, library management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
    );
  }

  return system_settings_form($form);
}
tripal_library_admin_validate ( form,
&$  form_state 
)

Definition at line 225 of file tripal_library.admin.inc.

                                                            {
  global $user;  // we need access to the user info
  $job_args = array();

  // Submit the Sync Job if selected
  if ($form_state['values']['op'] == t('Sync Libraries')) {

    // check to see if the user wants to sync chado and drupal.  If
    // so then we need to register a job to do so with tripal
    $libraries = $form_state['values']['libraries'];
    $do_all = FALSE;
    $to_sync = array();

  foreach ($libraries as $library_id) {
    if (preg_match("/^all$/i", $library_id)) {
      $do_all = TRUE;
    }
    if ($library_id and preg_match("/^\d+$/i", $library_id)) {
      // get the library info
      $sql = "SELECT * FROM {Library} WHERE library_id = %d";
      $library = db_fetch_object(chado_query($sql, $library_id));
      $to_sync[$library_id] = $library->name;
    }
  }

  // submit the job to the tripal job manager
  if ($do_all) {
    tripal_add_job('Sync all libraries', 'tripal_library', 'tripal_library_sync_libraries', $job_args, $user->uid);
  }
  else{
    foreach ($to_sync as $library_id => $name) {
      $job_args[0] = $library_id;
      tripal_add_job("Sync library: $name", 'tripal_library', 'tripal_library_sync_libraries', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Reindex Job if selected
  if ($form_state['values']['op'] == t('Reindex Features')) {
    $libraries = $form_state['values']['re-libraries'];
    foreach ($libraries as $library_id) {
      if ($library_id and preg_match("/^\d+$/i", $library_id)) {
        // get the library info
        $sql = "SELECT * FROM {Library} WHERE library_id = %d";
        $library = db_fetch_object(chado_query($sql, $library_id));
        $job_args[0] = $library_id;
        tripal_add_job("Reindex features for library: $library->name", 'tripal_library',
         'tripal_library_reindex_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Taxonomy Job if selected
  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
    $libraries = $form_state['values']['tx-libraries'];
    foreach ($libraries as $library_id) {
      if ($library_id and preg_match("/^\d+$/i", $library_id)) {
        // get the library info
        $sql = "SELECT * FROM {Library} WHERE library_id = %d";
        $library = db_fetch_object(chado_query($sql, $library_id));
        $job_args[0] = $library_id;
        tripal_add_job("Set taxonomy for features in library: $library->name", 'tripal_library',
         'tripal_library_taxonify_features', $job_args, $user->uid);
      }
    }
  }
    // -------------------------------------
    // Submit the Cleanup Job if selected
    if ($form_state['values']['op'] == t('Clean up orphaned libraries')) {
      tripal_add_job('Cleanup orphaned libraries', 'tripal_library',
         'tripal_library_cleanup', $job_args, $user->uid);
    }
}
tripal_library_block ( op = 'list',
delta = '0',
edit = array() 
)

Display block with libraries

Parameters:
op- parameter to define the phase being called for the block
delta- id of the block to return (ignored when op is list)
edit- when op is save, contains the submitted form data

Definition at line 699 of file tripal_library.module.

                                                                           {
  switch ($op) {
    case 'list':

    $blocks['libreferences']['info'] = t('Tripal Library Cross References');
    $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;

    $blocks['libbase']['info'] = t('Tripal Library Details');
    $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
    
    $blocks['libterms']['info'] = t('Tripal Library Terms');
    $blocks['libterms']['cache'] = BLOCK_NO_CACHE;

    $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
    $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;

    $blocks['libproperties']['info'] = t('Tripal Library Properties');
    $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;

    $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
    $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;

    $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
    $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;

    return $blocks;

    case 'view':
      if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
        $nid = arg(1);
        $node = node_load($nid);

        $block = array();
        switch ($delta) {
          case 'libreferences':
            $block['subject'] = t('Cross References');
            $block['content'] = theme('tripal_library_references', $node);
            break;
          case 'libbase':
            $block['subject'] = t('Library Details');
            $block['content'] = theme('tripal_library_base', $node);
            break;
          case 'libsynonyms':
            $block['subject'] = t('Synonyms');
            $block['content'] = theme('tripal_library_synonyms', $node);
            break;
          case 'libproperties':
            $block['subject'] = t('Properties');
            $block['content'] = theme('tripal_library_properties', $node);
            break;
          case 'libterms':
            $block['subject'] = t('Library Terms');
            $block['content'] = theme('tripal_library_terms', $node);
            break;
          case 'featurelibs':
            $block['subject'] = t('Libraries');
            $block['content'] = theme('tripal_feature_libraries', $node);
            break;
          case 'orglibs':
            $block['subject'] = t('Libraries');
            $block['content'] = theme('tripal_organism_libraries', $node);
            break;
            default :
        }
        return $block;
      }
  }
}
tripal_library_cleanup ( dummy = NULL,
job_id = NULL 
)

Remove orphaned drupal nodes

Parameters:
$dummyNot Used -kept for backwards compatibility
$job_idThe id of the tripal job executing this function

Definition at line 579 of file tripal_library.admin.inc.

                                                               {

  return tripal_core_clean_orphaned_nodes('library', $job_id);
  
}
tripal_library_cron ( )

Definition at line 358 of file tripal_library.module.

                               {

}
tripal_library_feature_set_taxonomy ( library_id = NULL)

Definition at line 422 of file tripal_library.admin.inc.

                                                                 {

   //TO DO : return usable error if vocabs don't exist
   // get the list of vocabularies and find our two vocabularies of interest
  $vocabularies = taxonomy_get_vocabularies();
  $vid = NULL;
  foreach ($vocabularies as $vocab) {
    if ($vocab->name == 'Library') {
      $vid = $vocab->vid;
    }
  }
  if (!$vid) {
    return;
  }

  // We'll use the following SQL statement for getting the node info
  if ($library_id) {
    print "Finding features for library with ID: $library_id\n";
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           "FROM {library_feature} LF ".
           "INNER JOIN Library L ON LF.library_id = L.library_id ".
           "WHERE L.library_id = $library_id ".
           "ORDER BY LF.feature_id";
    $features = chado_query($sql);
  }
  else {
    print "Finding features for all libraries\n";
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           "FROM {library_feature} LF ".
           "INNER JOIN Library L ON LF.library_id = L.library_id ".
           "ORDER BY LF.feature_id";
    $features = chado_query($sql);
  }

  $node_sql = "SELECT * FROM {chado_feature} CF ".
             "  INNER JOIN {node} N ON CF.nid = N.nid ".
             "WHERE feature_id = %d";

  // iterate through the features and add the taxonomy
  while ($feature = db_fetch_object($features)) {
    $node = db_fetch_object(db_query($node_sql, $feature->feature_id));
    $tags["$vid"] = $feature->libname;
    $terms['tags'] = $tags;
    taxonomy_node_save($node, $terms);
    print "Updated $feature->feature_id as $feature->libname\n";
  }
}
tripal_library_help ( path,
arg 
)

Display help and module information

Parameters:
pathwhich path of the site we're displaying help
argarray that holds the current path as would be returned from arg() function
Returns:
help text for the path

Definition at line 23 of file tripal_library.module.

                                          {
  $output = '';
  switch ($path) {
    case "admin/help#tripal_library":
      $output = '<p>'.
      t("Displays links to nodes created on this date") .
               '</p>';
      break;
  }
  return $output;
}
tripal_library_library_access ( op,
node,
account 
)

The following function proves access control for users trying to perform actions on data managed by this module

Definition at line 367 of file tripal_library.module.

                                                             {
  if ($op == 'create') {
    if (!user_access('create chado_library content', $account)) {
      return FALSE;
    }
  }

  if ($op == 'update') {
    if (!user_access('edit any chado_library content', $account) &&
        !user_access('edit own chado_library content', $account)) {
        return FALSE;
    }
    if (user_access('edit own chado_library content', $account) &&
      $account->uid != $node->uid) {
      return FALSE;
    }
  }

  if ($op == 'delete') {
    if (!user_access('delete any chado_library content', $account) &&
      !user_access('delete own chado_library content', $account)) {
      return FALSE;
    }
    if (user_access('delete own chado_library content', $account) &&
      $account->uid != $node->uid) {
      return FALSE;
    }
  }
  return NULL;
}
tripal_library_menu ( )

Menu items are automatically added for the new node types created by this module to the 'Create Content' Navigation menu item. This function adds more menu items needed for this module.

Definition at line 107 of file tripal_library.module.

                               {
  $items = array();
  // The administative settings menu
  $items['admin/tripal/tripal_library'] = array(
    'title' => 'Libraries',
    'description' => 'Basic Description of Tripal Library Module Functionality',
    'page callback' => 'theme',
    'page arguments' => array('tripal_library_admin'),
    'access arguments' => array('administer tripal libraries'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/tripal_library/configuration'] = array(
    'title' => 'Library Configuration',
    'description' => 'Manage integration of Chado libraries including associated features.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_library_admin'),
    'access arguments' => array('administer tripal libraries'),
    'type' => MENU_NORMAL_ITEM,
  );

  // Synchronizing libraries from Chado to Drupal
  $items['chado_sync_libraries'] = array(
    'title' => 'Sync Library Data',
    'page callback' => 'tripal_library_sync_libraries',
    'access arguments' => array('administer tripal libraries'),
    'type' => MENU_CALLBACK
  );
  return $items;
}
tripal_library_node_info ( )

Provide information to drupal about the node types that we're creating in this module

Definition at line 41 of file tripal_library.module.

                                    {
  $nodes = array();
  $nodes['chado_library'] = array(
    'name' => t('Library'),
    'module' => 'chado_library',
    'description' => t('A library from the chado database'),
    'has_title' => FALSE,
    'title_label' => t('Library'),
    'has_body' => FALSE,
    'body_label' => t('Library Description'),
    'locked' => TRUE
  );
  return $nodes;
}
tripal_library_nodeapi ( &$  node,
op,
teaser,
page 
)

Implementation of hook_nodeapi(). Display library information for associated features or organisms This function also provides contents for indexing

Definition at line 159 of file tripal_library.module.

                                                             {

  switch ($op) {
    // Note that this function only adds library view to an organism/feature
    // node.
    case 'view':
      // add the library to the organism/feature search indexing
    if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
      $node->content['tripal_library_index_version'] = array(
    '#value' => theme('tripal_library_search_index', $node),
      );
    }
    elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
      $node->content['tripal_library_index_version'] = array(
    '#value' => theme('tripal_library_search_result', $node),
      );
    }
    else {
      switch ($node->type) {
        case 'chado_organism':
          // Show library if the organism/feature is not at teaser view
          $node->content['tripal_organism_libraries'] = array(
        '#value' => theme('tripal_organism_libraries', $node),
          );
        break;
        case 'chado_feature':
          // Show library if the organism/feature is not at teaser view
          $node->content['tripal_feature_libraries'] = array(
        '#value' => theme('tripal_feature_libraries', $node),
          );
        break;
        }
      }
    break;
  }
}
tripal_library_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 63 of file tripal_library.module.

                               {
  return array(
    'access chado_library content',
    'create chado_library content',
    'delete chado_library content',
    'edit chado_library content',
    'administer tripal libraries',
  );
}
tripal_library_reindex_features ( library_id = NULL,
job_id = NULL 
)

Definition at line 473 of file tripal_library.admin.inc.

                                                                             {
  $i = 0;

  // if the caller provided a library_id then get all of the features
  // associated with the library. Otherwise get all sequences assoicated
  // with all libraries.
  if ($library_id) {
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           " FROM {library_feature} LF ".
           "  INNER JOIN Library L ON LF.library_id = L.library_id ".
           "WHERE L.library_id = $library_id ".
           "ORDER BY LF.feature_id";
    $results = chado_query($sql);
  }
  else {
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           " FROM {library_feature} LF ".
           "  INNER JOIN Library L ON LF.library_id = L.library_id ".
           "ORDER BY LF.feature_id";
    $results = chado_query($sql);
  }

   // load into ids array
  $count = 0;
  $ids = array();
  while ($id = db_fetch_object($results)) {
    $ids[$count] = $id->feature_id;
    $count++;
  }

  $interval = intval($count * 0.01);
  foreach ($ids as $feature_id) {
    // update the job status every 1% features
    if ($job_id and $i % interval == 0) {
      tripal_job_set_progress($job_id, intval(($i/$count)*100));
    }
    tripal_feature_sync_feature($feature_id);
    $i++;
  }
}
tripal_library_sync_libraries ( library_id = NULL,
job_id = NULL 
)

Definition at line 359 of file tripal_library.admin.inc.

                                                                           {

  global $user;
  $page_content = '';

  // get the list of libraries and create new nodes
  if (!$library_id) {
    $sql = "SELECT * FROM {Library} L";
    $results = chado_query($sql);
  }
  else {
    $sql = "SELECT * FROM {Library} L WHERE library_id = %d";
    $results = chado_query($sql, $library_id);
  }

  // We'll use the following SQL statement for checking if the library
  // already exists as a drupal node.
  $sql = "SELECT * FROM {chado_library} ".
        "WHERE library_id = %d";

  while ($library = db_fetch_object($results)) {

    // check if this library already exists in the drupal database. if it
    // does then skip this library and go to the next one.
    if (!db_fetch_object(db_query($sql, $library->library_id))) {

    $new_node = new stdClass();
    $new_node->type = 'chado_library';
    $new_node->uid = $user->uid;
    $new_node->title = "$library->name";
    $new_node->library_id = $library->library_id;
    $new_node->organism_id = $library->organism_id;
    $new_node->uniquename = $library->uniquename;
    $new_node->type_id = $library->type_id;

    node_validate($new_node);
    $errors = form_get_errors();
    if (!$errors) {
      $node = node_submit($new_node);
      node_save($node);
      if ($node->nid) {
        print "Added " . $library->name . "\n";
      }
      else {
        print "ERROR: Unable to create " . $library->name . "\n";
      }
    }
    else {
      print "ERROR: Unable to create " . $library->name . "\n" . print_r($errors, TRUE) . "\n";
    }
    }
    else {
      print "Skipped " . $library->name . "\n";
    }
  }
  return $page_content;
}
tripal_library_taxonify_features ( library_id = NULL,
job_id = NULL 
)

Definition at line 517 of file tripal_library.admin.inc.

                                                                              {
  $i = 0;

  // if the caller provided a library_id then get all of the features
  // associated with the library. Otherwise get all sequences assoicated
  // with all libraries.
  if ($library_id) {
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           " FROM {library_feature} LF ".
           "  INNER JOIN Library L ON LF.library_id = L.library_id ".
           "WHERE L.library_id = $library_id ".
           "ORDER BY LF.feature_id";
    $results = chado_query($sql);
  }
  else {
    $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
           " FROM {library_feature} LF ".
           "  INNER JOIN Library L ON LF.library_id = L.library_id ".
           "ORDER BY LF.feature_id";
    $results = chado_query($sql);
  }

  // load into ids array
  $count = 0;
  $ids = array();
  while ($id = db_fetch_object($results)) {
    $ids[$count] = $id->feature_id;
    $count++;
  }

  // make sure our vocabularies are set before proceeding
  tripal_feature_set_vocabulary();

  // use this SQL for getting the nodes
  $nsql =  "SELECT * FROM {chado_feature} CF ".
          "  INNER JOIN {node} N ON N.nid = CF.nid ".
          "WHERE feature_id = %d";

   // iterate through the features and set the taxonomy
  $interval = intval($count * 0.01);
  foreach ($ids as $feature_id) {
    // update the job status every 1% features
    if ($job_id and $i % interval == 0) {
      tripal_job_set_progress($job_id, intval(($i/$count)*100));
    }
      $node = db_fetch_object(db_query($nsql, $feature_id));
      tripal_feature_set_taxonomy($node, $feature_id);
      $i++;
  }
}
tripal_library_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 203 of file tripal_library.module.

                                {
  return array(
    'tripal_library_library_table' => array(
       'arguments' => array('libraries'),
    ),
    'tripal_library_search_index' => array(
       'arguments' => array('node'),
    ),
    'tripal_library_search_result' => array(
       'arguments' => array('node'),
    ),
    'tripal_organism_libraries' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_organism_libraries',
    ),
    'tripal_feature_libraries' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_libraries',
    ),
    'tripal_library_base' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_library_base',
    ),
    'tripal_library_synonyms' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_library_synonyms',
    ),
    'tripal_library_references' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_library_references',
    ),
    'tripal_library_properties' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_library_properties',
    ),
    'tripal_library_terms' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_library_terms',
    ),
    'tripal_library_admin' => array(
      'template' => 'tripal_library_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_library') . '/theme', 
    ),
  );
}
tripal_library_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 146 of file tripal_library.module.

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