library.views.inc 6.7 KB

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