stock.views.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. global $db_url;
  32. $data = array();
  33. // if the chado database is not local to the drupal database
  34. // then we need to set the database name. This should always
  35. // be 'chado'.
  36. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  37. $database = 'chado';
  38. }
  39. // Basic table definition
  40. $data['stock']['table']['group'] = t('Chado Stock');
  41. $data['stock']['table']['base'] = array(
  42. 'field' => 'stock_id',
  43. 'title' => t('Chado Stock'),
  44. '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.'),
  45. );
  46. if($database){
  47. $data['stock']['table']['database'] = $database;
  48. }
  49. // Define relationships between this table and others
  50. $data['stock']['table']['join'] = array(
  51. 'organism' => array(
  52. 'left_field' => 'organism_id',
  53. 'field' => 'organism_id',
  54. ),
  55. );
  56. // Table Field Definitions----------------------
  57. // Field: feature_id (primary key)
  58. $data['stock']['stock_id'] = array(
  59. 'title' => 'Stock ID',
  60. 'help' => 'The primary key of a stock',
  61. 'field' => array(
  62. 'handler' => 'views_handler_field_numeric',
  63. 'click sortable' => TRUE,
  64. ),
  65. 'filter' => array(
  66. 'handler' => 'views_handler_filter_numeric',
  67. ),
  68. 'sort' => array(
  69. 'handler' => 'views_handler_sort',
  70. ),
  71. );
  72. // Calculated Field: Node ID
  73. // use custom field handler to query drupal for the node ID
  74. // this is only needed if chado is in a separate database from drupal
  75. if ($database){
  76. $data['stock']['stock_nid'] = array(
  77. 'title' => 'Node ID',
  78. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  79. 'field' => array(
  80. 'handler' => 'views_handler_field_computed_stock_nid',
  81. ),
  82. );
  83. }
  84. //Field: unique name (text)
  85. $data['stock']['uniquename'] = array(
  86. 'title' => t('Unique Name'),
  87. 'help' => t('A unique name for this stock.'),
  88. 'field' => array(
  89. 'handler' => 'views_handler_field',
  90. 'click sortable' => TRUE,
  91. ),
  92. 'sort' => array(
  93. 'handler' => 'views_handler_sort',
  94. ),
  95. 'filter' => array(
  96. 'handler' => 'views_handler_filter_string',
  97. ),
  98. 'argument' => array(
  99. 'handler' => 'views_handler_argument_string',
  100. ),
  101. );
  102. //Field: name (varchar 255)
  103. $data['stock']['name'] = array(
  104. 'title' => t('Name'),
  105. 'help' => t('The human-readable name of this stock.'),
  106. 'field' => array(
  107. 'handler' => 'views_handler_field',
  108. 'click sortable' => TRUE,
  109. ),
  110. 'sort' => array(
  111. 'handler' => 'views_handler_sort',
  112. ),
  113. 'filter' => array(
  114. 'handler' => 'views_handler_filter_string',
  115. ),
  116. 'argument' => array(
  117. 'handler' => 'views_handler_argument_string',
  118. ),
  119. );
  120. //Field: description (varchar 255)
  121. $data['stock']['description'] = array(
  122. 'title' => t('Description'),
  123. 'help' => t('Provides a short description for a given stock.'),
  124. 'field' => array(
  125. 'handler' => 'views_handler_field',
  126. 'click sortable' => TRUE,
  127. ),
  128. 'sort' => array(
  129. 'handler' => 'views_handler_sort',
  130. ),
  131. 'filter' => array(
  132. 'handler' => 'views_handler_filter_string',
  133. ),
  134. 'argument' => array(
  135. 'handler' => 'views_handler_argument_string',
  136. ),
  137. );
  138. //Field: is_obsolete (boolean t/f)
  139. $data['stock']['is_obsolete'] = array(
  140. 'title' => t('Is Obsolete'),
  141. 'help' => t('A yes/no field indicating whether a given stock is obsolete or not.'),
  142. 'field' => array(
  143. 'handler' => 'views_handler_field',
  144. 'click sortable' => TRUE,
  145. ),
  146. 'sort' => array(
  147. 'handler' => 'views_handler_sort',
  148. ),
  149. );
  150. //Calculated Field: stock properties
  151. // uses a custom field handler which pulls results from the view
  152. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  153. $data['stock']['properties'] = array(
  154. 'title' => t('Stock Properties'),
  155. 'help' => t('Properties of the current stock.'),
  156. 'field' => array(
  157. 'title' => t('Properties'),
  158. 'help' => t('Display a given type of properties associated with a stock.'),
  159. 'handler' => 'views_handler_field_stockprop_by_type',
  160. ),
  161. 'filter' => array(
  162. 'title' => t('Properties'),
  163. 'help' => t('Filter by a given property type or value.'),
  164. 'handler' => 'views_handler_filter_stockprop_id',
  165. ),
  166. 'argument' => array(
  167. 'title' => t('Properties'),
  168. 'help' => t('Allow a property to be supplied in the path'),
  169. 'handler' => 'views_handler_argument_stockprop_id',
  170. ),
  171. );
  172. //Calculated Field: stock properties (ALL)
  173. // uses a custom field handler which pulls results from the view
  174. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  175. $data['stock']['all_properties'] = array(
  176. 'title' => t('All Stock Properties'),
  177. 'help' => t('Properties of the current stock.'),
  178. 'field' => array(
  179. 'title' => t('All Properties'),
  180. 'help' => t('Display all properties associated with a stock.'),
  181. 'handler' => 'views_handler_field_stockprop_all',
  182. ),
  183. );
  184. //Calculated Field: stock relationships
  185. // uses a custom field handler which pulls results from the view
  186. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  187. $data['stock']['relationships'] = array(
  188. 'title' => t('Stock Relationships'),
  189. 'help' => t('Relationships including the current stock.'),
  190. 'field' => array(
  191. 'title' => t('Relationships'),
  192. 'help' => t('Display a given type of relationships including the current stock.'),
  193. 'handler' => 'views_handler_field_stockrel_by_type',
  194. ),
  195. );
  196. //Calculated Field: stock relationships (ALL)
  197. // uses a custom field handler which pulls results from the view
  198. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  199. $data['stock']['all_relationships'] = array(
  200. 'title' => t('All Stock Relationships'),
  201. 'help' => t('Relationships including the current stock.'),
  202. 'field' => array(
  203. 'title' => t('All Relationships'),
  204. 'help' => t('Display all relationships including the stock.'),
  205. 'handler' => 'views_handler_field_stockrel_all',
  206. ),
  207. );
  208. //Calculated Field: stock dbxrefs
  209. // uses a custom field handler which pulls results from the view
  210. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  211. $data['stock']['dbxref'] = array(
  212. 'title' => t('Stock Database References'),
  213. 'help' => t('Database References associated with the current stock.'),
  214. 'field' => array(
  215. 'title' => t('Database References'),
  216. 'help' => t('Display database references from a given database for the current stock.'),
  217. 'handler' => 'views_handler_field_stock_dbxref_by_type',
  218. ),
  219. );
  220. //Calculated Field: stock dbxrefs (ALL)
  221. // uses a custom field handler which pulls results from the view
  222. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  223. $data['stock']['all_dbxref'] = array(
  224. 'title' => t('All Stock Database References'),
  225. 'help' => t('Database References associated with the current stock.'),
  226. 'field' => array(
  227. 'title' => t('All Database References'),
  228. 'help' => t('Display all database references for the current stock.'),
  229. 'handler' => 'views_handler_field_stock_dbxref_all',
  230. ),
  231. );
  232. return $data;
  233. }