library.views.inc 5.4 KB

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