stock.views.inc 10 KB

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