library.views.inc 5.1 KB

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