organism.views.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * @ingroup tripal_organism_views
  25. */
  26. function retrieve_organism_views_data() {
  27. global $db_url;
  28. $data = array();
  29. // if the chado database is not local to the drupal database
  30. // then we need to set the database name. This should always
  31. // be 'chado'.
  32. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  33. $database = 'chado';
  34. }
  35. // Basic table definition
  36. $data['organism']['table']['group'] = 'Chado Organism';
  37. $data['organism']['table']['base'] = array(
  38. 'field' => 'organism_id',
  39. 'title' => 'Chado Organism',
  40. 'help' => 'Organisms existing in the Chado Database',
  41. );
  42. if($database){
  43. $data['organism']['table']['base']['database'] = $database;
  44. }
  45. // Define relationships between this table and others
  46. $data['organism']['table']['join'] = array(
  47. 'feature' => array(
  48. 'left_field' => 'organism_id',
  49. 'field' => 'organism_id',
  50. ),
  51. 'library' => array(
  52. 'left_field' => 'organism_id',
  53. 'field' => 'organism_id',
  54. ),
  55. 'stock' => array(
  56. 'left_field' => 'organism_id',
  57. 'field' => 'organism_id',
  58. ),
  59. );
  60. // Table Field Definitions----------------------
  61. // Field: organism_id (primary key)
  62. $data['organism']['organism_id'] = array(
  63. 'title' => 'Organism ID',
  64. 'help' => 'The primary key of the organism.',
  65. 'field' => array(
  66. 'handler' => 'views_handler_field_numeric',
  67. 'click sortable' => TRUE,
  68. ),
  69. 'filter' => array(
  70. 'handler' => 'views_handler_filter_numeric',
  71. ),
  72. 'sort' => array(
  73. 'handler' => 'views_handler_sort',
  74. ),
  75. 'argument' => array(
  76. 'handler' => 'views_handler_argument',
  77. ),
  78. );
  79. // Calculated Field: Node ID
  80. // use custom field handler to query drupal for the node ID
  81. // this is only needed if chado is in a separate database from drupal
  82. if($database){
  83. $data['organism']['organism_nid'] = array(
  84. 'title' => 'Node ID',
  85. 'help' => 'This is the node ID of this organism. It can be used as a link to the node.',
  86. 'field' => array(
  87. 'handler' => 'views_handler_field_computed_organism_nid',
  88. ),
  89. );
  90. }
  91. // Field: abbreviation (varchar 255)
  92. $data['organism']['abbreviation'] = array(
  93. 'title' => 'Abbreviation',
  94. 'help' => 'The abbreviation of the organism name ie: A.thaliana.',
  95. 'field' => array(
  96. 'handler' => 'views_handler_field',
  97. 'click sortable' => TRUE,
  98. ),
  99. 'sort' => array(
  100. 'handler' => 'views_handler_sort',
  101. ),
  102. 'filter' => array(
  103. 'handler' => 'views_handler_filter_chado_select_string',
  104. ),
  105. 'argument' => array(
  106. 'handler' => 'views_handler_argument_string',
  107. ),
  108. );
  109. // if joined to the node table add a "Link to Node" option for the field
  110. if (!$database) {
  111. $data['organism']['abbreviation']['field']['handler'] = 'views_handler_field_node_optional';
  112. }
  113. // Field: genus (varchar 255)
  114. $data['organism']['genus'] = array(
  115. 'title' => 'Genus',
  116. 'help' => 'The genus portion of the organism\'s scientific name',
  117. 'field' => array(
  118. 'handler' => 'views_handler_field',
  119. 'click sortable' => TRUE,
  120. ),
  121. 'sort' => array(
  122. 'handler' => 'views_handler_sort',
  123. ),
  124. 'filter' => array(
  125. 'handler' => 'views_handler_filter_chado_select_string',
  126. ),
  127. 'argument' => array(
  128. 'handler' => 'views_handler_argument_string',
  129. ),
  130. );
  131. // Field: species (varchar 255)
  132. $data['organism']['species'] = array(
  133. 'title' => 'Species',
  134. 'help' => 'The species portion of the organism\'s scientific name',
  135. 'field' => array(
  136. 'handler' => 'views_handler_field',
  137. 'click sortable' => TRUE,
  138. ),
  139. 'sort' => array(
  140. 'handler' => 'views_handler_sort',
  141. ),
  142. 'filter' => array(
  143. 'handler' => 'views_handler_filter_chado_select_string',
  144. ),
  145. 'argument' => array(
  146. 'handler' => 'views_handler_argument_string',
  147. ),
  148. );
  149. // Field: common name (varchar 255)
  150. $data['organism']['common_name'] = array(
  151. 'title' => 'Common Name',
  152. 'help' => 'The common name of the organism.',
  153. 'field' => array(
  154. 'handler' => 'views_handler_field',
  155. 'click sortable' => TRUE,
  156. ),
  157. 'sort' => array(
  158. 'handler' => 'views_handler_sort',
  159. ),
  160. 'filter' => array(
  161. 'handler' => 'views_handler_filter_organism_common_name',
  162. ),
  163. 'argument' => array(
  164. 'handler' => 'views_handler_argument_string',
  165. ),
  166. );
  167. // if joined to the node table add a "Link to Node" option for the field
  168. if (!$database) {
  169. $data['organism']['common_name']['field']['handler'] = 'views_handler_field_node_optional';
  170. }
  171. // Field: Comment (text)
  172. $data['organism']['comment'] = array(
  173. 'title' => 'Comment',
  174. 'help' => 'A free-text comment about the organism',
  175. 'field' => array(
  176. 'handler' => 'views_handler_field',
  177. 'click sortable' => TRUE,
  178. ),
  179. 'filter' => array(
  180. 'handler' => 'views_handler_filter_string',
  181. ),
  182. 'argument' => array(
  183. 'handler' => 'views_handler_argument_string',
  184. ),
  185. );
  186. //Calculated Field: Count (Int)
  187. // Provides the number of features for a given organism
  188. // @see tripal_feature/views/misc_tables.views.inc
  189. //Calculated Field: Count (Int)
  190. // Provides the number of stocks for a given organism
  191. // @see tripal_stock/views/misc_tables.views.inc
  192. //Calculated Field: Number of Libraries (Count -Int)
  193. // Provides the number of libraries for a given organism
  194. // @see tripal_library/views/misc_tables.views.inc
  195. return $data;
  196. }