stock.views.inc 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_views
  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. } else {
  86. // Add relationship between chado_stock and stock
  87. $data['stock']['stock_nid'] = array(
  88. 'group' => 'Stock',
  89. 'title' => 'Stock Node',
  90. 'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
  91. 'real field' => 'stock_id',
  92. 'relationship' => array(
  93. 'handler' => 'views_handler_relationship',
  94. 'title' => t('Stock => Chado'),
  95. 'label' => t('Stock => Chado'),
  96. 'real field' => 'stock_id',
  97. 'base' => 'chado_stock',
  98. 'base field' => 'stock_id'
  99. ),
  100. );
  101. }
  102. //Field: unique name (text)
  103. $data['stock']['uniquename'] = array(
  104. 'title' => t('Unique Name'),
  105. 'help' => t('A unique name for 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. // if joined to the node table add a "Link to Node" option for the field
  121. if (!$database) {
  122. $data['stock']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  123. }
  124. //Field: name (varchar 255)
  125. $data['stock']['name'] = array(
  126. 'title' => t('Name'),
  127. 'help' => t('The human-readable name of this stock.'),
  128. 'field' => array(
  129. 'handler' => 'views_handler_field',
  130. 'click sortable' => TRUE,
  131. ),
  132. 'sort' => array(
  133. 'handler' => 'views_handler_sort',
  134. ),
  135. 'filter' => array(
  136. 'handler' => 'views_handler_filter_string',
  137. ),
  138. 'argument' => array(
  139. 'handler' => 'views_handler_argument_string',
  140. ),
  141. );
  142. // if joined to the node table add a "Link to Node" option for the field
  143. if (!$database) {
  144. $data['stock']['name']['field']['handler'] = 'views_handler_field_node_optional';
  145. }
  146. //Field: description (varchar 255)
  147. $data['stock']['description'] = array(
  148. 'title' => t('Description'),
  149. 'help' => t('Provides a short description for a given stock.'),
  150. 'field' => array(
  151. 'handler' => 'views_handler_field',
  152. 'click sortable' => TRUE,
  153. ),
  154. 'sort' => array(
  155. 'handler' => 'views_handler_sort',
  156. ),
  157. 'filter' => array(
  158. 'handler' => 'views_handler_filter_string',
  159. ),
  160. 'argument' => array(
  161. 'handler' => 'views_handler_argument_string',
  162. ),
  163. );
  164. //Field: is_obsolete (boolean t/f)
  165. $data['stock']['is_obsolete'] = array(
  166. 'title' => t('Is Obsolete?'),
  167. 'help' => t('A yes/no field indicating whether a given stock is obsolete or not.'),
  168. 'field' => array(
  169. 'handler' => 'views_handler_field_chado_tf_boolean',
  170. 'click sortable' => TRUE,
  171. ),
  172. 'filter' => array(
  173. 'handler' => 'views_handler_filter_chado_boolean',
  174. 'label' => t('Is Obsolete?'),
  175. 'type' => 'yes-no',
  176. ),
  177. 'sort' => array(
  178. 'handler' => 'views_handler_sort',
  179. ),
  180. );
  181. //Calculated Field: stock properties
  182. // uses a custom field handler which pulls results from the view
  183. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  184. $data['stock']['properties'] = array(
  185. 'title' => t('Stock Properties'),
  186. 'help' => t('Properties of the current stock.'),
  187. 'field' => array(
  188. 'title' => t('Properties'),
  189. 'help' => t('Display a given type of properties associated with a stock.'),
  190. 'handler' => 'views_handler_field_stockprop_by_type',
  191. ),
  192. 'filter' => array(
  193. 'title' => t('Properties'),
  194. 'help' => t('Filter by a given property type or value.'),
  195. 'handler' => 'views_handler_filter_stockprop_id',
  196. ),
  197. 'argument' => array(
  198. 'title' => t('Properties'),
  199. 'help' => t('Allow a property to be supplied in the path'),
  200. 'handler' => 'views_handler_argument_stockprop_id',
  201. ),
  202. );
  203. //Calculated Field: stock properties (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_properties'] = array(
  207. 'title' => t('All Stock Properties'),
  208. 'help' => t('Properties of the current stock.'),
  209. 'field' => array(
  210. 'title' => t('All Properties'),
  211. 'help' => t('Display all properties associated with a stock.'),
  212. 'handler' => 'views_handler_field_stockprop_all',
  213. ),
  214. );
  215. //Calculated Field: stock relationships
  216. // uses a custom field handler which pulls results from the view
  217. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  218. $data['stock']['relationships'] = array(
  219. 'title' => t('Stock Relationships'),
  220. 'help' => t('Relationships including the current stock.'),
  221. 'field' => array(
  222. 'title' => t('Relationships'),
  223. 'help' => t('Display a given type of relationships including the current stock.'),
  224. 'handler' => 'views_handler_field_stockrel_by_type',
  225. ),
  226. 'filter' => array(
  227. 'handler' => 'views_handler_filter_stock_relationship_id'
  228. ),
  229. );
  230. //Calculated Field: stock relationships (ALL)
  231. // uses a custom field handler which pulls results from the view
  232. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  233. $data['stock']['all_relationships'] = array(
  234. 'title' => t('All Stock Relationships'),
  235. 'help' => t('Relationships including the current stock.'),
  236. 'field' => array(
  237. 'title' => t('All Relationships'),
  238. 'help' => t('Display all relationships including the stock.'),
  239. 'handler' => 'views_handler_field_stockrel_all',
  240. ),
  241. );
  242. //Calculated Field: stock dbxrefs
  243. // uses a custom field handler which pulls results from the view
  244. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  245. $data['stock']['dbxref'] = array(
  246. 'title' => t('Stock Database References'),
  247. 'help' => t('Database References associated with the current stock.'),
  248. 'field' => array(
  249. 'title' => t('Database References'),
  250. 'help' => t('Display database references from a given database for the current stock.'),
  251. 'handler' => 'views_handler_field_stock_dbxref_by_type',
  252. ),
  253. 'filter' => array(
  254. 'title' => t('Database References'),
  255. 'help' => t('Filter by a given database reference type and/or value.'),
  256. 'handler' => 'views_handler_filter_stock_dbxref_id',
  257. ),
  258. );
  259. //Calculated Field: stock dbxrefs (ALL)
  260. // uses a custom field handler which pulls results from the view
  261. // actual query performed in chado_stock_views_views_pre_render (&$view) -file:tripal_stock.views.inc
  262. $data['stock']['all_dbxref'] = array(
  263. 'title' => t('All Stock Database References'),
  264. 'help' => t('Database References associated with the current stock.'),
  265. 'field' => array(
  266. 'title' => t('All Database References'),
  267. 'help' => t('Display all database references for the current stock.'),
  268. 'handler' => 'views_handler_field_stock_dbxref_all',
  269. ),
  270. );
  271. return $data;
  272. }