organism.views.inc 6.9 KB

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