template.table_defn.views.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /*************************************************************************
  3. * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
  4. *
  5. * - Every instance of XXX should be replaced with the name of your table
  6. * - If this is a base table (you want a view where every row is a row from this table)
  7. * then change $data['XXX']['table'] to $data['XXX']['table']['base']
  8. * and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
  9. * - Relationships between this table and others: YYY is the table you are trying to join to this
  10. * one. You want to join a table to this one if this table contains a foreign key to the other
  11. * table. If the join between this table and another is through a linking table
  12. * (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
  13. * directions (ie: in the file XXX.views.inc and the file YYY.views.inc
  14. * - Create a field definition for each field in this table using the example fields already
  15. * listed. Match the type of the database field to the field definition listed below.
  16. * (ie: for a text/varchar field from the database use plain_text_field below)
  17. *
  18. * NOTE: Creating the table definition file is not enough. You also need to call the
  19. * retrieve_XXX_views_data() function from ../tripal_cv.views.inc:tripal_cv_views_data()
  20. * by adding the following line:
  21. * $data = array_merge($data, retrieve_XXX_views_data());
  22. * to the function and including the file directly above the function (blow the function
  23. * header by adding:
  24. * require_once('views/XXX.views.inc');
  25. *
  26. * REMOVE THIS COMMENT IN THE COPY!
  27. */
  28. /**
  29. * @file
  30. * This file defines the data array for a given chado table. This array
  31. * is merged into a larger array containing definitions of all tables associated
  32. * with this module in:
  33. * @see tripal_cv.views.inc --in tripal_cv_views_data()
  34. *
  35. * Documentation on views integration can be found at
  36. * http://views2.logrus.com/doc/html/index.html.
  37. */
  38. /*************************************************************************
  39. * Purpose: this function returns the portion of the data array
  40. * which describes the XXX table, it's fields and any joins between it and other tables
  41. * @see tripal_cv_views_data() --in tripal_cv.views.inc
  42. *
  43. * Table: XXX
  44. * @code
  45. * XXX-Copy/Paste Table SQL code here-XXX
  46. * @endcode
  47. */
  48. function retrieve_XXX_views_data() {
  49. global $db_url;
  50. $data = array();
  51. // if the chado database is not local to the drupal database
  52. // then we need to set the database name. This should always
  53. // be 'chado'.
  54. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  55. $database = 'chado';
  56. }
  57. //Basic table definition-----------------------------------
  58. $data['XXX']['table']['group'] = t('Chado XXX');
  59. $data['XXX']['table'] = array(
  60. 'field' => 'primary_id',
  61. 'title' => t('Chado XXX'),
  62. 'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
  63. );
  64. if($database){
  65. $data['XXX']['table']['database'] = $database;
  66. }
  67. //Relationship Definitions---------------------------------
  68. //Join: XXX => YYY
  69. $data['XXX']['table']['join']['YYY'] = array(
  70. 'left_field' => 'primary key in YYY table',
  71. 'field' => 'foreign key in XXX table',
  72. );
  73. //Join: XXX => XY => YYY
  74. $data['XXX']['table']['join']['XY'] = array(
  75. 'left_field' => 'matching XXX key in the XY table',
  76. 'field' => 'foreign key in XXX table',
  77. );
  78. $data['XXX']['table']['join']['YYY'] => array(
  79. 'left_table' => 'XY',
  80. 'left_field' => 'matching XXX key in the XY table',
  81. 'field' => 'foreign key in XXX table',
  82. );
  83. $data['XY']['table']['join']['YYY'] = array(
  84. 'left_field' => 'foreign key in YYY table',
  85. 'field' => 'matching YYY key in the XY table',
  86. );
  87. //Table Field Definitions----------------------------------
  88. //Field: XXX_id (primary key)
  89. $data['XXX']['field_name'] = array(
  90. 'title' => t('XXX Primary Key'),
  91. 'help' => t('A unique index for every XXX.'),
  92. 'field' => array(
  93. 'handler' => 'views_handler_field_numeric',
  94. 'click sortable' => TRUE,
  95. ),
  96. 'sort' => array(
  97. 'handler' => 'views_handler_sort',
  98. ),
  99. 'filter' => array(
  100. 'handler' => 'views_handler_filter_numeric',
  101. ),
  102. );
  103. /*.......................................................
  104. * Beginning of Example Field definitions
  105. * Remove this section when done
  106. */
  107. //Field: plain_text_field (chado datatype)
  108. $data['XXX']['plain_text_field'] = array(
  109. 'title' => t('Human-Readable Name'),
  110. 'help' => t('Description of this field.'),
  111. 'field' => array(
  112. 'handler' => 'views_handler_field',
  113. 'click sortable' => TRUE,
  114. ),
  115. 'sort' => array(
  116. 'handler' => 'views_handler_sort',
  117. ),
  118. 'filter' => array(
  119. 'handler' => 'views_handler_filter_string',
  120. ),
  121. 'argument' => array(
  122. 'handler' => 'views_handler_argument_string',
  123. ),
  124. );
  125. //Field: numeric_field (chado datatype)
  126. $data['XXX']['numeric_field'] = array(
  127. 'title' => t('Human-Readable Name'),
  128. 'help' => t('Description of this field.'),
  129. 'field' => array(
  130. 'handler' => 'views_handler_field_numeric',
  131. 'click sortable' => TRUE,
  132. ),
  133. 'sort' => array(
  134. 'handler' => 'views_handler_sort',
  135. ),
  136. 'filter' => array(
  137. 'handler' => 'views_handler_filter_numeric',
  138. ),
  139. );
  140. //Field: boolean_field (chado datatype)
  141. $data['XXX']['boolean_field'] = array(
  142. 'title' => t('Human-Readable Name'),
  143. 'help' => t('Description of this field.'),
  144. 'field' => array(
  145. 'handler' => 'views_handler_field_boolean',
  146. 'click sortable' => TRUE,
  147. ),
  148. 'sort' => array(
  149. 'handler' => 'views_handler_sort',
  150. ),
  151. 'filter' => array(
  152. 'handler' => 'views_handler_filter_boolean_operator',
  153. ),
  154. );
  155. //Field: unix_timestamp (chado datatype)
  156. $data['XXX']['unix_timestamp'] = array(
  157. 'title' => t('Human-Readable Name'),
  158. 'help' => t('Description of this field.'),
  159. 'field' => array(
  160. 'handler' => 'views_handler_field_date',
  161. 'click sortable' => TRUE,
  162. ),
  163. 'sort' => array(
  164. 'handler' => 'views_handler_sort_date',
  165. ),
  166. 'filter' => array(
  167. 'handler' => 'views_handler_filter_date',
  168. ),
  169. );
  170. //Field: human_readable_date (chado datatype)
  171. $data['XXX']['human_readable_date'] = array(
  172. 'title' => t('Human-Readable Name'),
  173. 'help' => t('Description of this field.'),
  174. 'field' => array(
  175. 'handler' => 'views_handler_field_readble_date',
  176. 'click sortable' => TRUE,
  177. ),
  178. 'sort' => array(
  179. 'handler' => 'views_handler_sort_date',
  180. ),
  181. );
  182. /*
  183. * End of Example Field definitions
  184. *......................................................./
  185. return $data;
  186. }