tripal_organism.api.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. function tripal_organism_get_organism_options() {
  10. $previous_db = tripal_db_set_active('chado');
  11. $result = db_query(
  12. "SELECT organism_id, common_name FROM organism"
  13. );
  14. tripal_db_set_active($previous_db);
  15. $options = array();
  16. while ( $r = db_fetch_object($result) ) {
  17. $options[$r->organism_id] = $r->common_name;
  18. }
  19. return $options;
  20. }
  21. /*************************************************************************
  22. * Purpose: Return a given organism object using the nid
  23. *
  24. * @return organism object created by node load
  25. */
  26. function tripal_organism_get_organism_by_nid ($nid) {
  27. return node_load($nid);
  28. }
  29. /*************************************************************************
  30. * Purpose: Return a given organism object using the organism id
  31. *
  32. * @return organism object created by node load
  33. */
  34. function tripal_organism_get_organism_by_organism_id ($organism_id) {
  35. $sql = "SELECT nid FROM {chado_organism} WHERE organism_id=%d";
  36. $r = db_fetch_object(db_query($sql, $organism_id));
  37. if (!empty($r->nid)) {
  38. return node_load($r->nid);
  39. } else {
  40. drupal_set_message("Function: tripal_organism_get_organism_by_organism_id() -no organism with that organism id sync'd with drupal", 'error');
  41. }
  42. return 0;
  43. }
  44. /****************************************************************************
  45. * @section Chado Table Descriptions
  46. * There should be a default table description for all chado tables included
  47. * in core.
  48. ****************************************************************************/
  49. /**
  50. * Implements hook_chado_organism_schema()
  51. *
  52. * Purpose: To add descriptions and foreign keys to default table description
  53. * Note: This array will be merged with the array from all other implementations
  54. *
  55. * @return
  56. * Array describing the organism table
  57. *
  58. * @ingroup tripal_schema_api
  59. */
  60. function tripal_organism_chado_organism_schema() {
  61. $description = array();
  62. $referring_tables = array(
  63. 'biomaterial',
  64. 'feature',
  65. 'library',
  66. 'organism_dbxref',
  67. 'organismprop',
  68. 'phylonode_organism',
  69. 'stock',
  70. 'wwwuser_organism'
  71. );
  72. $description['referring_tables'] = $referring_tables;
  73. return $description;
  74. }
  75. /**
  76. * Implements hook_chado_organismprop_schema()
  77. *
  78. * Purpose: To add descriptions and foreign keys to default table description
  79. * Note: This array will be merged with the array from all other implementations
  80. *
  81. * @return
  82. * Array describing the organismprop table
  83. *
  84. * @ingroup tripal_schema_api
  85. */
  86. function tripal_organism_chado_organismprop_schema() {
  87. $description = array();
  88. $description['foreign keys']['cvterm'] = array(
  89. 'table' => 'cvterm',
  90. 'columns' => array(
  91. 'type_id' => 'cvterm_id',
  92. ),
  93. );
  94. $description['foreign keys']['organism'] = array(
  95. 'table' => 'organism',
  96. 'columns' => array(
  97. 'organism_id' => 'organism_id',
  98. ),
  99. );
  100. return $description;
  101. }