organism.views.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. } else {
  91. // Add relationship between chado_organism and organism
  92. $data['organism']['organism_nid'] = array(
  93. 'group' => 'Organism',
  94. 'title' => 'Organism Node',
  95. 'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
  96. 'real field' => 'organism_id',
  97. 'relationship' => array(
  98. 'handler' => 'views_handler_relationship',
  99. 'title' => t('Organism => Chado'),
  100. 'label' => t('Organism => Chado'),
  101. 'real field' => 'organism_id',
  102. 'base' => 'chado_organism',
  103. 'base field' => 'organism_id'
  104. ),
  105. );
  106. }
  107. // Field: abbreviation (varchar 255)
  108. $data['organism']['abbreviation'] = array(
  109. 'title' => 'Abbreviation',
  110. 'help' => 'The abbreviation of the organism name ie: A.thaliana.',
  111. 'field' => array(
  112. 'handler' => 'views_handler_field',
  113. 'click sortable' => TRUE,
  114. ),
  115. 'sort' => array(
  116. 'handler' => 'views_handler_sort',
  117. ),
  118. 'filter' => array(
  119. 'handler' => 'views_handler_filter_chado_select_string',
  120. ),
  121. 'argument' => array(
  122. 'handler' => 'views_handler_argument_string',
  123. ),
  124. );
  125. // if joined to the node table add a "Link to Node" option for the field
  126. if (!$database) {
  127. $data['organism']['abbreviation']['field']['handler'] = 'views_handler_field_node_optional';
  128. }
  129. // Field: genus (varchar 255)
  130. $data['organism']['genus'] = array(
  131. 'title' => 'Genus',
  132. 'help' => 'The genus 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_chado_select_string',
  142. ),
  143. 'argument' => array(
  144. 'handler' => 'views_handler_argument_string',
  145. ),
  146. );
  147. // Field: species (varchar 255)
  148. $data['organism']['species'] = array(
  149. 'title' => 'Species',
  150. 'help' => 'The species portion of the organism\'s scientific name',
  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_chado_select_string',
  160. ),
  161. 'argument' => array(
  162. 'handler' => 'views_handler_argument_string',
  163. ),
  164. );
  165. // Field: common name (varchar 255)
  166. $data['organism']['common_name'] = array(
  167. 'title' => 'Common Name',
  168. 'help' => 'The common name of the organism.',
  169. 'field' => array(
  170. 'handler' => 'views_handler_field',
  171. 'click sortable' => TRUE,
  172. ),
  173. 'sort' => array(
  174. 'handler' => 'views_handler_sort',
  175. ),
  176. 'filter' => array(
  177. 'handler' => 'views_handler_filter_organism_common_name',
  178. ),
  179. 'argument' => array(
  180. 'handler' => 'views_handler_argument_string',
  181. ),
  182. );
  183. // if joined to the node table add a "Link to Node" option for the field
  184. if (!$database) {
  185. $data['organism']['common_name']['field']['handler'] = 'views_handler_field_node_optional';
  186. }
  187. // Field: Comment (text)
  188. $data['organism']['comment'] = array(
  189. 'title' => 'Comment',
  190. 'help' => 'A free-text comment about the organism',
  191. 'field' => array(
  192. 'handler' => 'views_handler_field',
  193. 'click sortable' => TRUE,
  194. ),
  195. 'filter' => array(
  196. 'handler' => 'views_handler_filter_string',
  197. ),
  198. 'argument' => array(
  199. 'handler' => 'views_handler_argument_string',
  200. ),
  201. );
  202. //Calculated Field: Count (Int)
  203. // Provides the number of features for a given organism
  204. // @see tripal_feature/views/misc_tables.views.inc
  205. //Calculated Field: Count (Int)
  206. // Provides the number of stocks for a given organism
  207. // @see tripal_stock/views/misc_tables.views.inc
  208. //Calculated Field: Number of Libraries (Count -Int)
  209. // Provides the number of libraries for a given organism
  210. // @see tripal_library/views/misc_tables.views.inc
  211. return $data;
  212. }