feature.views.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the feature table, it's fields and any joins between it and other tables
  5. * @see tripal_feature_views_data() --in tripal_feature.views.inc
  6. *
  7. * @todo Add better handler for is_analysis, is_obsolete: something which changes the t/f to a true boolean
  8. * @todo Add support for the following tables: featureprop, featureloc, featurepos, feature_synonym, feature_relationship
  9. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  10. *
  11. * BASE TABLE: feature
  12. * @code
  13. * create table feature (
  14. * feature_id serial not null,
  15. * primary key (feature_id),
  16. * dbxref_id int,
  17. * foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
  18. * organism_id int not null,
  19. * foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
  20. * name varchar(255),
  21. * uniquename text not null,
  22. * residues text,
  23. * seqlen int,
  24. * md5checksum char(32),
  25. * type_id int not null,
  26. * foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
  27. * is_analysis boolean not null default 'false',
  28. * is_obsolete boolean not null default 'false',
  29. * timeaccessioned timestamp not null default current_timestamp,
  30. * timelastmodified timestamp not null default current_timestamp,
  31. * constraint feature_c1 unique (organism_id,uniquename,type_id)
  32. * );
  33. * @endcode
  34. */
  35. function retrieve_feature_views_data() {
  36. global $db_url;
  37. $data = array();
  38. // if the chado database is not local to the drupal database
  39. // then we need to set the database name. This should always
  40. // be 'chado'.
  41. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  42. $database = 'chado';
  43. }
  44. // Basic table definition
  45. $data['feature']['table']['group'] = 'Chado Feature';
  46. $data['feature']['table']['base'] = array(
  47. 'field' => 'feature_id',
  48. 'title' => 'Chado Features',
  49. 'help' => 'Features are Sequence Data Records in Chado.',
  50. );
  51. if($database){
  52. $data['feature']['table']['database'] = $database;
  53. }
  54. // Table Field Definitions----------------------
  55. // Field: feature_id (primary key)
  56. $data['feature']['feature_id'] = array(
  57. 'title' => 'Feature ID',
  58. 'help' => 'The primary key of a feature',
  59. 'field' => array(
  60. 'handler' => 'views_handler_field_numeric',
  61. 'click sortable' => TRUE,
  62. ),
  63. 'filter' => array(
  64. 'handler' => 'views_handler_filter_numeric',
  65. ),
  66. 'sort' => array(
  67. 'handler' => 'views_handler_sort',
  68. ),
  69. );
  70. // Calculated Field: Node ID
  71. // use custom field handler to query drupal for the node ID
  72. // this is only needed if chado is in a separate database from drupal
  73. if($database){
  74. $data['feature']['feature_nid'] = array(
  75. 'title' => 'Node ID',
  76. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  77. 'field' => array(
  78. 'handler' => 'views_handler_field_computed_feature_nid',
  79. ),
  80. );
  81. }
  82. // Field: organism_id (forgeign key)
  83. // join between organism table and this one in tripal_organism/views/organism.views.inc
  84. // Field: dbxref_id (forgeign key)
  85. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  86. // Field: type_id (forgeign key)
  87. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  88. // Field: name (varchar 255)
  89. $data['feature']['name'] = array(
  90. 'title' => 'Name',
  91. 'help' => 'The human-readable, non-unique name of a feature.',
  92. 'field' => array(
  93. 'handler' => 'views_handler_field',
  94. 'click sortable' => TRUE,
  95. ),
  96. 'sort' => array(
  97. 'handler' => 'views_handler_sort',
  98. ),
  99. 'filter' => array(
  100. 'handler' => 'views_handler_filter_string',
  101. ),
  102. 'argument' => array(
  103. 'handler' => 'views_handler_argument_string',
  104. ),
  105. );
  106. // if joined to the node table add a "Link to Node" option for the field
  107. if (!$database) {
  108. $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
  109. }
  110. // Field: unique name (text)
  111. $data['feature']['uniquename'] = array(
  112. 'title' => 'Unique Name',
  113. 'help' => 'The unique name of a feature.',
  114. 'field' => array(
  115. 'handler' => 'views_handler_field',
  116. 'click sortable' => TRUE,
  117. ),
  118. 'sort' => array(
  119. 'handler' => 'views_handler_sort',
  120. ),
  121. 'filter' => array(
  122. 'handler' => 'views_handler_filter_string',
  123. ),
  124. 'argument' => array(
  125. 'handler' => 'views_handler_argument_string',
  126. ),
  127. );
  128. // if joined to the node table add a "Link to Node" option for the field
  129. if (!$database) {
  130. $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  131. }
  132. // Field: residues (text)
  133. $data['feature']['residues'] = array(
  134. 'title' => 'Residues',
  135. 'help' => 'The sequence of a feature.',
  136. 'field' => array(
  137. 'handler' => 'views_handler_field',
  138. 'click sortable' => TRUE,
  139. ),
  140. 'sort' => array(
  141. 'handler' => 'views_handler_sort',
  142. ),
  143. 'filter' => array(
  144. 'handler' => 'views_handler_filter_string',
  145. ),
  146. 'argument' => array(
  147. 'handler' => 'views_handler_argument_string',
  148. ),
  149. );
  150. // Field: sequence length (integer)
  151. $data['feature']['seqlen'] = array(
  152. 'title' => 'Sequence Length',
  153. 'help' => 'The length of the sequence',
  154. 'field' => array(
  155. 'handler' => 'views_handler_field_numeric',
  156. 'click sortable' => TRUE,
  157. ),
  158. 'filter' => array(
  159. 'handler' => 'views_handler_filter_numeric',
  160. ),
  161. 'sort' => array(
  162. 'handler' => 'views_handler_sort',
  163. ),
  164. );
  165. // Field: is analysis (boolean -t/f)
  166. $data['feature']['is_analysis'] = array(
  167. 'title' => 'Is Analysis',
  168. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  169. 'field' => array(
  170. 'handler' => 'views_handler_field',
  171. 'click sortable' => TRUE,
  172. ),
  173. 'filter' => array(
  174. 'handler' => 'views_handler_filter',
  175. ),
  176. 'sort' => array(
  177. 'handler' => 'views_handler_sort',
  178. ),
  179. );
  180. // Field: is obsolete (boolean -t/f)
  181. $data['feature']['is_obsolete'] = array(
  182. 'title' => 'Is Obsolete',
  183. 'help' => 'A boolean indicating whether this feature is obsolete.',
  184. 'field' => array(
  185. 'handler' => 'views_handler_field',
  186. 'click sortable' => TRUE,
  187. ),
  188. 'filter' => array(
  189. 'handler' => 'views_handler_filter',
  190. ),
  191. 'sort' => array(
  192. 'handler' => 'views_handler_sort',
  193. ),
  194. );
  195. // Field: time accessioned (datetime)
  196. $data['feature']['timeaccessioned'] = array(
  197. 'title' => 'Time Accessioned',
  198. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  199. 'field' => array(
  200. 'handler' => 'views_handler_field_readable_date',
  201. 'click sortable' => TRUE,
  202. ),
  203. 'sort' => array(
  204. 'handler' => 'views_handler_sort_date',
  205. ),
  206. );
  207. // Field: time last modified (datetime)
  208. $data['feature']['timelastmodified'] = array(
  209. 'title' => 'Time Last Modified',
  210. 'help' => 'The date & time when this feature was last modified.',
  211. 'field' => array(
  212. 'handler' => 'views_handler_field_readable_date',
  213. 'click sortable' => TRUE,
  214. ),
  215. 'sort' => array(
  216. 'handler' => 'views_handler_sort_date',
  217. ),
  218. );
  219. return $data;
  220. }