stock.views.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. // if joined to the node table add a "Link to Node" option for the field
  103. if (!$database) {
  104. $data['stock']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  105. }
  106. //Field: name (varchar 255)
  107. $data['stock']['name'] = array(
  108. 'title' => t('Name'),
  109. 'help' => t('The human-readable name of this stock.'),
  110. 'field' => array(
  111. 'handler' => 'views_handler_field',
  112. 'click sortable' => TRUE,
  113. ),
  114. 'sort' => array(
  115. 'handler' => 'views_handler_sort',
  116. ),
  117. 'filter' => array(
  118. 'handler' => 'views_handler_filter_string',
  119. ),
  120. 'argument' => array(
  121. 'handler' => 'views_handler_argument_string',
  122. ),
  123. );
  124. // if joined to the node table add a "Link to Node" option for the field
  125. if (!$database) {
  126. $data['stock']['name']['field']['handler'] = 'views_handler_field_node_optional';
  127. }
  128. //Field: description (varchar 255)
  129. $data['stock']['description'] = array(
  130. 'title' => t('Description'),
  131. 'help' => t('Provides a short description for a given stock.'),
  132. 'field' => array(
  133. 'handler' => 'views_handler_field',
  134. 'click sortable' => TRUE,
  135. ),
  136. 'sort' => array(
  137. 'handler' => 'views_handler_sort',
  138. ),
  139. 'filter' => array(
  140. 'handler' => 'views_handler_filter_string',
  141. ),
  142. 'argument' => array(
  143. 'handler' => 'views_handler_argument_string',
  144. ),
  145. );
  146. //Field: is_obsolete (boolean t/f)
  147. $data['stock']['is_obsolete'] = array(
  148. 'title' => t('Is Obsolete'),
  149. 'help' => t('A yes/no field indicating whether a given stock is obsolete or not.'),
  150. 'field' => array(
  151. 'handler' => 'views_handler_field',
  152. 'click sortable' => TRUE,
  153. ),
  154. 'sort' => array(
  155. 'handler' => 'views_handler_sort',
  156. ),
  157. );
  158. //Calculated Field: stock properties
  159. // uses a custom field handler which pulls results from the view
  160. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  161. $data['stock']['properties'] = array(
  162. 'title' => t('Stock Properties'),
  163. 'help' => t('Properties of the current stock.'),
  164. 'field' => array(
  165. 'title' => t('Properties'),
  166. 'help' => t('Display a given type of properties associated with a stock.'),
  167. 'handler' => 'views_handler_field_stockprop_by_type',
  168. ),
  169. 'filter' => array(
  170. 'title' => t('Properties'),
  171. 'help' => t('Filter by a given property type or value.'),
  172. 'handler' => 'views_handler_filter_stockprop_id',
  173. ),
  174. 'argument' => array(
  175. 'title' => t('Properties'),
  176. 'help' => t('Allow a property to be supplied in the path'),
  177. 'handler' => 'views_handler_argument_stockprop_id',
  178. ),
  179. );
  180. //Calculated Field: stock properties (ALL)
  181. // uses a custom field handler which pulls results from the view
  182. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  183. $data['stock']['all_properties'] = array(
  184. 'title' => t('All Stock Properties'),
  185. 'help' => t('Properties of the current stock.'),
  186. 'field' => array(
  187. 'title' => t('All Properties'),
  188. 'help' => t('Display all properties associated with a stock.'),
  189. 'handler' => 'views_handler_field_stockprop_all',
  190. ),
  191. );
  192. //Calculated Field: stock relationships
  193. // uses a custom field handler which pulls results from the view
  194. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  195. $data['stock']['relationships'] = array(
  196. 'title' => t('Stock Relationships'),
  197. 'help' => t('Relationships including the current stock.'),
  198. 'field' => array(
  199. 'title' => t('Relationships'),
  200. 'help' => t('Display a given type of relationships including the current stock.'),
  201. 'handler' => 'views_handler_field_stockrel_by_type',
  202. ),
  203. );
  204. //Calculated Field: stock relationships (ALL)
  205. // uses a custom field handler which pulls results from the view
  206. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  207. $data['stock']['all_relationships'] = array(
  208. 'title' => t('All Stock Relationships'),
  209. 'help' => t('Relationships including the current stock.'),
  210. 'field' => array(
  211. 'title' => t('All Relationships'),
  212. 'help' => t('Display all relationships including the stock.'),
  213. 'handler' => 'views_handler_field_stockrel_all',
  214. ),
  215. );
  216. //Calculated Field: stock dbxrefs
  217. // uses a custom field handler which pulls results from the view
  218. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  219. $data['stock']['dbxref'] = array(
  220. 'title' => t('Stock Database References'),
  221. 'help' => t('Database References associated with the current stock.'),
  222. 'field' => array(
  223. 'title' => t('Database References'),
  224. 'help' => t('Display database references from a given database for the current stock.'),
  225. 'handler' => 'views_handler_field_stock_dbxref_by_type',
  226. ),
  227. 'filter' => array(
  228. 'title' => t('Database References'),
  229. 'help' => t('Filter by a given database reference type and/or value.'),
  230. 'handler' => 'views_handler_filter_stock_dbxref_id',
  231. ),
  232. );
  233. //Calculated Field: stock dbxrefs (ALL)
  234. // uses a custom field handler which pulls results from the view
  235. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  236. $data['stock']['all_dbxref'] = array(
  237. 'title' => t('All Stock Database References'),
  238. 'help' => t('Database References associated with the current stock.'),
  239. 'field' => array(
  240. 'title' => t('All Database References'),
  241. 'help' => t('Display all database references for the current stock.'),
  242. 'handler' => 'views_handler_field_stock_dbxref_all',
  243. ),
  244. );
  245. return $data;
  246. }