project.views.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. } else {
  92. // Add relationship between chado_project and project
  93. $data['project']['project_nid'] = array(
  94. 'group' => 'project',
  95. 'title' => 'project Node',
  96. 'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
  97. 'real field' => 'project_id',
  98. 'relationship' => array(
  99. 'handler' => 'views_handler_relationship',
  100. 'title' => t('project => Chado'),
  101. 'label' => t('project => Chado'),
  102. 'real field' => 'project_id',
  103. 'base' => 'chado_project',
  104. 'base field' => 'project_id'
  105. ),
  106. );
  107. }
  108. //Field: name (varchar -255)
  109. $data['project']['name'] = array(
  110. 'title' => t('Name'),
  111. 'help' => t('The name of the project.'),
  112. 'field' => array(
  113. 'handler' => 'views_handler_field',
  114. 'click sortable' => TRUE,
  115. ),
  116. 'sort' => array(
  117. 'handler' => 'views_handler_sort',
  118. ),
  119. 'filter' => array(
  120. 'handler' => 'views_handler_filter_string',
  121. ),
  122. 'argument' => array(
  123. 'handler' => 'views_handler_argument_string',
  124. ),
  125. );
  126. // if joined to the node table add a "Link to Node" option for the field
  127. if (!$database) {
  128. $data['project']['name']['field']['handler'] = 'views_handler_field_node_optional';
  129. }
  130. //Field: description (varchar -255)
  131. $data['project']['description'] = array(
  132. 'title' => t('Description'),
  133. 'help' => t('A short description of the project'),
  134. 'field' => array(
  135. 'handler' => 'views_handler_field',
  136. 'click sortable' => TRUE,
  137. ),
  138. 'sort' => array(
  139. 'handler' => 'views_handler_sort',
  140. ),
  141. 'filter' => array(
  142. 'handler' => 'views_handler_filter_string',
  143. ),
  144. 'argument' => array(
  145. 'handler' => 'views_handler_argument_string',
  146. ),
  147. );
  148. /*.......................................................
  149. * Beginning of Example Field definitions
  150. * Remove this section when done
  151. //Field: plain_text_field (chado datatype)
  152. $data['project']['plain_text_field'] = array(
  153. 'title' => t('Human-Readable Name'),
  154. 'help' => t('Description of this field.'),
  155. 'field' => array(
  156. 'handler' => 'views_handler_field',
  157. 'click sortable' => TRUE,
  158. ),
  159. 'sort' => array(
  160. 'handler' => 'views_handler_sort',
  161. ),
  162. 'filter' => array(
  163. 'handler' => 'views_handler_filter_string',
  164. ),
  165. 'argument' => array(
  166. 'handler' => 'views_handler_argument_string',
  167. ),
  168. );
  169. //Field: numeric_field (chado datatype)
  170. $data['project']['numeric_field'] = array(
  171. 'title' => t('Human-Readable Name'),
  172. 'help' => t('Description of this field.'),
  173. 'field' => array(
  174. 'handler' => 'views_handler_field_numeric',
  175. 'click sortable' => TRUE,
  176. ),
  177. 'sort' => array(
  178. 'handler' => 'views_handler_sort',
  179. ),
  180. 'filter' => array(
  181. 'handler' => 'views_handler_filter_numeric',
  182. ),
  183. );
  184. //Field: boolean_field (chado datatype)
  185. $data['project']['boolean_field'] = array(
  186. 'title' => t('Human-Readable Name'),
  187. 'help' => t('Description of this field.'),
  188. 'field' => array(
  189. 'handler' => 'views_handler_field_boolean',
  190. 'click sortable' => TRUE,
  191. ),
  192. 'sort' => array(
  193. 'handler' => 'views_handler_sort',
  194. ),
  195. 'filter' => array(
  196. 'handler' => 'views_handler_filter_boolean_operator',
  197. ),
  198. );
  199. //Field: unix_timestamp (chado datatype)
  200. $data['project']['unix_timestamp'] = array(
  201. 'title' => t('Human-Readable Name'),
  202. 'help' => t('Description of this field.'),
  203. 'field' => array(
  204. 'handler' => 'views_handler_field_date',
  205. 'click sortable' => TRUE,
  206. ),
  207. 'sort' => array(
  208. 'handler' => 'views_handler_sort_date',
  209. ),
  210. 'filter' => array(
  211. 'handler' => 'views_handler_filter_date',
  212. ),
  213. );
  214. //Field: human_readable_date (chado datatype)
  215. $data['project']['human_readable_date'] = array(
  216. 'title' => t('Human-Readable Name'),
  217. 'help' => t('Description of this field.'),
  218. 'field' => array(
  219. 'handler' => 'views_handler_field_readble_date',
  220. 'click sortable' => TRUE,
  221. ),
  222. 'sort' => array(
  223. 'handler' => 'views_handler_sort_date',
  224. ),
  225. );
  226. * End of Example Field definitions
  227. */
  228. return $data;
  229. }