organism.views.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the organism table, it's fields and any joins between it and other tables
  5. * @see tripal_organism_views_data() --in tripal_organism.views.inc
  6. *
  7. * @todo Add support for the following tables: organismprop, organism_dbxref
  8. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  9. *
  10. * BASE TABLE: organism
  11. * @code
  12. * create table organism (
  13. * organism_id serial not null,
  14. * primary key (organism_id),
  15. * abbreviation varchar(255) null,
  16. * genus varchar(255) not null,
  17. * species varchar(255) not null,
  18. * common_name varchar(255) null,
  19. * comment text null,
  20. * constraint organism_c1 unique (genus,species)
  21. * );
  22. * @endcode
  23. */
  24. function retrieve_organism_views_data() {
  25. global $db_url;
  26. $data = array();
  27. // if the chado database is not local to the drupal database
  28. // then we need to set the database name. This should always
  29. // be 'chado'.
  30. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  31. $database = 'chado';
  32. }
  33. // Basic table definition
  34. $data['organism']['table']['group'] = 'Chado Organism';
  35. $data['organism']['table']['base'] = array(
  36. 'field' => 'organism_id',
  37. 'title' => 'Chado Organism',
  38. 'help' => 'Organisms existing in the Chado Database',
  39. );
  40. if($database){
  41. $data['organism']['table']['database'] = $database;
  42. }
  43. // Define relationships between this table and others
  44. $data['organism']['table']['join'] = array(
  45. 'feature' => array(
  46. 'left_field' => 'organism_id',
  47. 'field' => 'organism_id',
  48. ),
  49. 'library' => array(
  50. 'left_field' => 'organism_id',
  51. 'field' => 'organism_id',
  52. ),
  53. 'stock' => array(
  54. 'left_field' => 'organism_id',
  55. 'field' => 'organism_id',
  56. ),
  57. );
  58. // Table Field Definitions----------------------
  59. // Field: organism_id (primary key)
  60. $data['organism']['organism_id'] = array(
  61. 'title' => 'Organism ID',
  62. 'help' => 'The primary key of the organism.',
  63. 'field' => array(
  64. 'handler' => 'views_handler_field_numeric',
  65. 'click sortable' => TRUE,
  66. ),
  67. 'filter' => array(
  68. 'handler' => 'views_handler_filter_numeric',
  69. ),
  70. 'sort' => array(
  71. 'handler' => 'views_handler_sort',
  72. ),
  73. 'argument' => array(
  74. 'handler' => 'views_handler_argument',
  75. ),
  76. );
  77. // Calculated Field: Node ID
  78. // use custom field handler to query drupal for the node ID
  79. // this is only needed if chado is in a separate database from drupal
  80. if($database){
  81. $data['organism']['organism_nid'] = array(
  82. 'title' => 'Node ID',
  83. 'help' => 'This is the node ID of this organism. It can be used as a link to the node.',
  84. 'field' => array(
  85. 'handler' => 'views_handler_field_computed_organism_nid',
  86. ),
  87. );
  88. }
  89. // Field: abbreviation (varchar 255)
  90. $data['organism']['abbreviation'] = array(
  91. 'title' => 'Abbreviation',
  92. 'help' => 'The abbreviation of the organism name ie: A.thaliana.',
  93. 'field' => array(
  94. 'handler' => 'views_handler_field',
  95. 'click sortable' => TRUE,
  96. ),
  97. 'sort' => array(
  98. 'handler' => 'views_handler_sort',
  99. ),
  100. 'filter' => array(
  101. 'handler' => 'views_handler_filter_string',
  102. ),
  103. 'argument' => array(
  104. 'handler' => 'views_handler_argument_string',
  105. ),
  106. );
  107. // if joined to the node table add a "Link to Node" option for the field
  108. if (!$database) {
  109. $data['organism']['abbreviation']['field']['handler'] = 'views_handler_field_node_optional';
  110. }
  111. // Field: genus (varchar 255)
  112. $data['organism']['genus'] = array(
  113. 'title' => 'Genus',
  114. 'help' => 'The genus portion of the organism\'s scientific name',
  115. 'field' => array(
  116. 'handler' => 'views_handler_field',
  117. 'click sortable' => TRUE,
  118. ),
  119. 'sort' => array(
  120. 'handler' => 'views_handler_sort',
  121. ),
  122. 'filter' => array(
  123. 'handler' => 'views_handler_filter_string',
  124. ),
  125. 'argument' => array(
  126. 'handler' => 'views_handler_argument_string',
  127. ),
  128. );
  129. // Field: species (varchar 255)
  130. $data['organism']['species'] = array(
  131. 'title' => 'Species',
  132. 'help' => 'The species portion of the organism\'s scientific name',
  133. 'field' => array(
  134. 'handler' => 'views_handler_field',
  135. 'click sortable' => TRUE,
  136. ),
  137. 'sort' => array(
  138. 'handler' => 'views_handler_sort',
  139. ),
  140. 'filter' => array(
  141. 'handler' => 'views_handler_filter_string',
  142. ),
  143. 'argument' => array(
  144. 'handler' => 'views_handler_argument_string',
  145. ),
  146. );
  147. // Field: common name (varchar 255)
  148. $data['organism']['common_name'] = array(
  149. 'title' => 'Common Name',
  150. 'help' => 'The common name of the organism.',
  151. 'field' => array(
  152. 'handler' => 'views_handler_field',
  153. 'click sortable' => TRUE,
  154. ),
  155. 'sort' => array(
  156. 'handler' => 'views_handler_sort',
  157. ),
  158. 'filter' => array(
  159. 'handler' => 'views_handler_filter_string',
  160. ),
  161. 'argument' => array(
  162. 'handler' => 'views_handler_argument_string',
  163. ),
  164. );
  165. // if joined to the node table add a "Link to Node" option for the field
  166. if (!$database) {
  167. $data['organism']['common_name']['field']['handler'] = 'views_handler_field_node_optional';
  168. }
  169. // Field: Comment (text)
  170. $data['organism']['comment'] = array(
  171. 'title' => 'Comment',
  172. 'help' => 'A free-text comment about the organism',
  173. 'field' => array(
  174. 'handler' => 'views_handler_field',
  175. 'click sortable' => TRUE,
  176. ),
  177. 'filter' => array(
  178. 'handler' => 'views_handler_filter_string',
  179. ),
  180. 'argument' => array(
  181. 'handler' => 'views_handler_argument_string',
  182. ),
  183. );
  184. return $data;
  185. }