stock.views.inc 9.3 KB

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