library.views.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. }
  97. // Field: organism_id (forgeign key)
  98. // join between organism table and this one in tripal_organism/views/organism.views.inc
  99. // Field: type_id (forgeign key)
  100. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  101. // Field: Name (varchar 255)
  102. $data['library']['name'] = array(
  103. 'title' => 'Name',
  104. 'help' => 'The human-readable name of the current library.',
  105. 'field' => array(
  106. 'handler' => 'views_handler_field',
  107. 'click sortable' => TRUE,
  108. ),
  109. 'sort' => array(
  110. 'handler' => 'views_handler_sort',
  111. ),
  112. 'filter' => array(
  113. 'handler' => 'views_handler_filter_string',
  114. ),
  115. 'argument' => array(
  116. 'handler' => 'views_handler_argument_string',
  117. ),
  118. );
  119. // if joined to the node table add a "Link to Node" option for the field
  120. if (!$database) {
  121. $data['library']['name']['field']['handler'] = 'views_handler_field_node_optional';
  122. }
  123. // Field: Unique name (text)
  124. $data['library']['uniquename'] = array(
  125. 'title' => 'Unique Name',
  126. 'help' => 'The unique name of the current library.',
  127. 'field' => array(
  128. 'handler' => 'views_handler_field',
  129. 'click sortable' => TRUE,
  130. ),
  131. 'filter' => array(
  132. 'handler' => 'views_handler_filter_string',
  133. ),
  134. 'argument' => array(
  135. 'handler' => 'views_handler_argument_string',
  136. ),
  137. );
  138. // if joined to the node table add a "Link to Node" option for the field
  139. if (!$database) {
  140. $data['library']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  141. }
  142. // Field: Is obsolete (integer 0/1)
  143. $data['library']['is_obsolete'] = array(
  144. 'title' => t('Is Obsolete?'),
  145. 'help' => t('Indicates whether a given library is obsolete or not.'),
  146. 'field' => array(
  147. 'handler' => 'views_handler_field_boolean',
  148. 'click sortable' => TRUE,
  149. ),
  150. 'filter' => array(
  151. 'handler' => 'views_handler_filter_chado_boolean',
  152. 'label' => t('Is Obsolete?'),
  153. 'type' => 'yes-no',
  154. ),
  155. 'sort' => array(
  156. 'handler' => 'views_handler_sort',
  157. ),
  158. );
  159. // Field: time accessioned (datetime)
  160. $data['library']['timeaccessioned'] = array(
  161. 'title' => t('Date Accessioned'),
  162. 'help' => t('Indicates the date a given library was accessioned (entered into the database).'),
  163. 'field' => array(
  164. 'handler' => 'views_handler_field_readable_date',
  165. 'click sortable' => TRUE,
  166. ),
  167. 'sort' => array(
  168. 'handler' => 'views_handler_sort_date',
  169. ),
  170. );
  171. // Field: time last modified (datetime)
  172. $data['library']['timelastmodified'] = array(
  173. 'title' => t('Date Last Modified'),
  174. 'help' => t('Indicates the date that a given library was last modified.'),
  175. 'field' => array(
  176. 'handler' => 'views_handler_field_readable_date',
  177. 'click sortable' => TRUE,
  178. ),
  179. 'sort' => array(
  180. 'handler' => 'views_handler_sort_date',
  181. ),
  182. );
  183. return $data;
  184. }