tripal_views.views.inc 23 KB

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