library.views.inc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. // Field: Unique name (text)
  118. $data['library']['uniquename'] = array(
  119. 'title' => 'Unique Name',
  120. 'help' => 'The unique name of the current library.',
  121. 'field' => array(
  122. 'handler' => 'views_handler_field',
  123. 'click sortable' => TRUE,
  124. ),
  125. 'filter' => array(
  126. 'handler' => 'views_handler_filter_string',
  127. ),
  128. 'argument' => array(
  129. 'handler' => 'views_handler_argument_string',
  130. ),
  131. );
  132. // Field: Is obsolete (integer 0/1)
  133. $data['library']['is_obsolete'] = array(
  134. 'title' => t('Is Obsolete?'),
  135. 'help' => t('Indicates whether a given library is obsolete or not.'),
  136. 'field' => array(
  137. 'handler' => 'views_handler_field_boolean',
  138. 'click sortable' => TRUE,
  139. ),
  140. 'filter' => array(
  141. 'handler' => 'views_handler_filter_boolean_operator',
  142. 'label' => t('Is Obsolete?'),
  143. 'type' => 'yes-no',
  144. ),
  145. 'sort' => array(
  146. 'handler' => 'views_handler_sort',
  147. ),
  148. );
  149. // Field: time accessioned (datetime)
  150. $data['library']['timeaccessioned'] = array(
  151. 'title' => t('Date Accessioned'),
  152. 'help' => t('Indicates the date a given library was accessioned (entered into the database).'),
  153. 'field' => array(
  154. 'handler' => 'views_handler_field_readable_date',
  155. 'click sortable' => TRUE,
  156. ),
  157. 'sort' => array(
  158. 'handler' => 'views_handler_sort_date',
  159. ),
  160. );
  161. // Field: time last modified (datetime)
  162. $data['library']['timelastmodified'] = array(
  163. 'title' => t('Date Last Modified'),
  164. 'help' => t('Indicates the date that a given library was last modified.'),
  165. 'field' => array(
  166. 'handler' => 'views_handler_field_readable_date',
  167. 'click sortable' => TRUE,
  168. ),
  169. 'sort' => array(
  170. 'handler' => 'views_handler_sort_date',
  171. ),
  172. );
  173. return $data;
  174. }