tripal_organism.api.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * @file
  4. * Provides an API to tripal organisms
  5. */
  6. /**
  7. * Purpose: Create an options array to be used in a form element
  8. * which provides a list of all chado organisms
  9. *
  10. * @return an array(organism_id => common_name)
  11. * for each organism in the chado organism table
  12. *
  13. * @ingroup tripal_organism_api
  14. */
  15. function tripal_organism_get_organism_options() {
  16. $result = chado_query(
  17. "SELECT organism_id, common_name FROM {organism}"
  18. );
  19. $options = array();
  20. while ( $r = db_fetch_object($result) ) {
  21. $options[$r->organism_id] = $r->common_name;
  22. }
  23. return $options;
  24. }
  25. /**
  26. * Purpose: Return a given organism object using the nid
  27. *
  28. * @return organism object created by node load
  29. *
  30. * @ingroup tripal_organism_api
  31. */
  32. function tripal_organism_get_organism_by_nid($nid) {
  33. return node_load($nid);
  34. }
  35. /**
  36. * Purpose: Return a given organism object using the organism id
  37. *
  38. * @return organism object created by node load
  39. *
  40. * @ingroup tripal_organism_api
  41. */
  42. function tripal_organism_get_organism_by_organism_id($organism_id) {
  43. $sql = "SELECT nid FROM {chado_organism} WHERE organism_id=%d";
  44. $r = db_fetch_object(db_query($sql, $organism_id));
  45. if (!empty($r->nid)) {
  46. return node_load($r->nid);
  47. }
  48. else {
  49. drupal_set_message(t("Function: tripal_organism_get_organism_by_organism_id() -no organism with that organism id sync'd with drupal"), 'error');
  50. }
  51. return 0;
  52. }
  53. /**
  54. * @section Chado Table Descriptions
  55. * There should be a default table description for all chado tables included
  56. * in core.
  57. */
  58. /**
  59. * Implements hook_chado_schema_v1_11_table()
  60. *
  61. * Purpose: To add descriptions and foreign keys to default table description
  62. * Note: This array will be merged with the array from all other implementations
  63. *
  64. * @return
  65. * Array describing the organism table
  66. *
  67. * @ingroup tripal_schema_api
  68. */
  69. function tripal_organism_chado_schema_v1_11_organism() {
  70. $description = array();
  71. $referring_tables = array(
  72. 'biomaterial',
  73. 'feature',
  74. 'library',
  75. 'organism_dbxref',
  76. 'organismprop',
  77. 'phylonode_organism',
  78. 'stock',
  79. 'wwwuser_organism'
  80. );
  81. $description['referring_tables'] = $referring_tables;
  82. return $description;
  83. }
  84. /**
  85. * Implements hook_chado_schema_v1_2_table()
  86. *
  87. * Purpose: To add descriptions and foreign keys to default table description
  88. * Note: This array will be merged with the array from all other implementations
  89. *
  90. * @return
  91. * Array describing the organism table
  92. *
  93. * @ingroup tripal_schema_api
  94. */
  95. function tripal_organism_chado_schema_v1_2_organism() {
  96. $description = array();
  97. $referring_tables = array(
  98. 'biomaterial',
  99. 'feature',
  100. 'library',
  101. 'organism_dbxref',
  102. 'organismprop',
  103. 'phylonode_organism',
  104. 'stock',
  105. 'wwwuser_organism'
  106. );
  107. $description['referring_tables'] = $referring_tables;
  108. return $description;
  109. }
  110. /**
  111. * Returns a list of organisms that are currently synced with Drupal
  112. * @ingroup tripal_organism_api
  113. */
  114. function tripal_organism_get_synced() {
  115. // use this SQL for getting synced organisms
  116. $dsql = "SELECT * FROM {chado_organism}";
  117. $orgs = db_query($dsql);
  118. // use this SQL statement for getting the organisms
  119. $csql = "SELECT * FROM {Organism} ".
  120. "WHERE organism_id = %d";
  121. $org_list = array();
  122. // iterate through the organisms and build an array of those that are synced
  123. while ($org = db_fetch_object($orgs)) {
  124. $info = db_fetch_object(chado_query($csql, $org->organism_id));
  125. $org_list[] = $info;
  126. }
  127. return $org_list;
  128. }