stock.views.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the stock table, it's fields and any joins between it and other tables
  5. * @see tripal_stock_views_data() --in tripal_stock.views.inc
  6. *
  7. * @todo add better support for is_obsolete -through a field handler
  8. * @todo Add support for the following tables: stock_cvterm, stock_pub, stock_genotype
  9. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  10. *
  11. * BASE TABLE: stock
  12. * @code
  13. * create table stock (
  14. * stock_id serial not null,
  15. * primary key (stock_id),
  16. * R dbxref_id int,
  17. * foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
  18. * R organism_id int,
  19. * foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
  20. * F name varchar(255),
  21. * F uniquename text not null,
  22. * F description text,
  23. * R type_id int not null,
  24. * foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
  25. * F is_obsolete boolean not null default 'false',
  26. * constraint stock_c1 unique (organism_id,uniquename,type_id)
  27. * );
  28. * @endcode
  29. */
  30. function retrieve_stock_views_data() {
  31. $data = array();
  32. // Basic table definition
  33. $data['stock']['table']['group'] = t('Chado Stock');
  34. $data['stock']['table']['base'] = array(
  35. 'field' => 'stock_id',
  36. 'title' => t('Chado Stock'),
  37. 'help' => t('Chado Stocks are a record of any material upon which an experiment can be done. For example, a DNA sample, an individual or a population.'),
  38. 'database' => 'chado'
  39. );
  40. // Define relationships between this table and others
  41. $data['stock']['table']['join'] = array(
  42. 'organism' => array(
  43. 'left_field' => 'organism_id',
  44. 'field' => 'organism_id',
  45. ),
  46. 'dbxref' => array(
  47. 'left_field' => 'dbxref_id',
  48. 'field' => 'dbxref_id',
  49. ),
  50. );
  51. // Table Field Definitions----------------------
  52. // Field: feature_id (primary key)
  53. $data['stock']['stock_id'] = array(
  54. 'title' => 'Stock ID',
  55. 'help' => 'The primary key of a stock',
  56. 'field' => array(
  57. 'handler' => 'views_handler_field_numeric',
  58. 'click sortable' => TRUE,
  59. ),
  60. 'filter' => array(
  61. 'handler' => 'views_handler_filter_numeric',
  62. ),
  63. 'sort' => array(
  64. 'handler' => 'views_handler_sort',
  65. ),
  66. );
  67. // Calculated Field: Node ID
  68. // use custom field handler to query drupal for the node ID
  69. // this is only needed if chado is in a separate database from drupal
  70. $data['stock']['nid'] = array(
  71. 'title' => 'Node ID',
  72. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  73. 'field' => array(
  74. 'handler' => 'views_handler_field_computed_nid',
  75. ),
  76. );
  77. //Field: unique name (text)
  78. $data['stock']['uniquename'] = array(
  79. 'title' => t('Unique Name'),
  80. 'help' => t('A unique name for this stock.'),
  81. 'field' => array(
  82. 'handler' => 'views_handler_field',
  83. 'click sortable' => TRUE,
  84. ),
  85. 'sort' => array(
  86. 'handler' => 'views_handler_sort',
  87. ),
  88. 'filter' => array(
  89. 'handler' => 'views_handler_filter_string',
  90. ),
  91. 'argument' => array(
  92. 'handler' => 'views_handler_argument_string',
  93. ),
  94. );
  95. //Field: name (varchar 255)
  96. $data['stock']['name'] = array(
  97. 'title' => t('Name'),
  98. 'help' => t('The human-readable name of this stock.'),
  99. 'field' => array(
  100. 'handler' => 'views_handler_field',
  101. 'click sortable' => TRUE,
  102. ),
  103. 'sort' => array(
  104. 'handler' => 'views_handler_sort',
  105. ),
  106. 'filter' => array(
  107. 'handler' => 'views_handler_filter_string',
  108. ),
  109. 'argument' => array(
  110. 'handler' => 'views_handler_argument_string',
  111. ),
  112. );
  113. //Field: description (varchar 255)
  114. $data['stock']['description'] = array(
  115. 'title' => t('Description'),
  116. 'help' => t('Provides a short description for a given stock.'),
  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_string',
  126. ),
  127. 'argument' => array(
  128. 'handler' => 'views_handler_argument_string',
  129. ),
  130. );
  131. //Field: is_obsolete (boolean t/f)
  132. $data['stock']['is_obsolete'] = array(
  133. 'title' => t('Is Obsolete'),
  134. 'help' => t('A yes/no field indicating whether a given stock is obsolete or not.'),
  135. 'field' => array(
  136. 'handler' => 'views_handler_field',
  137. 'click sortable' => TRUE,
  138. ),
  139. 'sort' => array(
  140. 'handler' => 'views_handler_sort',
  141. ),
  142. );
  143. //Calculated Field: stock properties
  144. // uses a custom field handler which pulls results from the view
  145. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  146. $data['stock']['properties'] = array(
  147. 'title' => t('Stock Properties'),
  148. 'help' => t('Properties of the current stock.'),
  149. 'field' => array(
  150. 'title' => t('Properties'),
  151. 'help' => t('Display a given type of properties associated with a stock.'),
  152. 'handler' => 'views_handler_field_stockprop_by_type',
  153. ),
  154. );
  155. //Calculated Field: stock properties (ALL)
  156. // uses a custom field handler which pulls results from the view
  157. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  158. $data['stock']['all_properties'] = array(
  159. 'title' => t('All Stock Properties'),
  160. 'help' => t('Properties of the current stock.'),
  161. 'field' => array(
  162. 'title' => t('All Properties'),
  163. 'help' => t('Display all properties associated with a stock.'),
  164. 'handler' => 'views_handler_field_stockprop_all',
  165. ),
  166. );
  167. //Calculated Field: stock relationships
  168. // uses a custom field handler which pulls results from the view
  169. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  170. $data['stock']['relationships'] = array(
  171. 'title' => t('Stock Relationships'),
  172. 'help' => t('Relationships including the current stock.'),
  173. 'field' => array(
  174. 'title' => t('Relationships'),
  175. 'help' => t('Display a given type of relationships including the current stock.'),
  176. 'handler' => 'views_handler_field_stockrel_by_type',
  177. ),
  178. );
  179. //Calculated Field: stock relationships (ALL)
  180. // uses a custom field handler which pulls results from the view
  181. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  182. $data['stock']['all_relationships'] = array(
  183. 'title' => t('All Stock Relationships'),
  184. 'help' => t('Relationships including the current stock.'),
  185. 'field' => array(
  186. 'title' => t('All Relationships'),
  187. 'help' => t('Display all relationships including the stock.'),
  188. 'handler' => 'views_handler_field_stockrel_all',
  189. ),
  190. );
  191. //Calculated Field: stock dbxrefs
  192. // uses a custom field handler which pulls results from the view
  193. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  194. $data['stock']['dbxref'] = array(
  195. 'title' => t('Stock Database References'),
  196. 'help' => t('Database References associated with the current stock.'),
  197. 'field' => array(
  198. 'title' => t('Database References'),
  199. 'help' => t('Display database references from a given database for the current stock.'),
  200. 'handler' => 'views_handler_field_stock_dbxref_by_type',
  201. ),
  202. );
  203. //Calculated Field: stock dbxrefs (ALL)
  204. // uses a custom field handler which pulls results from the view
  205. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  206. $data['stock']['all_dbxref'] = array(
  207. 'title' => t('All Stock Database References'),
  208. 'help' => t('Database References associated with the current stock.'),
  209. 'field' => array(
  210. 'title' => t('All Database References'),
  211. 'help' => t('Display all database references for the current stock.'),
  212. 'handler' => 'views_handler_field_stock_dbxref_all',
  213. ),
  214. );
  215. return $data;
  216. }