tripal_views.views.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. include('views/handlers/views_handler_join_chado_through_linking.inc');
  3. include('views/handlers/views_handler_join_chado_aggregator.inc');
  4. include('api/tripal_views.api.inc');
  5. // TEMPORARY
  6. include('views/chado_linking.TMP.inc');
  7. /**
  8. * @file
  9. * Tripal Views Integration
  10. *
  11. * @defgroup views Views Integration
  12. * @{
  13. * Provide rules for formatting and composition of fields
  14. * @}
  15. *
  16. * @defgroup views_handlers Views Integration Handlers
  17. * @ingroup views
  18. * @{
  19. * Provide rules for formatting and composition of fields
  20. * @}
  21. *
  22. * @defgroup views_field_handlers Views Field Handlers
  23. * @ingroup views_handlers
  24. * @{
  25. * Provide rules for formatting and composition of fields
  26. * @}
  27. *
  28. *
  29. * @defgroup views_filter_handlers Views Filter Handlers
  30. * @ingroup views_handlers
  31. * @{
  32. * Provide the ability to filter based on specified data
  33. * @}
  34. *
  35. * @defgroup views_sort_handlers Views Sort Handlers
  36. * @ingroup views_handlers
  37. * @{
  38. * Provide methods describing how specific data should be sorted
  39. * @}
  40. *
  41. * @defgroup views_argument_handlers Views Arguement Handlers
  42. * @ingroup views_handlers
  43. * @{
  44. * Provide the ability to filter pased on arguments in the path of the view
  45. * @}
  46. */
  47. /**
  48. * Implements hook_views_handlers()
  49. *
  50. * Purpose: Register all custom handlers with views
  51. * where a handler describes either "the type of field",
  52. * "how a field should be filtered", "how a field should be sorted"
  53. *
  54. * @return
  55. * An array of handler definitions
  56. *
  57. * @ingroup tripal_views
  58. */
  59. function tripal_views_views_handlers() {
  60. return array(
  61. 'info' => array(
  62. 'path' => drupal_get_path('module', 'tripal_views') . '/views/handlers',
  63. ),
  64. 'handlers' => array(
  65. // Custom Tripal Filter Handlers
  66. 'tripal_views_handler_filter_file_upload' => array(
  67. 'parent' => 'views_handler_filter',
  68. ),
  69. 'tripal_views_handler_filter_textarea' => array(
  70. 'parent' => 'views_handler_filter',
  71. ),
  72. 'tripal_views_handler_filter_no_results' => array(
  73. 'parent' => 'views_handler_filter'
  74. ),
  75. 'tripal_views_handler_filter_select_cvterm' => array(
  76. 'parent' => 'views_handler_filter_string',
  77. ),
  78. 'tripal_views_handler_filter_select_string' => array(
  79. 'parent' => 'chado_views_handler_filter_string',
  80. ),
  81. 'tripal_views_handler_filter_sequence' => array(
  82. 'parent' => 'chado_views_handler_filter_string',
  83. ),
  84. // Custom Tripal Field Handlers
  85. 'tripal_views_handler_field_aggregate' => array(
  86. 'parent' => 'chado_views_handler_field',
  87. ),
  88. 'tripal_views_handler_field_sequence' => array(
  89. 'parent' => 'chado_views_handler_field',
  90. ),
  91. // Join Handlers
  92. 'views_handler_join_chado_aggregator' => array(
  93. 'parent' => 'views_join',
  94. ),
  95. 'views_handler_join_chado_through_linking' => array(
  96. 'parent' => 'views_join',
  97. ),
  98. // Relationship Handlers
  99. 'chado_views_handler_relationship' => array(
  100. 'parent' => 'views_handler_relationship'
  101. ),
  102. 'chado_views_handler_relationship_to_node' => array(
  103. 'parent' => 'views_handler_relationship'
  104. ),
  105. // Wrappers for Default Views Handlers-----
  106. // Field Handlers
  107. 'chado_views_handler_field' => array(
  108. 'parent' => 'views_handler_field'
  109. ),
  110. 'chado_views_handler_field_boolean' => array(
  111. 'parent' => 'views_handler_field_boolean'
  112. ),
  113. 'chado_views_handler_field_counter' => array(
  114. 'parent' => 'views_handler_field_counter'
  115. ),
  116. 'chado_views_handler_field_custom' => array(
  117. 'parent' => 'views_handler_field_custom'
  118. ),
  119. 'chado_views_handler_field_date' => array(
  120. 'parent' => 'views_handler_field_date'
  121. ),
  122. 'chado_views_handler_field_markup' => array(
  123. 'parent' => 'views_handler_field_markup'
  124. ),
  125. 'chado_views_handler_field_math' => array(
  126. 'parent' => 'views_handler_field_math'
  127. ),
  128. 'chado_views_handler_field_numeric' => array(
  129. 'parent' => 'views_handler_field_numeric'
  130. ),
  131. // Filter Handlers
  132. 'chado_views_handler_filter_string' => array(
  133. 'parent' => 'views_handler_filter_string',
  134. ),
  135. 'chado_views_handler_filter_boolean_operator_string' => array(
  136. 'parent' => 'views_handler_filter_boolean_operator_string',
  137. ),
  138. 'chado_views_handler_filter_boolean_operator' => array(
  139. 'parent' => 'views_handler_filter_boolean_operator',
  140. ),
  141. 'chado_views_handler_filter_date' => array(
  142. 'parent' => 'views_handler_filter_date',
  143. ),
  144. 'chado_views_handler_filter_equality' => array(
  145. 'parent' => 'views_handler_filter_equality',
  146. ),
  147. 'chado_views_handler_filter_float' => array(
  148. 'parent' => 'views_handler_filter_float',
  149. ),
  150. 'chado_views_handler_filter_numeric' => array(
  151. 'parent' => 'views_handler_filter_numeric',
  152. ),
  153. // Sort Handlers
  154. 'chado_views_handler_sort' => array(
  155. 'parent' => 'views_handler_sort'
  156. ),
  157. 'chado_views_handler_sort_date' => array(
  158. 'parent' => 'views_handler_sort_date'
  159. ),
  160. 'chado_views_handler_sort_formula' => array(
  161. 'parent' => 'views_handler_sort_formula'
  162. ),
  163. 'chado_views_handler_sort_menu_hierarchy' => array(
  164. 'parent' => 'views_handler_sort_menu_hierarchy'
  165. ),
  166. 'chado_views_handler_sort_random' => array(
  167. 'parent' => 'views_handler_sort_random'
  168. ),
  169. ),
  170. );
  171. }
  172. /**
  173. * Implements hook_views_pre_render
  174. *
  175. * Purpose: Intercepts the view after the query has been executed
  176. * All the results are stored in $view->result
  177. * Looking up the NID here ensures the query is only executed once
  178. * for all stocks in the table.
  179. *
  180. * @todo add if !<chado/drupal same db> around NID portion
  181. *
  182. * @ingroup tripal_views
  183. */
  184. function tripal_views_views_pre_render(&$view) {
  185. // We need to unset the exposed_input for the view so we can repopulate that
  186. // variable. This is necessary if we're using the file_upload_combo
  187. // custom form element which adds the file_path variable to the $_GET after the
  188. // view has populated the $view->exposed_input variable
  189. unset($view->exposed_input);
  190. // we want to add to the bottom of the views the form for downloading
  191. // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
  192. // Export module provides small images at the bottom, but we want to provide
  193. // a more intutitive interface for getting different file formats
  194. $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
  195. $view->attachment_after = $form;
  196. }
  197. /**
  198. * Generates a dynamic data array for Views
  199. *
  200. * Purpose: This function is a hook used by the Views module. It populates and
  201. * returns a data array that specifies for the Views module the base table,
  202. * the tables it joins with and handlers. The data array is populated
  203. * using the data stored in the tripal_views tables.
  204. *
  205. * @return a data array formatted for the Views module
  206. *
  207. * @ingroup tripal_views
  208. */
  209. function tripal_views_views_data() {
  210. // Make sure all chado tables are integrated
  211. tripal_views_integrate_all_chado_tables();
  212. // Define Global Fields
  213. // Filter handler that lets the admin say:
  214. // "Show no results until they enter search parameters"
  215. $data['views']['search_results'] = array(
  216. 'title' => t('Search Results'),
  217. 'help' => t('Delay results until Apply/Search is clicked by the user.'),
  218. 'filter' => array(
  219. 'handler' => 'tripal_views_handler_filter_no_results',
  220. ),
  221. );
  222. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  223. while ($tvi_row = db_fetch_object($tvi_query)) {
  224. // check to see if this is the lightest (drupal-style) priority setup for this table
  225. // if not then don't use this definition
  226. $lightest_priority_setup = tripal_views_is_lightest_priority_setup($tvi_row->setup_id, $tvi_row->table_name);
  227. if (!$lightest_priority_setup) {
  228. continue;
  229. }
  230. // ids we'll use for queries
  231. $setup_id = $tvi_row->setup_id;
  232. $mview_id = $tvi_row->mview_id;
  233. // holds the base table name and fields
  234. $base_table = '';
  235. $base_fields = array();
  236. // indicated whether the current table is a base table or not
  237. $is_base_table = $tvi_row->base_table;
  238. // populate the base table name and fields. If an $mview_id is given
  239. // then get the materialized view info, otherwise get the Chado table info
  240. if ($mview_id) {
  241. // get the base table name from the materialized view
  242. $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
  243. $mview_table = db_fetch_object(db_query($sql, $mview_id));
  244. $base_table = $mview_table->name;
  245. // get the columns in this materialized view. They are separated by commas
  246. // where the first word is the column name and the rest is the type
  247. $columns = explode(",", $mview_table->mv_specs);
  248. foreach ($columns as $column) {
  249. $column = trim($column); // trim trailing and leading spaces
  250. preg_match("/^(.*?)\ (.*?)$/", $column, $matches);
  251. $column_name = $matches[1];
  252. $column_type = $matches[2];
  253. $base_fields[$column_name] = array(
  254. 'column_name' => $column_name,
  255. 'type' => $column_type,
  256. );
  257. }
  258. // get the field name and descriptions
  259. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
  260. $query = db_query($sql, $setup_id);
  261. while ($field = db_fetch_object($query)) {
  262. $base_fields[$field->column_name]['name'] = $field->name;
  263. $base_fields[$field->column_name]['help'] = $field->description;
  264. }
  265. }
  266. // if this is not a legacy materialized view
  267. else {
  268. $base_table = $tvi_row->table_name;
  269. // Check if we are trying to integrate the node table
  270. // if we are we want to add to a current integration
  271. // as compared to create a whole new one
  272. if ($base_table == 'node') {
  273. // Add any joins between the node table and other tables
  274. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  275. $joins = db_query($sql, $setup_id);
  276. while ($join = db_fetch_object($joins)) {
  277. $left_table = $join->left_table;
  278. $left_field = $join->left_field;
  279. $base_field = $join->base_field;
  280. $handler = $join->handler;
  281. // add join entry
  282. $data[$base_table]['table']['join'][$left_table] = array(
  283. 'left_field' => $left_field,
  284. 'field' => $base_field,
  285. );
  286. if ($handler) {
  287. $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
  288. }
  289. }
  290. // Add in any handlers for node fields
  291. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d";
  292. $query = db_query($sql, $setup_id);
  293. while ($handler = db_fetch_object($query)) {
  294. $data[$base_table][$handler->column_name][$handler->handler_type]['handler'] = $handler->handler_name;
  295. // Add in any additional arguments
  296. // This should be a serialized array including (at a minimum) name => <handler name>
  297. if ($handler->arguments) {
  298. $data[$base_table][$handler->column_name][$handler->handler_type] = array_merge($data[$base_table][$handler->column_name][$handler->handler_type], unserialize($handler->arguments));
  299. }
  300. }
  301. continue;
  302. }
  303. // get the table description
  304. $table_desc = tripal_core_get_chado_table_schema($base_table);
  305. $fields = $table_desc['fields'];
  306. if (!is_array($fields)) {
  307. $fields = array();
  308. watchdog('tripal_views', 'No fields were described for this table (%table) through the Tripal Schema API.', array('%table' => $base_table), WATCHDOG_ERROR);
  309. }
  310. foreach ($fields as $column => $attrs) {
  311. $base_fields[$column] = array(
  312. 'column_name' => $column,
  313. 'type' => $attrs['type'],
  314. );
  315. }
  316. // get the field name and descriptions
  317. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
  318. $query = db_query($sql, $setup_id);
  319. while ($field = db_fetch_object($query)) {
  320. $base_fields[$field->column_name]['name'] = $field->name;
  321. $base_fields[$field->column_name]['help'] = $field->description;
  322. }
  323. }
  324. // Setup the base table info in the data array
  325. $data[$base_table]['table']['group'] = t("$tvi_row->name");
  326. if ($is_base_table) {
  327. $data[$base_table]['table']['base'] = array(
  328. 'group' => "$tvi_row->name",
  329. 'title' => "$tvi_row->name",
  330. 'help' => $tvi_row->comment,
  331. );
  332. }
  333. else {
  334. $data[$base_table]['table'] = array(
  335. 'group' => "$tvi_row->name",
  336. 'title' => "$tvi_row->name",
  337. 'help' => $tvi_row->comment,
  338. );
  339. }
  340. // first add the fields
  341. foreach ($base_fields as $column_name => $base_field) {
  342. $data[$base_table][$column_name] = array(
  343. 'title' => t($base_field['name']),
  344. 'help' => t($base_field['help']),
  345. 'field' => array(
  346. 'click sortable' => TRUE,
  347. ),
  348. );
  349. // now add the handlers
  350. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
  351. $handlers = db_query($sql, $setup_id, $column_name);
  352. while ($handler = db_fetch_object($handlers)) {
  353. $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
  354. // Add in any additional arguments
  355. // This should be a serialized array including (at a minimum) name => <handler name>
  356. if ($handler->arguments) {
  357. $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
  358. }
  359. };
  360. }
  361. // now add the joins
  362. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  363. $joins = db_query($sql, $setup_id);
  364. if (!isset($joins)) {
  365. $joins = array();
  366. }
  367. while ($join = db_fetch_object($joins)) {
  368. $left_table = $join->left_table;
  369. $left_field = $join->left_field;
  370. $base_field = $join->base_field;
  371. $handler = $join->handler;
  372. // add join entry
  373. $data[$base_table]['table']['join'][$left_table] = array(
  374. 'left_field' => $left_field,
  375. 'field' => $base_field,
  376. );
  377. if ($handler) {
  378. $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
  379. }
  380. }
  381. }
  382. // TEMPORARY: needed to join chado base tables to node linking tables
  383. // currently done using old-style data arrays
  384. //$data = tripal_views_TEMPORARY_chado_linking_data($data);
  385. return $data;
  386. }
  387. /**
  388. *
  389. * @ingroup tripal_views
  390. */
  391. function tripal_views_views_data_alter(&$data) {
  392. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  393. // iterate through the views that we manage
  394. while ($tvi_row = db_fetch_object($tvi_query)) {
  395. //ids we'll use for queries
  396. $mview_id = $tvi_row->mview_id;
  397. $setup_id = $tvi_row->setup_id;
  398. // iterate through the columns and alter the existing data array for
  399. // joins to other tables
  400. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  401. $joins = db_query($sql, $setup_id);
  402. while ($join = db_fetch_object($joins)) {
  403. $left_table = $join->left_table;
  404. $left_field = $join->left_field;
  405. $base_field = $join->base_field;
  406. $base_table = $join->base_table;
  407. // add the recipricol join entries for each column
  408. if (array_key_exists($left_table, $data)) {
  409. $data[$left_table]['table']['join'][$base_table] = array(
  410. 'left_field' => $base_field,
  411. 'field' => $left_field,
  412. );
  413. }
  414. }
  415. }
  416. return $data;
  417. }
  418. /**
  419. * Implementation of hook_views_plugins().
  420. */
  421. function tripal_views_views_plugins() {
  422. $tc_path = drupal_get_path('module', 'tripal_views');
  423. $style_defaults = array(
  424. 'path' => $tc_path . '/views_data_export/plugins',
  425. 'parent' => 'views_data_export',
  426. 'theme' => 'views_data_export',
  427. 'theme path' => $tc_path . '/views_data_export/theme',
  428. 'theme file' => 'tripal_views_data_export.theme.inc',
  429. 'uses row plugin' => FALSE,
  430. 'uses fields' => TRUE,
  431. 'uses options' => TRUE,
  432. 'type' => 'data_export',
  433. );
  434. // add FASTA format as a new style for the existing views_export_data Display
  435. return array(
  436. 'style' => array(
  437. 'views_data_export_fasta' => array(
  438. 'title' => t('FASTA file'),
  439. 'help' => t('Display results in FASTA format. All fields in results are on the definition line while the feature.residues field must be present .'),
  440. 'handler' => 'tripal_views_plugin_style_export_fasta',
  441. // Views Data Export element that will be used to set additional headers when serving the feed.
  442. 'export headers' => array('Content-type: text/plain; charset=utf-8'),
  443. // Views Data Export element mostly used for creating some additional classes and template names.
  444. 'export feed type' => 'fasta',
  445. 'export feed text' => 'FASTA',
  446. 'export feed file' => '%view.fna',
  447. 'export feed icon' => $tc_path . '/views_data_export/images/fasta.png',
  448. 'additional themes' => array(
  449. 'views_data_export_fasta_header' => 'style',
  450. 'views_data_export_fasta_body' => 'style',
  451. 'views_data_export_fasta_footer' => 'style',
  452. ),
  453. 'additional themes base' => 'views_data_export_fasta',
  454. ) + $style_defaults,
  455. ),
  456. );
  457. }
  458. /**
  459. * Implementation of hook_views_pre_view().
  460. */
  461. function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
  462. // merge the $_GET and $_POST into the $_GET. This is because
  463. // Views and Views Data Export modules only uses the $_GET variable but
  464. // file uploads require $_POST. We need to make sure these two modules
  465. // have access to everything needed for this view to work properlys
  466. $_GET = array_merge($_GET, $_POST);
  467. }
  468. /**
  469. * Implementation of hook_views_pre_build().
  470. */
  471. /* function tripal_views_views_pre_render(&$view, &$display_id, &$args){
  472. // we want to add to the bottom of the views the form for downloading
  473. // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
  474. // Export module provides small images at the bottom, but we want to provide
  475. // a more intutitive interface for getting different file formats
  476. $form = drupal_get_form('tripal_views_data_export_download_form',$view,$display_id,$args);
  477. $view->attachment_after = $form;
  478. }*/
  479. /*
  480. *
  481. function tripal_views_views_query_alter(&$view, &$query){
  482. // iterate through the tables and see if they are chado tables.
  483. // if they are then prefix them with a "chado." prefix
  484. dpm($query);
  485. $tables = $query->tables;
  486. foreach ($tables as $base => $subtables) {
  487. $desc = tripal_core_get_chado_table_schema($base);
  488. if ($desc) {
  489. $query->tables["chado." . $base] = $subtables;
  490. unset($query->tables[$base]);
  491. $base = "chado." . $base;
  492. }
  493. foreach ($subtables as $subtable => $values) {
  494. $desc = tripal_core_get_chado_table_schema($subtable);
  495. if ($desc) {
  496. $query->tables[$base]["chado." . $subtable] = $values;
  497. unset($query->tables[$base][$subtable]);
  498. }
  499. }
  500. }
  501. dpm($query);
  502. } */
  503. /**
  504. * Implementation of hook_views_pre_execute().
  505. */
  506. function tripal_views_views_pre_execute(&$view) {
  507. // if the base table is a chado table then we want to set the
  508. // search path so it can find all of the tables.
  509. // this will break views that use tables that have the same name
  510. // as chado tables (e.g. contact).
  511. $desc = tripal_core_get_chado_table_schema($view->base_table);
  512. if ($desc) {
  513. tripal_db_set_chado_search_path('chado');
  514. }
  515. }
  516. /**
  517. * Implementation of hook_views_post_render().
  518. */
  519. function tripal_views_views_post_render(&$view, &$output, &$cache) {
  520. // if the base table and the query is completed we want to set
  521. // the search path back to the default.
  522. $desc = tripal_core_get_chado_table_schema($view->base_table);
  523. if ($desc) {
  524. tripal_db_set_default_search_path();
  525. }
  526. }
  527. /**
  528. * the Download Views data export form
  529. */
  530. function tripal_views_data_export_download_form(&$form_state, $view, $display_id, $args) {
  531. $form = array();
  532. $urls = array();
  533. // get any export_data_export displays
  534. $displays = $view->display;
  535. $options = array();
  536. $default = '';
  537. $current_display = $view->current_display;
  538. foreach ($displays as $name => $display) {
  539. if (preg_match("/^views_data_export/", $name)) {
  540. // only add this display to the form if it is attached
  541. $display_options = $display->display_options;
  542. if (strcmp($display_options['displays'][$current_display], $current_display) != 0) {
  543. continue;
  544. }
  545. // set the first item as default
  546. if (!$default) {
  547. $default = $display->id;
  548. }
  549. $path = $display->display_options['path'];
  550. $query = $view->get_exposed_input(); // retrieves elements in $_GET array
  551. $urls[$display->id]['path'] = $path;
  552. $urls[$display->id]['query'] = $query;
  553. // add the new item to the options array
  554. $options[$display->id] = $display->display_title;
  555. }
  556. }
  557. // only generate the form if we have views_data_export displays attached
  558. // to this view
  559. if (count($options) > 0) {
  560. $form_state['storage']['urls'] = $urls;
  561. $form['#cache'] = TRUE;
  562. // we want the form to redirect to a new window
  563. $form['#attributes']['target'] = "_blank";
  564. // now build the form elements
  565. $form['downloads'] = array(
  566. '#type' => 'fieldset',
  567. '#title' => 'Download Results',
  568. '#collapsible' => TRUE,
  569. '#collapsed' => FALSE
  570. );
  571. $form['downloads']['file_type'] = array(
  572. '#title' => t('File format'),
  573. '#type' => 'radios',
  574. '#options' => $options,
  575. '#required' => TRUE,
  576. '#default_value' => $default,
  577. '#description' => t('Please select a file format to download'),
  578. );
  579. $form['downloads']['submit'] = array(
  580. '#value' => t('Download Results'),
  581. '#type' => 'submit',
  582. );
  583. }
  584. return $form;
  585. }
  586. /**
  587. * Submit for the Download Views data export form
  588. */
  589. function tripal_views_data_export_download_form_submit($form, &$form_state) {
  590. $urls = $form_state['storage']['urls'];
  591. $display_id = $form_state['values']['file_type'];
  592. drupal_goto($urls[$display_id]['path'], $urls[$display_id]['query']);
  593. }