feature.views.inc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. //Relationship Definitions---------------------------------
  55. //Join: feature => nd_reagent
  56. $data['feature']['table']['join']['nd_reagent'] = array(
  57. 'left_field' => 'feature_id',
  58. 'field' => 'feature_id',
  59. );
  60. // Table Field Definitions----------------------
  61. // Field: feature_id (primary key)
  62. $data['feature']['feature_id'] = array(
  63. 'title' => 'Feature ID',
  64. 'help' => 'The primary key of a feature',
  65. 'field' => array(
  66. 'handler' => 'views_handler_field_numeric',
  67. 'click sortable' => TRUE,
  68. ),
  69. 'filter' => array(
  70. 'handler' => 'views_handler_filter_numeric',
  71. ),
  72. 'sort' => array(
  73. 'handler' => 'views_handler_sort',
  74. ),
  75. );
  76. // Calculated Field: Node ID
  77. // use custom field handler to query drupal for the node ID
  78. // this is only needed if chado is in a separate database from drupal
  79. if($database){
  80. $data['feature']['feature_nid'] = array(
  81. 'title' => 'Node ID',
  82. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  83. 'field' => array(
  84. 'handler' => 'views_handler_field_computed_feature_nid',
  85. ),
  86. );
  87. }
  88. // Field: organism_id (forgeign key)
  89. // join between organism table and this one in tripal_organism/views/organism.views.inc
  90. // Field: dbxref_id (forgeign key)
  91. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  92. // Field: type_id (forgeign key)
  93. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  94. // Field: name (varchar 255)
  95. $data['feature']['name'] = array(
  96. 'title' => 'Name',
  97. 'help' => 'The human-readable, non-unique name of a feature.',
  98. 'field' => array(
  99. 'handler' => 'views_handler_field',
  100. 'click sortable' => TRUE,
  101. ),
  102. 'sort' => array(
  103. 'handler' => 'views_handler_sort',
  104. ),
  105. 'filter' => array(
  106. 'handler' => 'views_handler_filter_string',
  107. ),
  108. 'argument' => array(
  109. 'handler' => 'views_handler_argument_string',
  110. ),
  111. );
  112. // if joined to the node table add a "Link to Node" option for the field
  113. if (!$database) {
  114. $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
  115. }
  116. // Field: unique name (text)
  117. $data['feature']['uniquename'] = array(
  118. 'title' => 'Unique Name',
  119. 'help' => 'The unique name of a feature.',
  120. 'field' => array(
  121. 'handler' => 'views_handler_field',
  122. 'click sortable' => TRUE,
  123. ),
  124. 'sort' => array(
  125. 'handler' => 'views_handler_sort',
  126. ),
  127. 'filter' => array(
  128. 'handler' => 'views_handler_filter_string',
  129. ),
  130. 'argument' => array(
  131. 'handler' => 'views_handler_argument_string',
  132. ),
  133. );
  134. // if joined to the node table add a "Link to Node" option for the field
  135. if (!$database) {
  136. $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  137. }
  138. // Field: residues (text)
  139. $data['feature']['residues'] = array(
  140. 'title' => 'Residues',
  141. 'help' => 'The sequence of a feature.',
  142. 'field' => array(
  143. 'handler' => 'views_handler_field_residues',
  144. 'click sortable' => TRUE,
  145. ),
  146. 'sort' => array(
  147. 'handler' => 'views_handler_sort',
  148. ),
  149. 'filter' => array(
  150. 'handler' => 'views_handler_filter_string',
  151. ),
  152. 'argument' => array(
  153. 'handler' => 'views_handler_argument_string',
  154. ),
  155. );
  156. // Field: sequence length (integer)
  157. $data['feature']['seqlen'] = array(
  158. 'title' => 'Sequence Length',
  159. 'help' => 'The length of the sequence',
  160. 'field' => array(
  161. 'handler' => 'views_handler_field_numeric',
  162. 'click sortable' => TRUE,
  163. ),
  164. 'filter' => array(
  165. 'handler' => 'views_handler_filter_numeric',
  166. ),
  167. 'sort' => array(
  168. 'handler' => 'views_handler_sort',
  169. ),
  170. );
  171. // Field: is analysis (boolean -t/f)
  172. $data['feature']['is_analysis'] = array(
  173. 'title' => 'Is Analysis',
  174. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  175. 'field' => array(
  176. 'handler' => 'views_handler_field_chado_tf_boolean',
  177. 'click sortable' => TRUE,
  178. 'label' => t('Is Analysis?'),
  179. 'type' => 'yes-no',
  180. ),
  181. 'filter' => array(
  182. 'handler' => 'views_handler_filter_chado_boolean',
  183. 'label' => t('Is Analysis?'),
  184. 'type' => 'yes-no',
  185. ),
  186. 'sort' => array(
  187. 'handler' => 'views_handler_sort',
  188. ),
  189. );
  190. // Field: is obsolete (boolean -t/f)
  191. $data['feature']['is_obsolete'] = array(
  192. 'title' => 'Is Obsolete',
  193. 'help' => 'A boolean indicating whether this feature is obsolete.',
  194. 'field' => array(
  195. 'handler' => 'views_handler_field_chado_tf_boolean',
  196. 'click sortable' => TRUE,
  197. 'label' => t('Is Obsolete?'),
  198. 'type' => 'yes-no',
  199. ),
  200. 'filter' => array(
  201. 'handler' => 'views_handler_filter_chado_boolean',
  202. 'label' => t('Is Obsolete?'),
  203. 'type' => 'yes-no',
  204. ),
  205. 'sort' => array(
  206. 'handler' => 'views_handler_sort',
  207. ),
  208. );
  209. // Field: time accessioned (datetime)
  210. $data['feature']['timeaccessioned'] = array(
  211. 'title' => 'Time Accessioned',
  212. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  213. 'field' => array(
  214. 'handler' => 'views_handler_field_readable_date',
  215. 'click sortable' => TRUE,
  216. ),
  217. 'sort' => array(
  218. 'handler' => 'views_handler_sort_date',
  219. ),
  220. );
  221. // Field: time last modified (datetime)
  222. $data['feature']['timelastmodified'] = array(
  223. 'title' => 'Time Last Modified',
  224. 'help' => 'The date & time when this feature was last modified.',
  225. 'field' => array(
  226. 'handler' => 'views_handler_field_readable_date',
  227. 'click sortable' => TRUE,
  228. ),
  229. 'sort' => array(
  230. 'handler' => 'views_handler_sort_date',
  231. ),
  232. );
  233. // Calculated Field: Number of Analysis' (Count -Int)
  234. // Provides the number of analysis' for a given feature
  235. // @see tripal_analysis/views/misc_tables.views.inc
  236. //Calculated Field: Number of Libraries (Count -Int)
  237. // Provides the number of libraries for a given feature
  238. // @see tripal_library/views/misc_tables.views.inc
  239. return $data;
  240. }