tripal_organism.api.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Provides an application programming interface (API) to manage organisms
  5. *
  6. * @defgroup tripal_library_api Organism Module API
  7. * @ingroup tripal_api
  8. */
  9. /**
  10. * Purpose: Return a given organism object using the nid
  11. *
  12. * @return organism object created by node load
  13. *
  14. * @ingroup tripal_organism_api
  15. */
  16. function tripal_organism_get_organism_by_nid($nid) {
  17. return node_load($nid);
  18. }
  19. /**
  20. * Purpose: Return a given organism object using the organism id
  21. *
  22. * @return organism object created by node load
  23. *
  24. * @ingroup tripal_organism_api
  25. */
  26. function tripal_organism_get_organism_by_organism_id($organism_id) {
  27. $sql = "SELECT nid FROM {chado_organism} WHERE organism_id=%d";
  28. $r = db_fetch_object(db_query($sql, $organism_id));
  29. if (!empty($r->nid)) {
  30. return node_load($r->nid);
  31. }
  32. else {
  33. drupal_set_message(t("Function: tripal_organism_get_organism_by_organism_id() -no organism with that organism id sync'd with drupal"), 'error');
  34. }
  35. return 0;
  36. }
  37. /**
  38. * Returns a list of organisms that are currently synced with Drupal
  39. * @ingroup tripal_organism_api
  40. */
  41. function tripal_organism_get_synced() {
  42. // use this SQL for getting synced organisms
  43. $dsql = "SELECT * FROM {chado_organism}";
  44. $orgs = db_query($dsql);
  45. // use this SQL statement for getting the organisms
  46. $csql = "SELECT * FROM {Organism} ".
  47. "WHERE organism_id = %d";
  48. $org_list = array();
  49. // iterate through the organisms and build an array of those that are synced
  50. while ($org = db_fetch_object($orgs)) {
  51. $info = db_fetch_object(chado_query($csql, $org->organism_id));
  52. $org_list[] = $info;
  53. }
  54. return $org_list;
  55. }