tripal_chado_views.views.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php
  2. /**
  3. * @file
  4. * Chado Views Integration
  5. */
  6. include 'views/handlers/tripal_views_handler_area_action_links.inc';
  7. /**
  8. * Implements hook_views_handlers().
  9. *
  10. * Purpose: Register all custom handlers with views
  11. * where a handler describes either "the type of field",
  12. * "how a field should be filtered", "how a field should be sorted"
  13. *
  14. * @return
  15. * An array of handler definitions
  16. *
  17. * @ingroup tripal_chado_views
  18. */
  19. function tripal_chado_views_views_handlers() {
  20. return array(
  21. 'info' => array(
  22. 'path' => drupal_get_path('module', 'tripal_chado_views') . '/views/handlers',
  23. ),
  24. 'handlers' => array(
  25. // Custom Tripal Field Handlers
  26. /** CANT FIX UNTIL Tripal Feature is working
  27. 'tripal_views_handler_field_sequence' => array(
  28. 'parent' => 'views_handler_field',
  29. ),
  30. */
  31. // Custom area handler
  32. 'tripal_views_handler_area_action_links' => array(
  33. 'parent' => 'views_handler_area',
  34. ),
  35. // Custom Tripal Filter Handlers
  36. 'tripal_views_handler_filter_no_results' => array(
  37. 'parent' => 'views_handler_filter'
  38. ),
  39. 'tripal_views_handler_filter_select_cvterm' => array(
  40. 'parent' => 'tripal_views_handler_filter_select_string',
  41. ),
  42. 'tripal_views_handler_filter_select_id' => array(
  43. 'parent' => 'tripal_views_handler_filter_select_string',
  44. ),
  45. 'tripal_views_handler_filter_select_string' => array(
  46. 'parent' => 'views_handler_filter_string',
  47. ),
  48. 'tripal_views_handler_filter_textarea' => array(
  49. 'parent' => 'views_handler_filter',
  50. ),
  51. 'tripal_views_handler_filter_file_upload' => array(
  52. 'parent' => 'views_handler_filter',
  53. ),
  54. /** D7 @todo: get handlers working
  55. */
  56. /** CANT FIX UNTIL Tripal Feature is working
  57. 'tripal_views_handler_filter_sequence' => array(
  58. 'parent' => 'chado_views_handler_filter_string',
  59. ),
  60. */
  61. ),
  62. );
  63. }
  64. /**
  65. * Implements hook_views_pre_render().
  66. *
  67. * Purpose: Intercepts the view after the query has been executed
  68. * All the results are stored in $view->result
  69. * Looking up the NID here ensures the query is only executed once
  70. * for all stocks in the table.
  71. *
  72. * @ingroup tripal_chado_views
  73. */
  74. function tripal_chado_views_views_pre_render(&$view) {
  75. // We need to unset the exposed_input for the view so we can repopulate that
  76. // variable. This is necessary if we're using the file_upload_combo
  77. // custom form element which adds the file_path variable to the $_GET after the
  78. // view has populated the $view->exposed_input variable
  79. unset($view->exposed_input);
  80. // Add css if tripal admin tagged view
  81. if ($view->tag == 'tripal admin') {
  82. $tripal_admin_view_css = drupal_get_path('module', 'tripal_chado_views') . '/theme/css/tripal_views_admin_views.css';
  83. drupal_add_css($tripal_admin_view_css);
  84. }
  85. }
  86. /**
  87. * Implements hook_views_data().
  88. *
  89. * Generates a dynamic data array for Views
  90. *
  91. * This function is a hook used by the Views module. It populates and
  92. * returns a data array that specifies for the Views module the base table,
  93. * the tables it joins with and handlers. The data array is populated
  94. * using the data stored in the tripal_views tables.
  95. *
  96. * @return a data array formatted for the Views module
  97. *
  98. * D7 @todo: Add support for materialized views relationships using the new method
  99. *
  100. * @ingroup tripal_chado_views
  101. */
  102. function tripal_chado_views_views_data() {
  103. $data = array();
  104. // Manually integrate the drupal.tripal_views* tables
  105. $data = tripal_chado_views_views_data_tripal_views_tables($data);
  106. // MAKE SURE ALL CHADO TABLES ARE INTEGRATED
  107. tripal_chado_views_integrate_all_chado_tables();
  108. // DEFINE GLOBAL FIELDS
  109. // Filter handler that lets the admin say:
  110. // "Show no results until they enter search parameters"
  111. $data['views']['search_results'] = array(
  112. 'title' => t('Delay Results'),
  113. 'help' => t('Delay results until Apply/Search is clicked by the user.'),
  114. 'filter' => array(
  115. 'handler' => 'tripal_views_handler_filter_no_results',
  116. ),
  117. );
  118. $data['views']['action_links_area'] = array(
  119. 'title' => t('Action Links'),
  120. 'help' => t('Add action links to the view.'),
  121. 'area' => array(
  122. 'handler' => 'tripal_views_handler_area_action_links',
  123. ),
  124. );
  125. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  126. // INTEGRATE THE LIGHTEST SETUP FOR EACH TABLE
  127. foreach ($tvi_query as $tvi_row) {
  128. // check to see if this is the lightest (drupal-style) priority setup for this table
  129. // if not then don't use this definition
  130. $lightest_priority_setup = tripal_is_lightest_priority_setup($tvi_row->setup_id, $tvi_row->table_name);
  131. if (!$lightest_priority_setup) {
  132. continue;
  133. }
  134. // ids we'll use for queries
  135. $setup_id = $tvi_row->setup_id;
  136. $mview_id = $tvi_row->mview_id;
  137. // holds the base table name and fields
  138. $base_table = '';
  139. $base_fields = array();
  140. // indicated whether the current table is a base table or not
  141. $is_base_table = $tvi_row->base_table;
  142. // POPULATE THE BASE TABLE NAME AND FIELDS
  143. // If an $mview_id is given then get the materialized view info,
  144. // otherwise get the Chado table info
  145. $legacy_mview = FALSE;
  146. if ($mview_id) {
  147. // get the base table name from the materialized view
  148. // D7 TODO: Check DBTNG changes work
  149. $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = :id";
  150. $mview_table = db_query($sql, array(':id' => $mview_id));
  151. $mview_table = $mview_table->fetchObject();
  152. $base_table = $mview_table->name;
  153. if (!empty($mview_table->mv_specs)) {
  154. $legacy_mview = TRUE;
  155. }
  156. }
  157. if ($legacy_mview) {
  158. // get the columns in this materialized view. They are separated by commas
  159. // where the first word is the column name and the rest is the type
  160. $columns = explode(",", $mview_table->mv_specs);
  161. foreach ($columns as $column) {
  162. $column = trim($column); // trim trailing and leading spaces
  163. preg_match("/^(.*?)\ (.*?)$/", $column, $matches);
  164. $column_name = $matches[1];
  165. $column_type = $matches[2];
  166. $base_fields[$column_name] = array(
  167. 'column_name' => $column_name,
  168. 'type' => $column_type,
  169. );
  170. }
  171. // get the field name and descriptions
  172. // D7 TODO: Check DBTNG changes work
  173. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
  174. $query = db_query($sql, array(':setup' => $setup_id));
  175. foreach($query as $field) {
  176. $base_fields[$field->column_name]['name'] = $field->name;
  177. $base_fields[$field->column_name]['help'] = $field->description;
  178. }
  179. }
  180. // if this is not a legacy materialized view
  181. else {
  182. $base_table = $tvi_row->table_name;
  183. // get the table description
  184. $table_desc = chado_get_schema($base_table);
  185. $fields = $table_desc['fields'];
  186. if (!is_array($fields)) {
  187. $fields = array();
  188. }
  189. foreach ($fields as $column => $attrs) {
  190. $base_fields[$column] = array(
  191. 'column_name' => $column,
  192. 'type' => $attrs['type'],
  193. );
  194. }
  195. // get the field name and descriptions
  196. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
  197. $query = db_query($sql, array(':setup' => $setup_id));
  198. foreach ($query as $field) {
  199. $base_fields[$field->column_name]['name'] = $field->name;
  200. $base_fields[$field->column_name]['help'] = $field->description;
  201. }
  202. }
  203. // SETUP THE BASE TABLE INFO IN THE DATA ARRAY
  204. $data[$base_table]['table']['group'] = t("$tvi_row->name");
  205. if ($is_base_table) {
  206. $data[$base_table]['table']['base'] = array(
  207. 'group' => "$tvi_row->name",
  208. 'title' => "$tvi_row->name",
  209. 'help' => $tvi_row->comment,
  210. 'search_path' => 'chado'
  211. );
  212. }
  213. else {
  214. $data[$base_table]['table'] = array(
  215. 'group' => "$tvi_row->name",
  216. 'title' => "$tvi_row->name",
  217. 'help' => $tvi_row->comment,
  218. 'search_path' => 'chado'
  219. );
  220. }
  221. // ADD THE FIELDS TO THE DATA ARRAY
  222. foreach ($base_fields as $column_name => $base_field) {
  223. if (!isset($base_field['name'])) {
  224. $data[$base_table][$column_name] = array(
  225. 'title' => t($column_name),
  226. 'help' => t($column_name),
  227. 'field' => array(
  228. 'click sortable' => TRUE,
  229. ),
  230. );
  231. tripal_report_error(
  232. 'tripal_chado_views',
  233. TRIPAL_WARNING,
  234. "The name and help were not set for %table.%column. As a consequence the column
  235. name has been used... You should ensure that the 'name' and 'help' keys for
  236. this field are set in the integration array (priority = %priority)",
  237. array(
  238. '%table'=> $base_table,
  239. '%column' => $column_name,
  240. '%priority' => $tvi_row->priority
  241. )
  242. );
  243. }
  244. else {
  245. $data[$base_table][$column_name] = array(
  246. 'title' => t($base_field['name']),
  247. 'help' => t($base_field['help']),
  248. 'field' => array(
  249. 'click sortable' => TRUE,
  250. ),
  251. );
  252. }
  253. // now add the handlers
  254. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = :setup AND column_name = :column";
  255. $handlers = db_query($sql, array(':setup' => $setup_id, ':column' => $column_name));
  256. $num_handlers = 0;
  257. foreach ($handlers as $handler) {
  258. $num_handlers++;
  259. $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
  260. // Add in any additional arguments
  261. // This should be a serialized array including (at a minimum) name => <handler name>
  262. if ($handler->arguments) {
  263. $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
  264. }
  265. };
  266. // If there were no handlers applied to the current field then warn the administrator!
  267. if ($num_handlers == 0) {
  268. tripal_report_error(
  269. 'tripal_chado_views',
  270. TRIPAL_WARNING,
  271. "No handlers were registered for %table.%column. This means there is no views
  272. functionality for this column. To register handlers, make sure the 'handlers'
  273. key for this field is set in the integration array (priority = %priority).
  274. The supported keys include 'field', 'filter', 'sort', 'relationship'. Look
  275. at the tripal_add_views_integration() for additional details.",
  276. array(
  277. '%table'=> $base_table,
  278. '%column' => $column_name,
  279. '%priority' => $tvi_row->priority
  280. )
  281. );
  282. }
  283. }
  284. // ADD JOINS & RELATIONSHIPS TO DATA ARRAY
  285. // only add joins if this is a base table
  286. // this keeps the list of available fields manageable
  287. // all other tables should be added via relationships
  288. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
  289. $joins = db_query($sql, array(':setup' => $setup_id));
  290. if (!isset($joins)) {
  291. $joins = array();
  292. }
  293. foreach ($joins as $join) {
  294. $left_table = $join->left_table;
  295. $left_field = $join->left_field;
  296. $base_table = $join->base_table;
  297. $base_field = $join->base_field;
  298. $handler = $join->handler;
  299. $base_title = ucwords(str_replace('_', ' ', $base_table));
  300. $left_title = ucwords(str_replace('_', ' ', $left_table));
  301. // if the 'node' table is in our integrated list then
  302. // we want to skip it. It shouldn't be there.
  303. if ($left_table == 'node') {
  304. continue;
  305. }
  306. // add join entry
  307. if (!$join->relationship_only) {
  308. $data[$left_table]['table']['join'][$base_table] = array(
  309. 'left_field' => $base_field,
  310. 'field' => $left_field,
  311. );
  312. if ($handler) {
  313. $data[$left_table]['table']['join'][$base_table]['handler'] = $handler;
  314. }
  315. if (!empty($join->arguments)) {
  316. array_merge($data[$left_table]['table']['join'][$base_table], unserialize($join->arguments));
  317. }
  318. }
  319. // warn if deprecated method of relationship addition was used (ie: through handlers)
  320. if (isset($data[$base_table][$base_field]['relationship'])) {
  321. tripal_report_error('tripal_chado_views', TRIPAL_NOTICE,
  322. 'DEPRECATED: Currently using tripal_views_handlers to store relationship for %base => %left when you should be using tripal_views_joins.',
  323. array('%base' => $base_table, '%left' => $left_table));
  324. }
  325. // Add relationship entry.
  326. // NOTE: we use a fake field name to allow us to have multiple
  327. // relationships for the same field (ie: feature.feature_id has many
  328. // Many relationships but views only supports a single one).
  329. $fake_field = $base_field . '_to_' . $left_table;
  330. // Bug Fix: The old $fake_field used above doesn't take into account
  331. // multiple relationships to the same left table. To keep backwards
  332. // compatibility, this old fake_field needs to continue to be used for
  333. // the LAST recorded relationship. However, for all previously set
  334. // relationships we can use an improved fake name which takes into
  335. // account the left field and ensures all relationships for a single
  336. // left table are not condensed into a single relationship.
  337. if (array_key_exists($fake_field, $data[$base_table])) {
  338. // Again, note that we can't just change the fake_name after finding
  339. // there is more than one relationship because then the FIRST
  340. // relationship would keep the old fake_name rather than the LAST
  341. // which keeps backwards compatiblity since the old naming caused all
  342. // previous relationships be be overridden by the next one.
  343. // Thus we first need to determine the left field of the previous
  344. // join for this table combination and then use that to form our
  345. // improved fake field.
  346. $previous_left_field = $data[$base_table][$fake_field]['relationship']['base field'];
  347. $improved_fake_field = $base_field . '_to_' . $left_table . "." . $previous_left_field;
  348. $data[$base_table][$improved_fake_field] = $data[$base_table][$fake_field];
  349. }
  350. $data[$base_table][$fake_field] = array(
  351. 'title' => "$base_title.$base_field => $left_title.$left_field",
  352. 'help' => t("Joins @base to @left", array('@base' => "$base_title.$base_field", '@left' => "$left_title.$left_field")),
  353. 'relationship' => array(
  354. 'handler' => $join->relationship_handler,
  355. 'title' => t("$base_field => $left_title ($left_field)"),
  356. 'label' => t("$base_field => $left_title ($left_field)"),
  357. 'real field' => $base_field,
  358. 'base' => $left_table,
  359. 'base field' => $left_field
  360. )
  361. );
  362. if (!empty($join->arguments)) {
  363. array_merge($data[$base_table][$fake_field]['relationship'], unserialize($join->arguments));
  364. }
  365. }
  366. }
  367. return $data;
  368. }
  369. /**
  370. * Describes the tripal views integration tables to views for the administration views
  371. *
  372. * @ingroup tripal_chado_views
  373. */
  374. function tripal_chado_views_views_data_tripal_views_tables($data) {
  375. $data['tripal_views']['table']['group'] = t('Chado Views Integration');
  376. $data['tripal_views']['table']['base'] = array(
  377. 'field' => 'setup_id', // This is the identifier field for the view.
  378. 'title' => t('Chado Views Integration'),
  379. 'help' => t('Specifications on how to integrate various tables with Drupal Views'),
  380. 'weight' => -10,
  381. );
  382. // Implicit Join to Materialized Views
  383. $data['tripal_views']['table']['join'] = array(
  384. 'tripal_mviews' => array(
  385. 'left_field' => 'mview_id',
  386. 'field' => 'mview_id',
  387. ),
  388. );
  389. // setup_id
  390. $data['tripal_views']['setup_id'] = array(
  391. 'title' => t('Setup ID'),
  392. 'help' => t('Primary key of the integration'),
  393. 'field' => array(
  394. 'handler' => 'views_handler_field_numeric',
  395. 'click sortable' => TRUE,
  396. ),
  397. 'filter' => array(
  398. 'handler' => 'views_handler_filter_numeric',
  399. ),
  400. 'sort' => array(
  401. 'handler' => 'views_handler_sort',
  402. ),
  403. );
  404. // mview_id
  405. $data['tripal_views']['mview_id'] = array(
  406. 'title' => t('Materialized View ID'),
  407. 'help' => t('The primary key of the Mview integrated.'),
  408. 'field' => array(
  409. 'handler' => 'views_handler_field_numeric',
  410. 'click sortable' => TRUE,
  411. ),
  412. 'filter' => array(
  413. 'handler' => 'views_handler_filter_numeric',
  414. ),
  415. 'sort' => array(
  416. 'handler' => 'views_handler_sort',
  417. ),
  418. );
  419. // base_table
  420. $data['tripal_views']['base_table'] = array(
  421. 'title' => t('Base Table?'),
  422. 'help' => t('Whether the table being integrated should be considered a base table.'),
  423. 'field' => array(
  424. 'handler' => 'views_handler_field_boolean',
  425. 'click sortable' => TRUE,
  426. ),
  427. 'filter' => array(
  428. 'handler' => 'views_handler_filter_boolean_operator',
  429. 'label' => t('Base Table?'),
  430. 'type' => 'yes-no',
  431. 'use equal' => TRUE,
  432. ),
  433. 'sort' => array(
  434. 'handler' => 'views_handler_sort',
  435. ),
  436. );
  437. // table_name
  438. $data['tripal_views']['table_name'] = array(
  439. 'title' => t('Chado Table Name'),
  440. 'help' => t('The name of the table being integrated'),
  441. 'field' => array(
  442. 'handler' => 'views_handler_field',
  443. 'click sortable' => TRUE, // This is use by the table display plugin.
  444. ),
  445. 'sort' => array(
  446. 'handler' => 'views_handler_sort',
  447. ),
  448. 'filter' => array(
  449. 'handler' => 'views_handler_filter_string',
  450. ),
  451. 'argument' => array(
  452. 'handler' => 'views_handler_argument_string',
  453. ),
  454. );
  455. // priority
  456. $data['tripal_views']['priority'] = array(
  457. 'title' => t('Priority'),
  458. 'help' => t('The priority of the integration.'),
  459. 'field' => array(
  460. 'handler' => 'views_handler_field_numeric',
  461. 'click sortable' => TRUE,
  462. ),
  463. 'filter' => array(
  464. 'handler' => 'views_handler_filter_numeric',
  465. ),
  466. 'sort' => array(
  467. 'handler' => 'views_handler_sort',
  468. ),
  469. );
  470. // name
  471. $data['tripal_views']['name'] = array(
  472. 'title' => t('Name'),
  473. 'help' => t('The name of the integration'),
  474. 'field' => array(
  475. 'handler' => 'views_handler_field',
  476. 'click sortable' => TRUE, // This is use by the table display plugin.
  477. ),
  478. 'sort' => array(
  479. 'handler' => 'views_handler_sort',
  480. ),
  481. 'filter' => array(
  482. 'handler' => 'views_handler_filter_string',
  483. ),
  484. 'argument' => array(
  485. 'handler' => 'views_handler_argument_string',
  486. ),
  487. );
  488. // comment
  489. $data['tripal_views']['comment'] = array(
  490. 'title' => t('Description'),
  491. 'help' => t('Short description or comment about this integration.'),
  492. 'field' => array(
  493. 'handler' => 'views_handler_field',
  494. 'click sortable' => TRUE, // This is use by the table display plugin.
  495. ),
  496. 'sort' => array(
  497. 'handler' => 'views_handler_sort',
  498. ),
  499. 'filter' => array(
  500. 'handler' => 'views_handler_filter_string',
  501. ),
  502. 'argument' => array(
  503. 'handler' => 'views_handler_argument_string',
  504. ),
  505. );
  506. return $data;
  507. }
  508. /**
  509. * Implements hook_views_data_alter().
  510. * Used to add Chado <-> Node Joins & Relationships
  511. * since you need to add to the $data['node'] to do this
  512. *
  513. * @ingroup tripal_chado_views
  514. */
  515. function tripal_chado_views_views_data_alter(&$data) {
  516. // ADD IN NODE JOINS & RELATIONSHIPS
  517. // D7 @todo: Create custom handler to allow join from Node => Base (ie: organism)
  518. // with the addition of a single relationship
  519. // D7 @todo: Create custom handler to allow join from Base (ie: organism)
  520. // with the addition of a single relationship
  521. // D7 @todo: Add support for Mview <-> Node joins and relationships
  522. $tvi_query = db_query('SELECT * FROM {tripal_views} WHERE base_table=1');
  523. foreach ($tvi_query as $tvi_row) {
  524. //ids we'll use for queries
  525. $setup_id = $tvi_row->setup_id;
  526. $base_table = $tvi_row->table_name;
  527. $linker_table = 'chado_' . $base_table;
  528. $base_title = ucwords(str_replace('_', ' ', $base_table));
  529. // add in joins to the node tables if the Chado schema is local
  530. if (chado_is_local()) {
  531. // if a node linking table exists then add in the joins
  532. if (db_table_exists($linker_table)) {
  533. // Adds content (node) fields to chado base table field lists automatically
  534. $data['node']['table']['join'][$linker_table] = array(
  535. 'left_field' => 'nid',
  536. 'field' => 'nid',
  537. );
  538. $data[$linker_table]['table']['join'][$base_table] = array(
  539. 'left_field' => $base_table . '_id',
  540. 'field' => $base_table . '_id',
  541. );
  542. $data['node']['table']['join'][$base_table] = array(
  543. 'left_table' => $linker_table,
  544. 'left_field' => 'nid',
  545. 'field' => 'nid',
  546. );
  547. // Adds in a chado base table => node relationship
  548. // This allows controlled joining to multiple nodes per line
  549. // Use Case: link to feature and organism nodes on a feature listing
  550. // D7 todo: a custom relationship handler to get from feature.organism_id => organism node
  551. // without 1st needing to add relationship to organism table
  552. $base_field = $base_table . '_id';
  553. $data[$linker_table][$base_field] = array(
  554. 'group' => $base_title,
  555. 'title' => $base_title . 'Node',
  556. 'help' => t("Links @base_title to it's node.", array('@base_title' => $base_title)),
  557. 'relationship' => array(
  558. 'handler' => 'views_handler_relationship',
  559. 'title' => t("@base_title => Node", array('@base_title' => $base_title)),
  560. 'label' => t("@base_title => Node", array('@base_title' => $base_title)),
  561. 'real field' => 'nid',
  562. 'base' => 'node',
  563. 'base field' => 'nid'
  564. ),
  565. );
  566. // Add Chado fields to a node-based view
  567. // This will only be done with relationships
  568. $base_field = $base_table . '_id';
  569. $data['node'][$base_field] = array(
  570. 'group' => $base_title,
  571. 'title' => $base_title,
  572. 'help' => t("Links node to chado @base_title.", array('@base_title' => $base_title)),
  573. 'relationship' => array(
  574. 'handler' => 'views_handler_relationship',
  575. 'title' => t("Node => @base_title", array('@base_title' => $base_title)),
  576. 'label' => t("Node => @base_title", array('@base_title' => $base_title)),
  577. 'real field' => 'nid',
  578. 'base' => $linker_table,
  579. 'base field' => 'nid'
  580. ),
  581. );
  582. }
  583. }
  584. }
  585. return $data;
  586. }
  587. /**
  588. * Implementation of hook_views_pre_view().
  589. *
  590. * Merge the $_GET and $_POST into the $_GET. This is because
  591. * Views and Views Data Export modules only uses the $_GET variable but
  592. * file uploads require $_POST. We need to make sure these two modules
  593. * have access to everything needed for this view to work properly.
  594. *
  595. * @ingroup tripal_chado_views
  596. */
  597. function tripal_chado_views_views_pre_view(&$view, &$display_id, &$args) {
  598. $_GET = array_merge($_GET, $_POST);
  599. }