tripal_core.views.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php
  2. include('views/handlers/views_handler_join_chado_through_linking.inc');
  3. include('views/handlers/views_handler_join_chado_aggregator.inc');
  4. /**
  5. * @defgroup views Views Integration
  6. * @{
  7. * Provide rules for formatting and composition of fields
  8. * @}
  9. */
  10. /**
  11. * @defgroup views_field_handlers Views Field Handlers
  12. * @{
  13. * Provide rules for formatting and composition of fields
  14. * @}
  15. * @ingroup views
  16. */
  17. /**
  18. * @defgroup views_filter_handlers Views Filter Handlers
  19. * @{
  20. * Provide the ability to filter based on specified data
  21. * @}
  22. * @ingroup views
  23. */
  24. /**
  25. * @defgroup views_sort_handlers Views Sort Handlers
  26. * @{
  27. * Provide methods describing how specific data should be sorted
  28. * @}
  29. * @ingroup views
  30. */
  31. /**
  32. * @defgroup views_argument_handlers Views Arguement Handlers
  33. * @{
  34. * Provide the ability to filter pased on arguments in the path of the view
  35. * @}
  36. * @ingroup views
  37. */
  38. /**
  39. * Implements hook_views_handlers()
  40. *
  41. * Purpose: Register all custom handlers with views
  42. * where a handler describes either "the type of field",
  43. * "how a field should be filtered", "how a field should be sorted"
  44. *
  45. * @return
  46. * An array of handler definitions
  47. *
  48. * @ingroup tripal_core
  49. */
  50. function tripal_core_views_handlers() {
  51. return array(
  52. 'info' => array(
  53. 'path' => drupal_get_path('module', 'tripal_core') . '/views/handlers',
  54. ),
  55. 'handlers' => array(
  56. // Custom Chado Handlers
  57. 'chado_views_handler_field_aggregate' => array(
  58. 'parent' => 'chado_views_handler_field',
  59. ),
  60. 'views_handler_filter_chado_select_string' => array(
  61. 'parent' => 'views_handler_filter_string',
  62. ),
  63. 'views_handler_filter_chado_select_cvterm_name' => array(
  64. 'parent' => 'views_handler_filter_string',
  65. ),
  66. // Other Custom Handlers
  67. 'views_handler_filter_no_results' => array(
  68. 'parent' => 'views_handler_filter'
  69. ),
  70. // Old Handlers
  71. 'views_handler_field_node_optional' => array(
  72. 'parent' => 'views_handler_field_node',
  73. ),
  74. 'views_handler_field_cvterm_name' => array(
  75. 'parent' => 'views_handler_field',
  76. ),
  77. 'views_handler_field_chado_tf_boolean' => array(
  78. 'parent' => 'views_handler_field_boolean',
  79. ),
  80. 'views_handler_field_chado_count' => array(
  81. 'parent' => 'views_handler_field',
  82. ),
  83. 'views_handler_filter_chado_boolean' => array(
  84. 'parent' => 'views_handler_filter_boolean_operator',
  85. ),
  86. 'views_handler_field_chado_rel_by_type' => array(
  87. 'parent' => 'views_handler_field_prerender_list',
  88. ),
  89. // Wrappers for Default Views Handlers-----
  90. // Field Handlers
  91. 'chado_views_handler_field' => array(
  92. 'parent' => 'views_handler_field'
  93. ),
  94. 'chado_views_handler_field_boolean' => array(
  95. 'parent' => 'views_handler_field_boolean'
  96. ),
  97. 'chado_views_handler_field_counter' => array(
  98. 'parent' => 'views_handler_field_counter'
  99. ),
  100. 'chado_views_handler_field_custom' => array(
  101. 'parent' => 'views_handler_field_custom'
  102. ),
  103. 'chado_views_handler_field_date' => array(
  104. 'parent' => 'views_handler_field_date'
  105. ),
  106. 'chado_views_handler_field_markup' => array(
  107. 'parent' => 'views_handler_field_markup'
  108. ),
  109. 'chado_views_handler_field_math' => array(
  110. 'parent' => 'views_handler_field_math'
  111. ),
  112. 'chado_views_handler_field_numeric' => array(
  113. 'parent' => 'views_handler_field_numeric'
  114. ),
  115. // Filter Handlers
  116. 'chado_views_handler_filter_string' => array(
  117. 'parent' => 'views_handler_filter_string',
  118. ),
  119. 'chado_views_handler_filter_boolean_operator_string' => array(
  120. 'parent' => 'views_handler_filter_boolean_operator_string',
  121. ),
  122. 'chado_views_handler_filter_boolean_operator' => array(
  123. 'parent' => 'views_handler_filter_boolean_operator',
  124. ),
  125. 'chado_views_handler_filter_date' => array(
  126. 'parent' => 'views_handler_filter_date',
  127. ),
  128. 'chado_views_handler_filter_equality' => array(
  129. 'parent' => 'views_handler_filter_equality',
  130. ),
  131. 'chado_views_handler_filter_float' => array(
  132. 'parent' => 'views_handler_filter_float',
  133. ),
  134. 'chado_views_handler_filter_numeric' => array(
  135. 'parent' => 'views_handler_filter_numeric',
  136. ),
  137. 'views_handler_filter_file_upload' => array(
  138. 'parent' => 'views_handler_filter',
  139. ),
  140. // Sort Handlers
  141. 'chado_views_handler_sort' => array(
  142. 'parent' => 'views_handler_sort'
  143. ),
  144. 'chado_views_handler_sort_date' => array(
  145. 'parent' => 'views_handler_sort_date'
  146. ),
  147. 'chado_views_handler_sort_formula' => array(
  148. 'parent' => 'views_handler_sort_formula'
  149. ),
  150. 'chado_views_handler_sort_menu_hierarchy' => array(
  151. 'parent' => 'views_handler_sort_menu_hierarchy'
  152. ),
  153. 'chado_views_handler_sort_random' => array(
  154. 'parent' => 'views_handler_sort_random'
  155. ),
  156. ),
  157. );
  158. }
  159. /**
  160. * Implements hook_views_pre_render
  161. *
  162. * Purpose: Intercepts the view after the query has been executed
  163. * All the results are stored in $view->result
  164. * Looking up the NID here ensures the query is only executed once
  165. * for all stocks in the table.
  166. *
  167. * @todo add if !<chado/drupal same db> around NID portion
  168. *
  169. * @ingroup tripal_core
  170. */
  171. function tripal_core_views_pre_render (&$view) {
  172. //Add Node IDs in to every table that needs them
  173. // @see file: tripal_core.views.inc
  174. tripal_core_add_node_ids_to_view ($view);
  175. }
  176. /**
  177. * Adds nid fields to all pertinent view results
  178. *
  179. * Purpose: To add basetable_nid fields to all result arrays of a view
  180. * only if the basetable_nid field is added. This function will only be
  181. * called if chado/drupal are not in the same database (ie: only if
  182. * a join between the base and node table isn't possible.
  183. *
  184. * Note: Supports adding Node IDs to analysis, feature, library, organism, stock
  185. *
  186. * @param $view
  187. * the view object passed to hook_views_pre_render
  188. *
  189. * @return the views object with nids added to the result array
  190. *
  191. * @ingroup tripal_core
  192. */
  193. function tripal_core_add_node_ids_to_view (&$view) {
  194. //-----Analysis----------------------------------------------
  195. if (!empty($view->field['analysis_nid'])) {
  196. // retrieve the analysis_id for each record in the views current page
  197. $analysis_ids = array();
  198. foreach ($view->result as $row_num => $row) {
  199. if (!empty($row->analysis_id)) {
  200. //we're looking at analysis id field already in table
  201. $analysis_ids[$row_num] = $row->analysis_id;
  202. } else {
  203. //we're looking at analysis id added by field handler
  204. $analysis_ids[$row_num] = $row->analysis_analysis_id;
  205. }
  206. }
  207. $unique_analysis_ids = array_filter($analysis_ids);
  208. $unique_analysis_ids = array_unique($unique_analysis_ids);
  209. if (!empty($unique_analysis_ids)) {
  210. // Using the list of analysis_ids from the view
  211. // lookup the NIDs from drupal
  212. // and add that to the results of the view
  213. $sql = "SELECT nid, analysis_id FROM {chado_analysis} WHERE analysis_id IN (".implode(',',$unique_analysis_ids).")";
  214. $resource = db_query($sql);
  215. while ($r = db_fetch_object($resource)) {
  216. $keys = array_keys($analysis_ids, $r->analysis_id);
  217. foreach ($keys as $k) {
  218. $view->result[$k]->analysis_nid = $r->nid;
  219. }
  220. }
  221. } // if there are any analysis'
  222. } //end of case for analysis NID
  223. //-----Feature-----------------------------------------------
  224. if (!empty($view->field['feature_nid'])) {
  225. // retrieve the feature_id for each record in the views current page
  226. $feature_ids = array();
  227. foreach ($view->result as $row_num => $row) {
  228. if (!empty($row->feature_id)) {
  229. //we're looking at feature id field already in table
  230. $feature_ids[$row_num] = $row->feature_id;
  231. } else {
  232. //we're looking at feature id added by field handler
  233. $feature_ids[$row_num] = $row->feature_feature_id;
  234. }
  235. }
  236. $unique_feature_ids = array_filter($feature_ids);
  237. $unique_feature_ids = array_unique($unique_feature_ids);
  238. if (!empty($unique_feature_ids)) {
  239. // Using the list of feature_ids from the view
  240. // lookup the NIDs from drupal
  241. // and add that to the results of the view
  242. $sql = "SELECT nid, feature_id FROM {chado_feature} WHERE feature_id IN (".implode(',',$unique_feature_ids).")";
  243. $resource = db_query($sql);
  244. while ($r = db_fetch_object($resource)) {
  245. $keys = array_keys($feature_ids, $r->feature_id);
  246. foreach ($keys as $k) {
  247. $view->result[$k]->feature_nid = $r->nid;
  248. }
  249. }
  250. } // if there are any features
  251. } //end of case for feature NID
  252. //-----Library-----------------------------------------------
  253. if (!empty($view->field['library_nid'])) {
  254. // retrieve the library_id for each record in the views current page
  255. $library_ids = array();
  256. foreach ($view->result as $row_num => $row) {
  257. if (!empty($row->library_id)) {
  258. //we're looking at library id field already in table
  259. $library_ids[$row_num] = $row->library_id;
  260. } else {
  261. //we're looking at library id added by field handler
  262. $library_ids[$row_num] = $row->library_library_id;
  263. }
  264. }
  265. $unique_library_ids = array_filter($library_ids);
  266. $unique_library_ids = array_unique($unique_library_ids);
  267. if (!empty($unique_library_ids)) {
  268. // Using the list of library_ids from the view
  269. // lookup the NIDs from drupal
  270. // and add that to the results of the view
  271. $sql = "SELECT nid, library_id FROM {chado_library} WHERE library_id IN (".implode(',',$unique_library_ids).")";
  272. $resource = db_query($sql);
  273. while ($r = db_fetch_object($resource)) {
  274. $keys = array_keys($library_ids, $r->library_id);
  275. foreach ($keys as $k) {
  276. $view->result[$k]->library_nid = $r->nid;
  277. }
  278. }
  279. } // if there are libraries
  280. } //end of case for library NID
  281. //-----Organism----------------------------------------------
  282. if (!empty($view->field['organism_nid'])) {
  283. // retrieve the organism_id for each record in the views current page
  284. $organism_ids = array();
  285. foreach ($view->result as $row_num => $row) {
  286. if (!empty($row->organism_id)) {
  287. //we're looking at organism id field already in table
  288. $organism_ids[$row_num] = $row->organism_id;
  289. } else {
  290. //we're looking at organism id added by field handler
  291. $organism_ids[$row_num] = $row->organism_organism_id;
  292. }
  293. }
  294. $unique_organism_ids = array_filter($organism_ids);
  295. $unique_organism_ids = array_unique($unique_organism_ids);
  296. if (!empty($unique_organism_ids)) {
  297. // Using the list of organism_ids from the view
  298. // lookup the NIDs from drupal
  299. // and add that to the results of the view
  300. $sql = "SELECT nid, organism_id FROM {chado_organism} WHERE organism_id IN (".implode(',',$unique_organism_ids).")";
  301. $resource = db_query($sql);
  302. while ($r = db_fetch_object($resource)) {
  303. $keys = array_keys($organism_ids, $r->organism_id);
  304. foreach ($keys as $k) {
  305. $view->result[$k]->organism_nid = $r->nid;
  306. }
  307. }
  308. } // if there are organisms
  309. } //end of case for organism NID
  310. //-----Stock-------------------------------------------------
  311. if (!empty($view->field['stock_nid'])) {
  312. // retrieve the stock_id for each record in the views current page
  313. $stock_ids = array();
  314. foreach ($view->result as $row_num => $row) {
  315. if (!empty($row->stock_id)) {
  316. //we're looking at stock id field already in table
  317. $stock_ids[$row_num] = $row->stock_id;
  318. } else {
  319. //we're looking at stock id added by field handler
  320. $stock_ids[$row_num] = $row->stock_stock_id;
  321. }
  322. }
  323. $unique_stock_ids = array_filter($stock_ids);
  324. $unique_stock_ids = array_unique($unique_stock_ids);
  325. if (!empty($unique_stock_ids)) {
  326. // Using the list of stock_ids from the view
  327. // lookup the NIDs from drupal
  328. // and add that to the results of the view
  329. $sql = "SELECT nid, stock_id FROM {chado_stock} WHERE stock_id IN (".implode(',',$unique_stock_ids).")";
  330. $resource = db_query($sql);
  331. while ($r = db_fetch_object($resource)) {
  332. $keys = array_keys($stock_ids, $r->stock_id);
  333. foreach ($keys as $k) {
  334. $view->result[$k]->stock_nid = $r->nid;
  335. }
  336. }
  337. } //if there are stocks
  338. } //end of case for stock NID
  339. return $view;
  340. }
  341. /**
  342. *
  343. * @ingroup tripal_core
  344. */
  345. function tripal_core_views_data(){
  346. // Define Global Fields -------------
  347. // Filter handler that lets the admin say:
  348. // "Show no results until they enter search parameters"
  349. $data['views']['search_results'] = array(
  350. 'title' => t('Search Results'),
  351. 'help' => t('Delay results until Apply/Search is clicked by the user.'),
  352. 'filter' => array(
  353. 'handler' => 'views_handler_filter_no_results',
  354. ),
  355. );
  356. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  357. while($tvi_row = db_fetch_object($tvi_query)){
  358. // ids we'll use for queries
  359. $setup_id = $tvi_row->setup_id;
  360. $mview_id = $tvi_row->mview_id;
  361. // holds the base table name and fields
  362. $base_table = '';
  363. $base_fields = array();
  364. $type_prefix = '';
  365. // populate the base table name and fields. If an $mview_id is given
  366. // the get the materialized view info, otherwise get the Chado table info
  367. if($mview_id){
  368. $type_prefix = 'MView';
  369. // get the base table name from the materialized view
  370. $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
  371. $mview_table = db_fetch_object(db_query($sql,$mview_id));
  372. $base_table = $mview_table->name;
  373. // get the columns in this materialized view. They are separated by commas
  374. // where the first word is the column name and the rest is the type
  375. $columns = explode(",",$mview_table->mv_specs);
  376. foreach ($columns as $column){
  377. $column = trim($column); // trim trailing and leading spaces
  378. preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
  379. $column_name = $matches[1];
  380. $column_type = $matches[2];
  381. $base_fields[] = $column_name;
  382. }
  383. }
  384. else {
  385. $type_prefix = 'Chado Table';
  386. $base_table = $tvi_row->table_name;
  387. $table_desc = module_invoke_all('chado_'.$base_table.'_schema');
  388. $fields = $table_desc['fields'];
  389. foreach($fields as $column => $attrs){
  390. $base_fields[] = $column;
  391. }
  392. }
  393. // Setup the base table info in the data array
  394. $data[$base_table]['table']['group'] = t("$type_prefix: $tvi_row->name");
  395. $data[$base_table]['table']['base'] = array(
  396. 'group' => "$type_prefix: $tvi_row->name",
  397. 'title' => "$type_prefix: $tvi_row->name",
  398. 'help' => $tvi_row->comment,
  399. );
  400. // first add the fields
  401. foreach ($base_fields as $base_field){
  402. $data[$base_table][$base_field] = array(
  403. 'title' => $base_field,
  404. 'help' => t("The $base_field from the $base_table table (added by Tripal Views Integration)"),
  405. 'field' => array(
  406. 'click sortable' => TRUE,
  407. ),
  408. );
  409. // now add the handlers
  410. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
  411. $handlers = db_query($sql,$setup_id,$base_field);
  412. while($handler = db_fetch_object($handlers)){
  413. $data[$base_table][$base_field][$handler->handler_type]['handler'] = $handler->handler_name;
  414. };
  415. }
  416. // now add the joins
  417. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  418. $joins = db_query($sql,$setup_id);
  419. while($join = db_fetch_object($joins)){
  420. $left_table = $join->left_table;
  421. $left_field = $join->left_field;
  422. $base_field = $join->base_field;
  423. // add join entry
  424. $data[$base_table]['table']['join'][$left_table] = array(
  425. 'left_field' => $left_field,
  426. 'field' => $base_field,
  427. );
  428. // check to see if the join table is one that correlates with Drupal nodes
  429. // if so, there will be a chado_<table_name> table in the Drupal database
  430. // if there is, then we need to add the linking join information
  431. $sql = "SELECT tablename FROM pg_tables WHERE tablename = 'chado_$left_table'";
  432. if(db_fetch_object(db_query($sql))){
  433. // join the mview to the linker table
  434. $data[$base_table]['table']['join']["chado_$left_table"] = array(
  435. 'left_field' => $left_field,
  436. 'field' => $base_field,
  437. );
  438. }
  439. }
  440. }
  441. //dpm($data);
  442. return $data;
  443. }
  444. /**
  445. *
  446. * @ingroup tripal_core
  447. */
  448. function tripal_core_views_data_alter(&$data) {
  449. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  450. // iterate through the views that we manage
  451. while($tvi_row = db_fetch_object($tvi_query)){
  452. //ids we'll use for queries
  453. $mview_id = $tvi_row->mview_id;
  454. $setup_id = $tvi_row->setup_id;
  455. // iterate through the columns and alter the existing data array for
  456. // joins to other tables
  457. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  458. $joins = db_query($sql,$setup_id);
  459. while($join = db_fetch_object($joins)){
  460. $left_table = $join->left_table;
  461. $left_field = $join->left_field;
  462. $base_field = $join->base_field;
  463. $base_table = $join->base_table;
  464. // add the recipricol join entries for each column
  465. if(array_key_exists($left_table,$data)){
  466. $data[$left_table]['table']['join'][$base_table] = array(
  467. 'left_field' => $base_field,
  468. 'field' => $left_field,
  469. );
  470. }
  471. // check to see if this table is one that correlates with Drupal nodes
  472. // if so, there will be a chado_<table_name> table in the Drupal database
  473. // if there is, then we need to add the linking join information. We did
  474. // this step in the hook_views_data function above, but now we need
  475. // to add the reciprical joins
  476. $sql = "SELECT tablename FROM pg_tables WHERE tablename = '%s'";
  477. if(db_fetch_object(db_query($sql,"chado_$left_table"))){
  478. // join the linker table to the mview
  479. if(array_key_exists("chado_$left_table",$data)){
  480. $data["chado_$left_table"]['table']['join'][$base_table] = array(
  481. 'left_field' => $base_field,
  482. 'field' => $left_field,
  483. );
  484. // Join the node table to the view by way of the chado linker table
  485. $data['node']['table']['join'][$base_table] = array(
  486. 'left_table' => "chado_$left_table",
  487. 'left_field' => 'nid',
  488. 'field' => 'nid',
  489. );
  490. }
  491. }
  492. }
  493. }
  494. return $data;
  495. }
  496. /**
  497. * Implementation of hook_views_plugins().
  498. */
  499. function tripal_core_views_plugins() {
  500. $tc_path = drupal_get_path('module', 'tripal_core');
  501. $style_defaults = array(
  502. 'path' => $tc_path . '/views_data_export/plugins',
  503. 'parent' => 'views_data_export',
  504. 'theme' => 'views_data_export',
  505. 'theme path' => $tc_path . '/views_data_export/theme',
  506. 'theme file' => 'tripal_core_views_data_export.theme.inc',
  507. 'uses row plugin' => FALSE,
  508. 'uses fields' => TRUE,
  509. 'uses options' => TRUE,
  510. 'type' => 'data_export',
  511. );
  512. // add FASTA format as a new style for the existing views_export_data Display
  513. return array(
  514. 'style' => array(
  515. 'views_data_export_fasta' => array(
  516. 'title' => t('FASTA file'),
  517. 'help' => t('Display results in FASTA format. All fields in results are on the definition line while the feature.residues field must be present .'),
  518. 'handler' => 'tripal_core_plugin_style_export_fasta',
  519. // Views Data Export element that will be used to set additional headers when serving the feed.
  520. 'export headers' => array('Content-type: text/plain; charset=utf-8'),
  521. // Views Data Export element mostly used for creating some additional classes and template names.
  522. 'export feed type' => 'fasta',
  523. 'export feed text' => 'FASTA',
  524. 'export feed file' => '%view.fna',
  525. 'export feed icon' => $tc_path . '/views_data_export/images/fasta.png',
  526. 'additional themes' => array(
  527. 'views_data_export_fasta_header' => 'style',
  528. 'views_data_export_fasta_body' => 'style',
  529. 'views_data_export_fasta_footer' => 'style',
  530. ),
  531. 'additional themes base' => 'views_data_export_fasta',
  532. ) + $style_defaults,
  533. ),
  534. );
  535. }
  536. /**
  537. * Implementation of hook_views_pre_view().
  538. */
  539. function tripal_core_views_pre_view(&$view,&$display_id,&$args){
  540. $form = drupal_get_form('tripal_core_views_data_export_download_form',$view,$display_id,$args);
  541. $view->attachment_after = $form;
  542. }
  543. /**
  544. *
  545. */
  546. function tripal_core_views_data_export_download_form(&$form_state, $view,$display_id,$args){
  547. $form = array();
  548. $urls = array();
  549. // get any export_data_export displays
  550. $displays = $view->display;
  551. $options = array();
  552. $default = '';
  553. foreach($displays as $name => $display){
  554. if(preg_match("/^views_data_export/",$name)){
  555. // set the first item as default
  556. if(!$default){
  557. $default = $display->id;
  558. }
  559. // add the data export URL to the URLs array
  560. $query = $view->get_exposed_input();
  561. $path = $display->display_options['path'];
  562. $urls[$display->id]['path'] = $path;
  563. $urls[$display->id]['query'] = $query;
  564. // add the new item to the options array
  565. $options[$display->id] = $display->display_title;
  566. }
  567. }
  568. // only generate the form if we have views_data_export displays attached
  569. // to this view
  570. if(count($options) > 0){
  571. $form_state['storage']['urls'] = $urls;
  572. $form['#cache'] = TRUE;
  573. // we want the form to redirect to a new window
  574. $form['#attributes']['target'] = "_blank";
  575. // now build the form elements
  576. $form['downloads'] = array(
  577. '#type' => 'fieldset',
  578. '#title' => 'Download Results',
  579. '#collapsible' => TRUE,
  580. '#collapsed' => FALSE
  581. );
  582. $form['downloads']['file_type'] = array(
  583. '#title' => t('File format'),
  584. '#type' => 'radios',
  585. '#options' => $options,
  586. '#required' => TRUE,
  587. '#default_value' => $default,
  588. '#description' => t('Please select a file format to download'),
  589. );
  590. $form['downloads']['submit'] = array(
  591. '#value' => t('Download Results'),
  592. '#type' => 'submit',
  593. );
  594. }
  595. return $form;
  596. }
  597. /**
  598. *
  599. */
  600. function tripal_core_views_data_export_download_form_submit($form, &$form_state){
  601. $urls = $form_state['storage']['urls'];
  602. $display_id = $form_state['values']['file_type'];
  603. drupal_goto($urls[$display_id]['path'],$urls[$display_id]['query']);
  604. }