stock.views.inc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. 'filter' => array(
  155. 'handler' => 'views_handler_filter_chado_boolean',
  156. 'label' => t('Is Obsolete?'),
  157. 'type' => 'yes-no',
  158. ),
  159. 'sort' => array(
  160. 'handler' => 'views_handler_sort',
  161. ),
  162. );
  163. //Calculated Field: stock properties
  164. // uses a custom field handler which pulls results from the view
  165. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  166. $data['stock']['properties'] = array(
  167. 'title' => t('Stock Properties'),
  168. 'help' => t('Properties of the current stock.'),
  169. 'field' => array(
  170. 'title' => t('Properties'),
  171. 'help' => t('Display a given type of properties associated with a stock.'),
  172. 'handler' => 'views_handler_field_stockprop_by_type',
  173. ),
  174. 'filter' => array(
  175. 'title' => t('Properties'),
  176. 'help' => t('Filter by a given property type or value.'),
  177. 'handler' => 'views_handler_filter_stockprop_id',
  178. ),
  179. 'argument' => array(
  180. 'title' => t('Properties'),
  181. 'help' => t('Allow a property to be supplied in the path'),
  182. 'handler' => 'views_handler_argument_stockprop_id',
  183. ),
  184. );
  185. //Calculated Field: stock properties (ALL)
  186. // uses a custom field handler which pulls results from the view
  187. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  188. $data['stock']['all_properties'] = array(
  189. 'title' => t('All Stock Properties'),
  190. 'help' => t('Properties of the current stock.'),
  191. 'field' => array(
  192. 'title' => t('All Properties'),
  193. 'help' => t('Display all properties associated with a stock.'),
  194. 'handler' => 'views_handler_field_stockprop_all',
  195. ),
  196. );
  197. //Calculated Field: stock relationships
  198. // uses a custom field handler which pulls results from the view
  199. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  200. $data['stock']['relationships'] = array(
  201. 'title' => t('Stock Relationships'),
  202. 'help' => t('Relationships including the current stock.'),
  203. 'field' => array(
  204. 'title' => t('Relationships'),
  205. 'help' => t('Display a given type of relationships including the current stock.'),
  206. 'handler' => 'views_handler_field_stockrel_by_type',
  207. ),
  208. );
  209. //Calculated Field: stock relationships (ALL)
  210. // uses a custom field handler which pulls results from the view
  211. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  212. $data['stock']['all_relationships'] = array(
  213. 'title' => t('All Stock Relationships'),
  214. 'help' => t('Relationships including the current stock.'),
  215. 'field' => array(
  216. 'title' => t('All Relationships'),
  217. 'help' => t('Display all relationships including the stock.'),
  218. 'handler' => 'views_handler_field_stockrel_all',
  219. ),
  220. );
  221. //Calculated Field: stock dbxrefs
  222. // uses a custom field handler which pulls results from the view
  223. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  224. $data['stock']['dbxref'] = array(
  225. 'title' => t('Stock Database References'),
  226. 'help' => t('Database References associated with the current stock.'),
  227. 'field' => array(
  228. 'title' => t('Database References'),
  229. 'help' => t('Display database references from a given database for the current stock.'),
  230. 'handler' => 'views_handler_field_stock_dbxref_by_type',
  231. ),
  232. 'filter' => array(
  233. 'title' => t('Database References'),
  234. 'help' => t('Filter by a given database reference type and/or value.'),
  235. 'handler' => 'views_handler_filter_stock_dbxref_id',
  236. ),
  237. );
  238. //Calculated Field: stock dbxrefs (ALL)
  239. // uses a custom field handler which pulls results from the view
  240. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  241. $data['stock']['all_dbxref'] = array(
  242. 'title' => t('All Stock Database References'),
  243. 'help' => t('Database References associated with the current stock.'),
  244. 'field' => array(
  245. 'title' => t('All Database References'),
  246. 'help' => t('Display all database references for the current stock.'),
  247. 'handler' => 'views_handler_field_stock_dbxref_all',
  248. ),
  249. );
  250. return $data;
  251. }