project.views.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /**
  3. * @file
  4. * This file defines the data array for a given chado table. This array
  5. * is merged into a larger array containing definitions of all tables associated
  6. * with this module in:
  7. * @see tripal_project.views.inc --in tripal_project_views_data()
  8. *
  9. * Documentation on views integration can be found at
  10. * http://views2.logrus.com/doc/html/index.html.
  11. */
  12. /*************************************************************************
  13. * Purpose: this function returns the portion of the data array
  14. * which describes the project table, it's fields and any joins between it and other tables
  15. * @see tripal_project_views_data() --in tripal_project.views.inc
  16. *
  17. * Table: project
  18. * @code
  19. * project-Copy/Paste Table SQL code here-project
  20. * @endcode
  21. */
  22. function retrieve_project_views_data() {
  23. global $db_url;
  24. $data = array();
  25. // if the chado database is not local to the drupal database
  26. // then we need to set the database name. This should always
  27. // be 'chado'.
  28. if (is_array($db_url) and array_key_exists('chado', $db_url)) {
  29. $database = 'chado';
  30. }
  31. //Basic table definition-----------------------------------
  32. $data['project']['table']['group'] = t('Chado Project');
  33. $data['project']['table']['base'] = array(
  34. 'field' => 'project_id',
  35. 'title' => t('Chado Project'),
  36. 'help' => t('Another way of grouping chado content together.'),
  37. );
  38. if ($database) {
  39. $data['project']['table']['database'] = $database;
  40. }
  41. //Relationship Definitions---------------------------------
  42. //Join: YYY => project
  43. // Notice that this relationship tells the primary table to show it's fields to the
  44. // table referencing it by a foreign key and thus the relationship is from
  45. // primary table to table referenceing it (ie: cvterm => feature)
  46. /**
  47. $data['project']['table']['join']['YYY'] = array(
  48. 'left_field' => 'foreign key in YYY table',
  49. 'field' => 'primary key in project table',
  50. );
  51. */
  52. //Join: project => XY => YYY
  53. // This relationship should be described in both directions
  54. // in the appropriate files (ie: for feature => library
  55. // describe in both feature.views.inc and library.views.inc)
  56. /**
  57. $data['project']['table']['join']['XY'] = array(
  58. 'left_field' => 'matching project key in the XY table',
  59. 'field' => 'primary key in project table',
  60. );
  61. $data['project']['table']['join']['YYY'] = array(
  62. 'left_table' => 'XY',
  63. 'left_field' => 'matching project key in the XY table',
  64. 'field' => 'primary key in project table',
  65. );
  66. $data['XY']['table']['join']['YYY'] = array(
  67. 'left_field' => 'primary key in YYY table',
  68. 'field' => 'matching YYY key in the XY table',
  69. );
  70. */
  71. //Table Field Definitions----------------------------------
  72. //Field: project_id (primary key)
  73. $data['project']['project_id'] = array(
  74. 'title' => t('Project Primary Key'),
  75. 'help' => t('A unique index for every project.'),
  76. 'field' => array(
  77. 'handler' => 'views_handler_field_numeric',
  78. 'click sortable' => TRUE,
  79. ),
  80. 'sort' => array(
  81. 'handler' => 'views_handler_sort',
  82. ),
  83. 'filter' => array(
  84. 'handler' => 'views_handler_filter_numeric',
  85. ),
  86. );
  87. // Calculated Field: Node ID
  88. // use custom field handler to query drupal for the node ID
  89. // this is only needed if chado is in a separate database from drupal
  90. if ($database) {
  91. }
  92. else {
  93. // Add relationship between chado_project and project
  94. $data['project']['project_nid'] = array(
  95. 'group' => 'project',
  96. 'title' => 'project Node',
  97. 'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
  98. 'real field' => 'project_id',
  99. 'relationship' => array(
  100. 'handler' => 'views_handler_relationship',
  101. 'title' => t('project => Chado'),
  102. 'label' => t('project => Chado'),
  103. 'real field' => 'project_id',
  104. 'base' => 'chado_project',
  105. 'base field' => 'project_id'
  106. ),
  107. );
  108. }
  109. //Field: name (varchar -255)
  110. $data['project']['name'] = array(
  111. 'title' => t('Name'),
  112. 'help' => t('The name of the project.'),
  113. 'field' => array(
  114. 'handler' => 'views_handler_field',
  115. 'click sortable' => TRUE,
  116. ),
  117. 'sort' => array(
  118. 'handler' => 'views_handler_sort',
  119. ),
  120. 'filter' => array(
  121. 'handler' => 'views_handler_filter_string',
  122. ),
  123. 'argument' => array(
  124. 'handler' => 'views_handler_argument_string',
  125. ),
  126. );
  127. // if joined to the node table add a "Link to Node" option for the field
  128. if (!$database) {
  129. $data['project']['name']['field']['handler'] = 'views_handler_field_node_optional';
  130. }
  131. //Field: description (varchar -255)
  132. $data['project']['description'] = array(
  133. 'title' => t('Description'),
  134. 'help' => t('A short description of the project'),
  135. 'field' => array(
  136. 'handler' => 'views_handler_field',
  137. 'click sortable' => TRUE,
  138. ),
  139. 'sort' => array(
  140. 'handler' => 'views_handler_sort',
  141. ),
  142. 'filter' => array(
  143. 'handler' => 'views_handler_filter_string',
  144. ),
  145. 'argument' => array(
  146. 'handler' => 'views_handler_argument_string',
  147. ),
  148. );
  149. /*.......................................................
  150. * Beginning of Example Field definitions
  151. * Remove this section when done
  152. //Field: plain_text_field (chado datatype)
  153. $data['project']['plain_text_field'] = array(
  154. 'title' => t('Human-Readable Name'),
  155. 'help' => t('Description of this field.'),
  156. 'field' => array(
  157. 'handler' => 'views_handler_field',
  158. 'click sortable' => TRUE,
  159. ),
  160. 'sort' => array(
  161. 'handler' => 'views_handler_sort',
  162. ),
  163. 'filter' => array(
  164. 'handler' => 'views_handler_filter_string',
  165. ),
  166. 'argument' => array(
  167. 'handler' => 'views_handler_argument_string',
  168. ),
  169. );
  170. //Field: numeric_field (chado datatype)
  171. $data['project']['numeric_field'] = array(
  172. 'title' => t('Human-Readable Name'),
  173. 'help' => t('Description of this field.'),
  174. 'field' => array(
  175. 'handler' => 'views_handler_field_numeric',
  176. 'click sortable' => TRUE,
  177. ),
  178. 'sort' => array(
  179. 'handler' => 'views_handler_sort',
  180. ),
  181. 'filter' => array(
  182. 'handler' => 'views_handler_filter_numeric',
  183. ),
  184. );
  185. //Field: boolean_field (chado datatype)
  186. $data['project']['boolean_field'] = array(
  187. 'title' => t('Human-Readable Name'),
  188. 'help' => t('Description of this field.'),
  189. 'field' => array(
  190. 'handler' => 'views_handler_field_boolean',
  191. 'click sortable' => TRUE,
  192. ),
  193. 'sort' => array(
  194. 'handler' => 'views_handler_sort',
  195. ),
  196. 'filter' => array(
  197. 'handler' => 'views_handler_filter_boolean_operator',
  198. ),
  199. );
  200. //Field: unix_timestamp (chado datatype)
  201. $data['project']['unix_timestamp'] = array(
  202. 'title' => t('Human-Readable Name'),
  203. 'help' => t('Description of this field.'),
  204. 'field' => array(
  205. 'handler' => 'views_handler_field_date',
  206. 'click sortable' => TRUE,
  207. ),
  208. 'sort' => array(
  209. 'handler' => 'views_handler_sort_date',
  210. ),
  211. 'filter' => array(
  212. 'handler' => 'views_handler_filter_date',
  213. ),
  214. );
  215. //Field: human_readable_date (chado datatype)
  216. $data['project']['human_readable_date'] = array(
  217. 'title' => t('Human-Readable Name'),
  218. 'help' => t('Description of this field.'),
  219. 'field' => array(
  220. 'handler' => 'views_handler_field_readble_date',
  221. 'click sortable' => TRUE,
  222. ),
  223. 'sort' => array(
  224. 'handler' => 'views_handler_sort_date',
  225. ),
  226. );
  227. * End of Example Field definitions
  228. */
  229. return $data;
  230. }