library.views.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. function retrieve_library_views_data() {
  30. global $db_url;
  31. $data = array();
  32. // if the chado database is not local to the drupal database
  33. // then we need to set the database name. This should always
  34. // be 'chado'.
  35. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  36. $database = 'chado';
  37. }
  38. // Basic table definition
  39. $data['library']['table']['group'] = 'Chado Library';
  40. $data['library']['table']['base'] = array(
  41. 'field' => 'library_id',
  42. 'title' => 'Chado Library',
  43. 'help' => 'Library existing in the Chado Database',
  44. );
  45. if($database){
  46. $data['library']['table']['database'] = $database;
  47. }
  48. // Define relationships between this table and others
  49. $data['library']['table']['join'] = array(
  50. 'library_feature' => array(
  51. 'left_field' => 'library_id',
  52. 'field' => 'library_id',
  53. ),
  54. 'feature' => array(
  55. 'left_table' => 'library_feature',
  56. 'left_field' => 'library_id',
  57. 'field' => 'library_id',
  58. ),
  59. );
  60. // Describe the joins with the library_feature table
  61. $data['library_feature']['table']['join'] = array(
  62. 'feature' => array(
  63. 'left_field' => 'feature_id',
  64. 'field' => 'feature_id',
  65. ),
  66. );
  67. // Table Field Definitions----------------------
  68. // Field: library_id (primary key)
  69. $data['library']['library_id'] = array(
  70. 'title' => 'Library ID',
  71. 'help' => 'The primary key of the library table.',
  72. 'field' => array(
  73. 'handler' => 'views_handler_field_numeric',
  74. 'click sortable' => TRUE,
  75. ),
  76. 'filter' => array(
  77. 'handler' => 'views_handler_filter_numeric',
  78. ),
  79. 'sort' => array(
  80. 'handler' => 'views_handler_sort',
  81. ),
  82. );
  83. // Calculated Field: Node ID
  84. // use custom field handler to query drupal for the node ID
  85. // this is only needed if chado is in a separate database from drupal
  86. if($database){
  87. $data['library']['library_nid'] = array(
  88. 'title' => 'Node ID',
  89. 'help' => 'The node ID for the current library',
  90. 'field' => array(
  91. 'handler' => 'views_handler_field_computed_library_nid',
  92. ),
  93. );
  94. }
  95. // Field: organism_id (forgeign key)
  96. // join between organism table and this one in tripal_organism/views/organism.views.inc
  97. // Field: type_id (forgeign key)
  98. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  99. // Field: Name (varchar 255)
  100. $data['library']['name'] = array(
  101. 'title' => 'Name',
  102. 'help' => 'The human-readable name of the current library.',
  103. 'field' => array(
  104. 'handler' => 'views_handler_field',
  105. 'click sortable' => TRUE,
  106. ),
  107. 'sort' => array(
  108. 'handler' => 'views_handler_sort',
  109. ),
  110. 'filter' => array(
  111. 'handler' => 'views_handler_filter_string',
  112. ),
  113. 'argument' => array(
  114. 'handler' => 'views_handler_argument_string',
  115. ),
  116. );
  117. // if joined to the node table add a "Link to Node" option for the field
  118. if (!$database) {
  119. $data['library']['name']['field']['handler'] = 'views_handler_field_node_optional';
  120. }
  121. // Field: Unique name (text)
  122. $data['library']['uniquename'] = array(
  123. 'title' => 'Unique Name',
  124. 'help' => 'The unique name of the current library.',
  125. 'field' => array(
  126. 'handler' => 'views_handler_field',
  127. 'click sortable' => TRUE,
  128. ),
  129. 'filter' => array(
  130. 'handler' => 'views_handler_filter_string',
  131. ),
  132. 'argument' => array(
  133. 'handler' => 'views_handler_argument_string',
  134. ),
  135. );
  136. // if joined to the node table add a "Link to Node" option for the field
  137. if (!$database) {
  138. $data['library']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  139. }
  140. // Field: Is obsolete (integer 0/1)
  141. $data['library']['is_obsolete'] = array(
  142. 'title' => t('Is Obsolete?'),
  143. 'help' => t('Indicates whether a given library is obsolete or not.'),
  144. 'field' => array(
  145. 'handler' => 'views_handler_field_boolean',
  146. 'click sortable' => TRUE,
  147. ),
  148. 'filter' => array(
  149. 'handler' => 'views_handler_filter_boolean_operator',
  150. 'label' => t('Is Obsolete?'),
  151. 'type' => 'yes-no',
  152. ),
  153. 'sort' => array(
  154. 'handler' => 'views_handler_sort',
  155. ),
  156. );
  157. // Field: time accessioned (datetime)
  158. $data['library']['timeaccessioned'] = array(
  159. 'title' => t('Date Accessioned'),
  160. 'help' => t('Indicates the date a given library was accessioned (entered into the database).'),
  161. 'field' => array(
  162. 'handler' => 'views_handler_field_readable_date',
  163. 'click sortable' => TRUE,
  164. ),
  165. 'sort' => array(
  166. 'handler' => 'views_handler_sort_date',
  167. ),
  168. );
  169. // Field: time last modified (datetime)
  170. $data['library']['timelastmodified'] = array(
  171. 'title' => t('Date Last Modified'),
  172. 'help' => t('Indicates the date that a given library was last modified.'),
  173. 'field' => array(
  174. 'handler' => 'views_handler_field_readable_date',
  175. 'click sortable' => TRUE,
  176. ),
  177. 'sort' => array(
  178. 'handler' => 'views_handler_sort_date',
  179. ),
  180. );
  181. return $data;
  182. }