tripal_organism.api.inc 4.1 KB

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