template.table_defn.views.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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_library.views.inc:tripal_library_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_library.views.inc --in tripal_library_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_library_views_data() --in tripal_library.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: YYY => XXX
  69. // Notice that this relationship tells the primary table to show it's fields to the
  70. // table referencing it by a foreign key and thus the relationship is from
  71. // primary table to table referenceing it (ie: cvterm => feature)
  72. $data['XXX']['table']['join']['YYY'] = array(
  73. 'left_field' => 'foreign key in YYY table',
  74. 'field' => 'primary key in XXX table',
  75. );
  76. //Join: XXX => XY => YYY
  77. // This relationship should be described in both directions
  78. // in the appropriate files (ie: for feature => library
  79. // describe in both feature.views.inc and library.views.inc)
  80. $data['XXX']['table']['join']['XY'] = array(
  81. 'left_field' => 'matching XXX key in the XY table',
  82. 'field' => 'primary key in XXX table',
  83. );
  84. $data['XXX']['table']['join']['YYY'] = array(
  85. 'left_table' => 'XY',
  86. 'left_field' => 'matching XXX key in the XY table',
  87. 'field' => 'primary key in XXX table',
  88. );
  89. $data['XY']['table']['join']['YYY'] = array(
  90. 'left_field' => 'primary key in YYY table',
  91. 'field' => 'matching YYY key in the XY table',
  92. );
  93. //Table Field Definitions----------------------------------
  94. //Field: XXX_id (primary key)
  95. $data['XXX']['field_name'] = array(
  96. 'title' => t('XXX Primary Key'),
  97. 'help' => t('A unique index for every XXX.'),
  98. 'field' => array(
  99. 'handler' => 'views_handler_field_numeric',
  100. 'click sortable' => TRUE,
  101. ),
  102. 'sort' => array(
  103. 'handler' => 'views_handler_sort',
  104. ),
  105. 'filter' => array(
  106. 'handler' => 'views_handler_filter_numeric',
  107. ),
  108. );
  109. /*.......................................................
  110. * Beginning of Example Field definitions
  111. * Remove this section when done
  112. */
  113. //Field: plain_text_field (chado datatype)
  114. $data['XXX']['plain_text_field'] = array(
  115. 'title' => t('Human-Readable Name'),
  116. 'help' => t('Description of this field.'),
  117. 'field' => array(
  118. 'handler' => 'views_handler_field',
  119. 'click sortable' => TRUE,
  120. ),
  121. 'sort' => array(
  122. 'handler' => 'views_handler_sort',
  123. ),
  124. 'filter' => array(
  125. 'handler' => 'views_handler_filter_string',
  126. ),
  127. 'argument' => array(
  128. 'handler' => 'views_handler_argument_string',
  129. ),
  130. );
  131. //Field: numeric_field (chado datatype)
  132. $data['XXX']['numeric_field'] = array(
  133. 'title' => t('Human-Readable Name'),
  134. 'help' => t('Description of this field.'),
  135. 'field' => array(
  136. 'handler' => 'views_handler_field_numeric',
  137. 'click sortable' => TRUE,
  138. ),
  139. 'sort' => array(
  140. 'handler' => 'views_handler_sort',
  141. ),
  142. 'filter' => array(
  143. 'handler' => 'views_handler_filter_numeric',
  144. ),
  145. );
  146. //Field: boolean_field (chado datatype)
  147. $data['XXX']['boolean_field'] = array(
  148. 'title' => t('Human-Readable Name'),
  149. 'help' => t('Description of this field.'),
  150. 'field' => array(
  151. 'handler' => 'views_handler_field_boolean',
  152. 'click sortable' => TRUE,
  153. ),
  154. 'sort' => array(
  155. 'handler' => 'views_handler_sort',
  156. ),
  157. 'filter' => array(
  158. 'handler' => 'views_handler_filter_boolean_operator',
  159. ),
  160. );
  161. //Field: unix_timestamp (chado datatype)
  162. $data['XXX']['unix_timestamp'] = array(
  163. 'title' => t('Human-Readable Name'),
  164. 'help' => t('Description of this field.'),
  165. 'field' => array(
  166. 'handler' => 'views_handler_field_date',
  167. 'click sortable' => TRUE,
  168. ),
  169. 'sort' => array(
  170. 'handler' => 'views_handler_sort_date',
  171. ),
  172. 'filter' => array(
  173. 'handler' => 'views_handler_filter_date',
  174. ),
  175. );
  176. //Field: human_readable_date (chado datatype)
  177. $data['XXX']['human_readable_date'] = array(
  178. 'title' => t('Human-Readable Name'),
  179. 'help' => t('Description of this field.'),
  180. 'field' => array(
  181. 'handler' => 'views_handler_field_readble_date',
  182. 'click sortable' => TRUE,
  183. ),
  184. 'sort' => array(
  185. 'handler' => 'views_handler_sort_date',
  186. ),
  187. );
  188. /*
  189. * End of Example Field definitions
  190. */
  191. return $data;
  192. }