library.views.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the library table, it's fields and any joins between it and other tables
  5. * @see tripal_library_views_data() --in tripal_library.views.inc
  6. *
  7. * @todo Add support for the following tables: library_cvterm, library_pub, library_synonym, libraryprop
  8. * @todo Add support for multiple libraries listed per feature
  9. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  10. *
  11. * BASE TABLE: library
  12. * @code
  13. * create table library (
  14. * library_id serial not null,
  15. * primary key (library_id),
  16. * organism_id int not null,
  17. * foreign key (organism_id) references organism (organism_id),
  18. * name varchar(255),
  19. * uniquename text not null,
  20. * type_id int not null,
  21. * foreign key (type_id) references cvterm (cvterm_id),
  22. * is_obsolete int not null default 0,
  23. * timeaccessioned timestamp not null default current_timestamp,
  24. * timelastmodified timestamp not null default current_timestamp,
  25. * constraint library_c1 unique (organism_id,uniquename,type_id)
  26. * );
  27. * @endcode
  28. *
  29. * @ingroup tripal_library_views
  30. */
  31. function retrieve_library_views_data() {
  32. global $db_url;
  33. $data = array();
  34. // if the chado database is not local to the drupal database
  35. // then we need to set the database name. This should always
  36. // be 'chado'.
  37. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  38. $database = 'chado';
  39. }
  40. // Basic table definition
  41. $data['library']['table']['group'] = 'Chado Library';
  42. $data['library']['table']['base'] = array(
  43. 'field' => 'library_id',
  44. 'title' => 'Chado Library',
  45. 'help' => 'Library existing in the Chado Database',
  46. );
  47. if($database){
  48. $data['library']['table']['base']['database'] = $database;
  49. }
  50. // Define relationships between this table and others
  51. $data['library']['table']['join'] = array(
  52. 'library_feature' => array(
  53. 'left_field' => 'library_id',
  54. 'field' => 'library_id',
  55. ),
  56. 'feature' => array(
  57. 'left_table' => 'library_feature',
  58. 'left_field' => 'library_id',
  59. 'field' => 'library_id',
  60. ),
  61. );
  62. // Describe the joins with the library_feature table
  63. $data['library_feature']['table']['join'] = array(
  64. 'feature' => array(
  65. 'left_field' => 'feature_id',
  66. 'field' => 'feature_id',
  67. ),
  68. );
  69. // Table Field Definitions----------------------
  70. // Field: library_id (primary key)
  71. $data['library']['library_id'] = array(
  72. 'title' => 'Library ID',
  73. 'help' => 'The primary key of the library table.',
  74. 'field' => array(
  75. 'handler' => 'views_handler_field_numeric',
  76. 'click sortable' => TRUE,
  77. ),
  78. 'filter' => array(
  79. 'handler' => 'views_handler_filter_numeric',
  80. ),
  81. 'sort' => array(
  82. 'handler' => 'views_handler_sort',
  83. ),
  84. );
  85. // Calculated Field: Node ID
  86. // use custom field handler to query drupal for the node ID
  87. // this is only needed if chado is in a separate database from drupal
  88. if($database){
  89. $data['library']['library_nid'] = array(
  90. 'title' => 'Node ID',
  91. 'help' => 'The node ID for the current library',
  92. 'field' => array(
  93. 'handler' => 'views_handler_field_computed_library_nid',
  94. ),
  95. );
  96. } else {
  97. // Add relationship between chado_library and library
  98. $data['library']['library_nid'] = array(
  99. 'group' => 'Library',
  100. 'title' => 'Library Node',
  101. 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
  102. 'real field' => 'library_id',
  103. 'relationship' => array(
  104. 'handler' => 'views_handler_relationship',
  105. 'title' => t('Library => Chado'),
  106. 'label' => t('Library => Chado'),
  107. 'real field' => 'library_id',
  108. 'base' => 'chado_library',
  109. 'base field' => 'library_id'
  110. ),
  111. );
  112. }
  113. // Field: organism_id (forgeign key)
  114. // join between organism table and this one in tripal_organism/views/organism.views.inc
  115. // Field: type_id (forgeign key)
  116. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  117. // Field: Name (varchar 255)
  118. $data['library']['name'] = array(
  119. 'title' => 'Name',
  120. 'help' => 'The human-readable name of the current library.',
  121. 'field' => array(
  122. 'handler' => 'views_handler_field',
  123. 'click sortable' => TRUE,
  124. ),
  125. 'sort' => array(
  126. 'handler' => 'views_handler_sort',
  127. ),
  128. 'filter' => array(
  129. 'handler' => 'views_handler_filter_chado_select_string',
  130. ),
  131. 'argument' => array(
  132. 'handler' => 'views_handler_argument_string',
  133. ),
  134. );
  135. // if joined to the node table add a "Link to Node" option for the field
  136. if (!$database) {
  137. $data['library']['name']['field']['handler'] = 'views_handler_field_node_optional';
  138. }
  139. // Field: Unique name (text)
  140. $data['library']['uniquename'] = array(
  141. 'title' => 'Unique Name',
  142. 'help' => 'The unique name of the current library.',
  143. 'field' => array(
  144. 'handler' => 'views_handler_field',
  145. 'click sortable' => TRUE,
  146. ),
  147. 'filter' => array(
  148. 'handler' => 'views_handler_filter_string',
  149. ),
  150. 'argument' => array(
  151. 'handler' => 'views_handler_argument_string',
  152. ),
  153. );
  154. // if joined to the node table add a "Link to Node" option for the field
  155. if (!$database) {
  156. $data['library']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  157. }
  158. // Field: Is obsolete (integer 0/1)
  159. $data['library']['is_obsolete'] = array(
  160. 'title' => t('Is Obsolete?'),
  161. 'help' => t('Indicates whether a given library is obsolete or not.'),
  162. 'field' => array(
  163. 'handler' => 'views_handler_field_boolean',
  164. 'click sortable' => TRUE,
  165. ),
  166. 'filter' => array(
  167. 'handler' => 'views_handler_filter_chado_boolean',
  168. 'label' => t('Is Obsolete?'),
  169. 'type' => 'yes-no',
  170. ),
  171. 'sort' => array(
  172. 'handler' => 'views_handler_sort',
  173. ),
  174. );
  175. // Field: time accessioned (datetime)
  176. $data['library']['timeaccessioned'] = array(
  177. 'title' => t('Date Accessioned'),
  178. 'help' => t('Indicates the date a given library was accessioned (entered into the database).'),
  179. 'field' => array(
  180. 'handler' => 'views_handler_field_readable_date',
  181. 'click sortable' => TRUE,
  182. ),
  183. 'sort' => array(
  184. 'handler' => 'views_handler_sort_date',
  185. ),
  186. );
  187. // Field: time last modified (datetime)
  188. $data['library']['timelastmodified'] = array(
  189. 'title' => t('Date Last Modified'),
  190. 'help' => t('Indicates the date that a given library was last modified.'),
  191. 'field' => array(
  192. 'handler' => 'views_handler_field_readable_date',
  193. 'click sortable' => TRUE,
  194. ),
  195. 'sort' => array(
  196. 'handler' => 'views_handler_sort_date',
  197. ),
  198. );
  199. return $data;
  200. }