tripal_organism.api.inc 1.7 KB

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