function tripal_library_feature_set_taxonomy

1.x tripal_library.admin.inc tripal_library_feature_set_taxonomy($library_id = NULL)

Related topics

File

tripal_library/includes/tripal_library.admin.inc, line 422

Code

function tripal_library_feature_set_taxonomy($library_id = NULL) {

  //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";
  }
}