123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815 |
- <?php
- include('views/handlers/views_handler_join_chado_through_linking.inc');
- include('views/handlers/views_handler_join_chado_aggregator.inc');
- include('tripal_views.api.inc');
- // TEMPORARY
- include('views/chado_linking.TMP.inc');
- /**
- * @file
- * Tripal Views Integration
- *
- * @defgroup views Views Integration
- * @{
- * Provide rules for formatting and composition of fields
- * @}
- *
- * @defgroup views_field_handlers Views Field Handlers
- * @{
- * Provide rules for formatting and composition of fields
- * @}
- * @ingroup views
- *
- * @defgroup views_filter_handlers Views Filter Handlers
- * @{
- * Provide the ability to filter based on specified data
- * @}
- * @ingroup views
- *
- * @defgroup views_sort_handlers Views Sort Handlers
- * @{
- * Provide methods describing how specific data should be sorted
- * @}
- * @ingroup views
- *
- * @defgroup views_argument_handlers Views Arguement Handlers
- * @{
- * Provide the ability to filter pased on arguments in the path of the view
- * @}
- * @ingroup views
- */
- /**
- * Implements hook_views_handlers()
- *
- * Purpose: Register all custom handlers with views
- * where a handler describes either "the type of field",
- * "how a field should be filtered", "how a field should be sorted"
- *
- * @return
- * An array of handler definitions
- *
- * @ingroup tripal_views
- */
- function tripal_views_views_handlers() {
- return array(
- 'info' => array(
- 'path' => drupal_get_path('module', 'tripal_views') . '/views/handlers',
- ),
- 'handlers' => array(
- // Custom Tripal Handlers
- 'views_handler_filter_file_upload' => array(
- 'parent' => 'views_handler_filter',
- ),
- 'tripal_views_handler_filter_string_selectbox' => array(
- 'parent' => 'views_handler_filter_string',
- ),
- 'views_handler_filter_no_results' => array(
- 'parent' => 'views_handler_filter'
- ),
- // Custom Chado Handlers
- 'chado_views_handler_field_aggregate' => array(
- 'parent' => 'chado_views_handler_field',
- ),
- 'chado_views_handler_filter_select_cvterm' => array(
- 'parent' => 'views_handler_filter_chado_select_cvterm_name',
- ),
- 'chado_views_handler_filter_select_string' => array(
- 'parent' => 'chado_views_handler_filter_string',
- ),
- // Join Handlers
- 'views_handler_join_chado_aggregator' => array(
- 'parent' => 'views_join',
- ),
- 'views_handler_join_chado_through_linking' => array(
- 'parent' => 'views_join',
- ),
- // Relationship Handlers
- 'chado_views_handler_relationship' => array(
- 'parent' => 'views_handler_relationship'
- ),
- // Old Handlers no longer used (deprecated)
- 'views_handler_field_node_optional' => array(
- 'parent' => 'views_handler_field_node',
- ),
- 'views_handler_field_chado_tf_boolean' => array(
- 'parent' => 'views_handler_field_boolean',
- ),
- 'views_handler_field_chado_count' => array(
- 'parent' => 'views_handler_field',
- ),
- 'views_handler_filter_chado_boolean' => array(
- 'parent' => 'views_handler_filter_boolean_operator',
- ),
- 'views_handler_field_dbxref_accession_link' => array(
- 'parent' => 'views_handler_field',
- ),
- 'views_handler_field_readable_date' => array(
- 'parent' => 'views_handler_field',
- ),
- // Old handlers with new counterparts (deprecated)
- 'views_handler_filter_chado_select_string' => array(
- 'parent' => 'views_handler_filter_string',
- ),
- 'views_handler_filter_chado_select_cvterm_name' => array(
- 'parent' => 'views_handler_filter_string',
- ),
- // Wrappers for Default Views Handlers-----
- // Field Handlers
- 'chado_views_handler_field' => array(
- 'parent' => 'views_handler_field'
- ),
- 'chado_views_handler_field_boolean' => array(
- 'parent' => 'views_handler_field_boolean'
- ),
- 'chado_views_handler_field_counter' => array(
- 'parent' => 'views_handler_field_counter'
- ),
- 'chado_views_handler_field_custom' => array(
- 'parent' => 'views_handler_field_custom'
- ),
- 'chado_views_handler_field_date' => array(
- 'parent' => 'views_handler_field_date'
- ),
- 'chado_views_handler_field_markup' => array(
- 'parent' => 'views_handler_field_markup'
- ),
- 'chado_views_handler_field_math' => array(
- 'parent' => 'views_handler_field_math'
- ),
- 'chado_views_handler_field_numeric' => array(
- 'parent' => 'views_handler_field_numeric'
- ),
- // Filter Handlers
- 'chado_views_handler_filter_string' => array(
- 'parent' => 'views_handler_filter_string',
- ),
- 'chado_views_handler_filter_boolean_operator_string' => array(
- 'parent' => 'views_handler_filter_boolean_operator_string',
- ),
- 'chado_views_handler_filter_boolean_operator' => array(
- 'parent' => 'views_handler_filter_boolean_operator',
- ),
- 'chado_views_handler_filter_date' => array(
- 'parent' => 'views_handler_filter_date',
- ),
- 'chado_views_handler_filter_equality' => array(
- 'parent' => 'views_handler_filter_equality',
- ),
- 'chado_views_handler_filter_float' => array(
- 'parent' => 'views_handler_filter_float',
- ),
- 'chado_views_handler_filter_numeric' => array(
- 'parent' => 'views_handler_filter_numeric',
- ),
- // Sort Handlers
- 'chado_views_handler_sort' => array(
- 'parent' => 'views_handler_sort'
- ),
- 'chado_views_handler_sort_date' => array(
- 'parent' => 'views_handler_sort_date'
- ),
- 'chado_views_handler_sort_formula' => array(
- 'parent' => 'views_handler_sort_formula'
- ),
- 'chado_views_handler_sort_menu_hierarchy' => array(
- 'parent' => 'views_handler_sort_menu_hierarchy'
- ),
- 'chado_views_handler_sort_random' => array(
- 'parent' => 'views_handler_sort_random'
- ),
- ),
- );
- }
- /**
- * Implements hook_views_pre_render
- *
- * Purpose: Intercepts the view after the query has been executed
- * All the results are stored in $view->result
- * Looking up the NID here ensures the query is only executed once
- * for all stocks in the table.
- *
- * @todo add if !<chado/drupal same db> around NID portion
- *
- * @ingroup tripal_views
- */
- function tripal_views_views_pre_render(&$view) {
- //Add Node IDs in to every table that needs them
- // @see tripal_views.views.inc
- tripal_views_add_node_ids_to_view($view);
- // We need to unset the exposed_input for the view so we can repopulate that
- // variable. This is necessary if we're using the file_upload_combo
- // custom form element which adds the file_path variable to the $_GET after the
- // view has populated the $view->exposed_input variable
- unset($view->exposed_input);
- // we want to add to the bottom of the views the form for downloading
- // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
- // Export module provides small images at the bottom, but we want to provide
- // a more intutitive interface for getting different file formats
- $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
- $view->attachment_after = $form;
- }
- /**
- * Adds nid fields to all pertinent view results
- *
- * Purpose: To add basetable_nid fields to all result arrays of a view
- * only if the basetable_nid field is added. This function will only be
- * called if chado/drupal are not in the same database (ie: only if
- * a join between the base and node table isn't possible.
- *
- * Note: Supports adding Node IDs to analysis, feature, library, organism, stock
- *
- * @param $view
- * the view object passed to hook_views_pre_render
- *
- * @return the views object with nids added to the result array
- *
- * @ingroup tripal_views
- */
- function tripal_views_add_node_ids_to_view(&$view) {
- //-----Analysis----------------------------------------------
- if (!empty($view->field['analysis_nid'])) {
- // retrieve the analysis_id for each record in the views current page
- $analysis_ids = array();
- foreach ($view->result as $row_num => $row) {
- if (!empty($row->analysis_id)) {
- //we're looking at analysis id field already in table
- $analysis_ids[$row_num] = $row->analysis_id;
- }
- else {
- //we're looking at analysis id added by field handler
- $analysis_ids[$row_num] = $row->analysis_analysis_id;
- }
- }
- $unique_analysis_ids = array_filter($analysis_ids);
- $unique_analysis_ids = array_unique($unique_analysis_ids);
- if (!empty($unique_analysis_ids)) {
- // Using the list of analysis_ids from the view
- // lookup the NIDs from drupal
- // and add that to the results of the view
- $sql = "SELECT nid, analysis_id FROM {chado_analysis} WHERE analysis_id IN (" . implode(',', $unique_analysis_ids) . ")";
- $resource = db_query($sql);
- while ($r = db_fetch_object($resource)) {
- $keys = array_keys($analysis_ids, $r->analysis_id);
- foreach ($keys as $k) {
- $view->result[$k]->analysis_nid = $r->nid;
- }
- }
- } // if there are any analysis'
- } //end of case for analysis NID
- //-----Feature-----------------------------------------------
- if (!empty($view->field['feature_nid'])) {
- // retrieve the feature_id for each record in the views current page
- $feature_ids = array();
- foreach ($view->result as $row_num => $row) {
- if (!empty($row->feature_id)) {
- //we're looking at feature id field already in table
- $feature_ids[$row_num] = $row->feature_id;
- }
- else {
- //we're looking at feature id added by field handler
- $feature_ids[$row_num] = $row->feature_feature_id;
- }
- }
- $unique_feature_ids = array_filter($feature_ids);
- $unique_feature_ids = array_unique($unique_feature_ids);
- if (!empty($unique_feature_ids)) {
- // Using the list of feature_ids from the view
- // lookup the NIDs from drupal
- // and add that to the results of the view
- $sql = "SELECT nid, feature_id FROM {chado_feature} WHERE feature_id IN (" . implode(',', $unique_feature_ids) . ")";
- $resource = db_query($sql);
- while ($r = db_fetch_object($resource)) {
- $keys = array_keys($feature_ids, $r->feature_id);
- foreach ($keys as $k) {
- $view->result[$k]->feature_nid = $r->nid;
- }
- }
- } // if there are any features
- } //end of case for feature NID
- //-----Library-----------------------------------------------
- if (!empty($view->field['library_nid'])) {
- // retrieve the library_id for each record in the views current page
- $library_ids = array();
- foreach ($view->result as $row_num => $row) {
- if (!empty($row->library_id)) {
- //we're looking at library id field already in table
- $library_ids[$row_num] = $row->library_id;
- }
- else {
- //we're looking at library id added by field handler
- $library_ids[$row_num] = $row->library_library_id;
- }
- }
- $unique_library_ids = array_filter($library_ids);
- $unique_library_ids = array_unique($unique_library_ids);
- if (!empty($unique_library_ids)) {
- // Using the list of library_ids from the view
- // lookup the NIDs from drupal
- // and add that to the results of the view
- $sql = "SELECT nid, library_id FROM {chado_library} WHERE library_id IN (" . implode(',', $unique_library_ids) . ")";
- $resource = db_query($sql);
- while ($r = db_fetch_object($resource)) {
- $keys = array_keys($library_ids, $r->library_id);
- foreach ($keys as $k) {
- $view->result[$k]->library_nid = $r->nid;
- }
- }
- } // if there are libraries
- } //end of case for library NID
- //-----Organism----------------------------------------------
- if (!empty($view->field['organism_nid'])) {
- // retrieve the organism_id for each record in the views current page
- $organism_ids = array();
- foreach ($view->result as $row_num => $row) {
- if (!empty($row->organism_id)) {
- //we're looking at organism id field already in table
- $organism_ids[$row_num] = $row->organism_id;
- }
- else {
- //we're looking at organism id added by field handler
- $organism_ids[$row_num] = $row->organism_organism_id;
- }
- }
- $unique_organism_ids = array_filter($organism_ids);
- $unique_organism_ids = array_unique($unique_organism_ids);
- if (!empty($unique_organism_ids)) {
- // Using the list of organism_ids from the view
- // lookup the NIDs from drupal
- // and add that to the results of the view
- $sql = "SELECT nid, organism_id FROM {chado_organism} WHERE organism_id IN (" . implode(',', $unique_organism_ids) . ")";
- $resource = db_query($sql);
- while ($r = db_fetch_object($resource)) {
- $keys = array_keys($organism_ids, $r->organism_id);
- foreach ($keys as $k) {
- $view->result[$k]->organism_nid = $r->nid;
- }
- }
- } // if there are organisms
- } //end of case for organism NID
- //-----Stock-------------------------------------------------
- if (!empty($view->field['stock_nid'])) {
- // retrieve the stock_id for each record in the views current page
- $stock_ids = array();
- foreach ($view->result as $row_num => $row) {
- if (!empty($row->stock_id)) {
- //we're looking at stock id field already in table
- $stock_ids[$row_num] = $row->stock_id;
- }
- else {
- //we're looking at stock id added by field handler
- $stock_ids[$row_num] = $row->stock_stock_id;
- }
- }
- $unique_stock_ids = array_filter($stock_ids);
- $unique_stock_ids = array_unique($unique_stock_ids);
- if (!empty($unique_stock_ids)) {
- // Using the list of stock_ids from the view
- // lookup the NIDs from drupal
- // and add that to the results of the view
- $sql = "SELECT nid, stock_id FROM {chado_stock} WHERE stock_id IN (" . implode(',', $unique_stock_ids) . ")";
- $resource = db_query($sql);
- while ($r = db_fetch_object($resource)) {
- $keys = array_keys($stock_ids, $r->stock_id);
- foreach ($keys as $k) {
- $view->result[$k]->stock_nid = $r->nid;
- }
- }
- } //if there are stocks
- } //end of case for stock NID
- return $view;
- }
- /**
- * Generates a dynamic data array for Views
- *
- * Purpose: This function is a hook used by the Views module. It populates and
- * returns a data array that specifies for the Views module the base table,
- * the tables it joins with and handlers. The data array is populated
- * using the data stored in the tripal_views tables.
- *
- * @return a data array formatted for the Views module
- *
- * @ingroup tripal_views
- */
- function tripal_views_views_data() {
- // Make sure all chado tables are integrated
- tripal_views_integrate_all_chado_tables();
- // Define Global Fields
- // Filter handler that lets the admin say:
- // "Show no results until they enter search parameters"
- $data['views']['search_results'] = array(
- 'title' => t('Search Results'),
- 'help' => t('Delay results until Apply/Search is clicked by the user.'),
- 'filter' => array(
- 'handler' => 'views_handler_filter_no_results',
- ),
- );
- $tvi_query = db_query('SELECT * FROM {tripal_views}');
- while ($tvi_row = db_fetch_object($tvi_query)) {
- // check to see if this is the lightest (drupal-style) priority setup for this table
- // if not then don't use this definition
- $lightest_priority_setup = tripal_views_is_lightest_priority_setup($tvi_row->setup_id, $tvi_row->table_name);
- if (!$lightest_priority_setup) {
- continue;
- }
- // ids we'll use for queries
- $setup_id = $tvi_row->setup_id;
- $mview_id = $tvi_row->mview_id;
- // holds the base table name and fields
- $base_table = '';
- $base_fields = array();
- // indicated whether the current table is a base table or not
- $is_base_table = $tvi_row->base_table;
- // populate the base table name and fields. If an $mview_id is given
- // then get the materialized view info, otherwise get the Chado table info
- if ($mview_id) {
- // get the base table name from the materialized view
- $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
- $mview_table = db_fetch_object(db_query($sql, $mview_id));
- $base_table = $mview_table->name;
- // get the columns in this materialized view. They are separated by commas
- // where the first word is the column name and the rest is the type
- $columns = explode(",", $mview_table->mv_specs);
- foreach ($columns as $column) {
- $column = trim($column); // trim trailing and leading spaces
- preg_match("/^(.*?)\ (.*?)$/", $column, $matches);
- $column_name = $matches[1];
- $column_type = $matches[2];
- $base_fields[$column_name] = array(
- 'column_name' => $column_name,
- 'type' => $column_type,
- );
- }
- // get the field name and descriptions
- $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
- $query = db_query($sql, $setup_id);
- while ($field = db_fetch_object($query)) {
- $base_fields[$field->column_name]['name'] = $field->name;
- $base_fields[$field->column_name]['help'] = $field->description;
- }
- }
- else {
- $base_table = $tvi_row->table_name;
- // The chado table could be a regular Chado table or a custom table
- // in the chado database. Therefore we'll check both
- $table_desc = tripal_core_get_chado_table_schema($base_table);
- if (!$table_desc) {
- $table_desc = tripal_get_chado_custom_schema($base_table);
- }
- $fields = $table_desc['fields'];
- if (!is_array($fields)) {
- $fields = array();
- watchdog('tripal_views', 'No fields were described for this table (%table) through the Tripal Schema API.', array('%table' => $base_table), WATCHDOG_ERROR);
- }
- foreach ($fields as $column => $attrs) {
- $base_fields[$column] = array(
- 'column_name' => $column,
- 'type' => $attrs['type'],
- );
- }
- // get the field name and descriptions
- $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
- $query = db_query($sql, $setup_id);
- while ($field = db_fetch_object($query)) {
- $base_fields[$field->column_name]['name'] = $field->name;
- $base_fields[$field->column_name]['help'] = $field->description;
- }
- }
- // Setup the base table info in the data array
- $data[$base_table]['table']['group'] = t("$tvi_row->name");
- if ($is_base_table) {
- $data[$base_table]['table']['base'] = array(
- 'group' => "$tvi_row->name",
- 'title' => "$tvi_row->name",
- 'help' => $tvi_row->comment,
- );
- }
- else {
- $data[$base_table]['table'] = array(
- 'group' => "$tvi_row->name",
- 'title' => "$tvi_row->name",
- 'help' => $tvi_row->comment,
- );
- }
- // first add the fields
- foreach ($base_fields as $column_name => $base_field) {
- $data[$base_table][$column_name] = array(
- 'title' => t($base_field['name']),
- 'help' => t($base_field['help']),
- 'field' => array(
- 'click sortable' => TRUE,
- ),
- );
- // now add the handlers
- $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
- $handlers = db_query($sql, $setup_id, $column_name);
- while ($handler = db_fetch_object($handlers)) {
- $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
- // Add in any additional arguments
- // This should be a serialized array including (at a minimum) name => <handler name>
- if ($handler->arguments) {
- $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
- }
- };
- }
- // now add the joins
- $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
- $joins = db_query($sql, $setup_id);
- if (!isset($joins)) {
- $joins = array();
- }
- while ($join = db_fetch_object($joins)) {
- $left_table = $join->left_table;
- $left_field = $join->left_field;
- $base_field = $join->base_field;
- $handler = $join->handler;
- // add join entry
- $data[$base_table]['table']['join'][$left_table] = array(
- 'left_field' => $left_field,
- 'field' => $base_field,
- );
- if ($handler) {
- $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
- }
- // check to see if the join table is one that correlates with Drupal nodes
- // if so, there will be a chado_<table_name> table in the Drupal database
- // if there is, then we need to add the linking join information
- if (db_table_exists("chado_$left_table")) {
- // join the mview to the linker table
- $data[$base_table]['table']['join']["chado_$left_table"] = array(
- 'left_field' => $left_field,
- 'field' => $base_field,
- );
- }
- }
- }
- // TEMPORARY: needed to join chado base tables to node linking tables
- // currently done using old-style data arrays
- $data = tripal_views_TEMPORARY_chado_linking_data($data);
- return $data;
- }
- /**
- *
- * @ingroup tripal_views
- */
- function tripal_views_views_data_alter(&$data) {
- $tvi_query = db_query('SELECT * FROM {tripal_views}');
- // iterate through the views that we manage
- while ($tvi_row = db_fetch_object($tvi_query)) {
- //ids we'll use for queries
- $mview_id = $tvi_row->mview_id;
- $setup_id = $tvi_row->setup_id;
- // iterate through the columns and alter the existing data array for
- // joins to other tables
- $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
- $joins = db_query($sql, $setup_id);
- while ($join = db_fetch_object($joins)) {
- $left_table = $join->left_table;
- $left_field = $join->left_field;
- $base_field = $join->base_field;
- $base_table = $join->base_table;
- // add the recipricol join entries for each column
- if (array_key_exists($left_table, $data)) {
- $data[$left_table]['table']['join'][$base_table] = array(
- 'left_field' => $base_field,
- 'field' => $left_field,
- );
- }
- // check to see if this table is one that correlates with Drupal nodes
- // if so, there will be a chado_<table_name> table in the Drupal database
- // if there is, then we need to add the linking join information. We did
- // this step in the hook_views_data function above, but now we need
- // to add the reciprical joins
- if (db_table_exists("chado_$left_table")) {
- // join the linker table to the mview
- if (array_key_exists("chado_$left_table", $data)) {
- $data["chado_$left_table"]['table']['join'][$base_table] = array(
- 'left_field' => $base_field,
- 'field' => $left_field,
- );
- // Join the node table to the view by way of the chado linker table
- $data['node']['table']['join'][$base_table] = array(
- 'left_table' => "chado_$left_table",
- 'left_field' => 'nid',
- 'field' => 'nid',
- );
- }
- }
- }
- }
- return $data;
- }
- /**
- * Implementation of hook_views_plugins().
- */
- function tripal_views_views_plugins() {
- $tc_path = drupal_get_path('module', 'tripal_views');
- $style_defaults = array(
- 'path' => $tc_path . '/views_data_export/plugins',
- 'parent' => 'views_data_export',
- 'theme' => 'views_data_export',
- 'theme path' => $tc_path . '/views_data_export/theme',
- 'theme file' => 'tripal_views_data_export.theme.inc',
- 'uses row plugin' => FALSE,
- 'uses fields' => TRUE,
- 'uses options' => TRUE,
- 'type' => 'data_export',
- );
- // add FASTA format as a new style for the existing views_export_data Display
- return array(
- 'style' => array(
- 'views_data_export_fasta' => array(
- 'title' => t('FASTA file'),
- 'help' => t('Display results in FASTA format. All fields in results are on the definition line while the feature.residues field must be present .'),
- 'handler' => 'tripal_views_plugin_style_export_fasta',
- // Views Data Export element that will be used to set additional headers when serving the feed.
- 'export headers' => array('Content-type: text/plain; charset=utf-8'),
- // Views Data Export element mostly used for creating some additional classes and template names.
- 'export feed type' => 'fasta',
- 'export feed text' => 'FASTA',
- 'export feed file' => '%view.fna',
- 'export feed icon' => $tc_path . '/views_data_export/images/fasta.png',
- 'additional themes' => array(
- 'views_data_export_fasta_header' => 'style',
- 'views_data_export_fasta_body' => 'style',
- 'views_data_export_fasta_footer' => 'style',
- ),
- 'additional themes base' => 'views_data_export_fasta',
- ) + $style_defaults,
- ),
- );
- }
- /**
- * Implementation of hook_views_pre_view().
- */
- function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
- // merge the $_GET and $_POST into the $_GET. This is because
- // Views and Views Data Export modules only uses the $_GET variable but
- // file uploads require $_POST. We need to make sure these two modules
- // have access to everything needed for this view to work properlys
- $_GET = array_merge($_GET, $_POST);
- }
- /**
- * Implementation of hook_views_pre_build().
- */
- /* function tripal_views_views_pre_render(&$view, &$display_id, &$args){
- // we want to add to the bottom of the views the form for downloading
- // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
- // Export module provides small images at the bottom, but we want to provide
- // a more intutitive interface for getting different file formats
- $form = drupal_get_form('tripal_views_data_export_download_form',$view,$display_id,$args);
- $view->attachment_after = $form;
- }*/
- /**
- * the Download Views data export form
- */
- function tripal_views_data_export_download_form(&$form_state, $view, $display_id, $args) {
- $form = array();
- $urls = array();
- // get any export_data_export displays
- $displays = $view->display;
- $options = array();
- $default = '';
- $current_display = $view->current_display;
- foreach ($displays as $name => $display) {
- if (preg_match("/^views_data_export/", $name)) {
- // only add this display to the form if it is attached
- $display_options = $display->display_options;
- if (strcmp($display_options['displays'][$current_display], $current_display) != 0) {
- continue;
- }
- // set the first item as default
- if (!$default) {
- $default = $display->id;
- }
- $path = $display->display_options['path'];
- $query = $view->get_exposed_input(); // retrieves elements in $_GET array
- $urls[$display->id]['path'] = $path;
- $urls[$display->id]['query'] = $query;
- // add the new item to the options array
- $options[$display->id] = $display->display_title;
- }
- }
- // only generate the form if we have views_data_export displays attached
- // to this view
- if (count($options) > 0) {
- $form_state['storage']['urls'] = $urls;
- $form['#cache'] = TRUE;
- // we want the form to redirect to a new window
- $form['#attributes']['target'] = "_blank";
- // now build the form elements
- $form['downloads'] = array(
- '#type' => 'fieldset',
- '#title' => 'Download Results',
- '#collapsible' => TRUE,
- '#collapsed' => FALSE
- );
- $form['downloads']['file_type'] = array(
- '#title' => t('File format'),
- '#type' => 'radios',
- '#options' => $options,
- '#required' => TRUE,
- '#default_value' => $default,
- '#description' => t('Please select a file format to download'),
- );
- $form['downloads']['submit'] = array(
- '#value' => t('Download Results'),
- '#type' => 'submit',
- );
- }
- return $form;
- }
- /**
- * Submit for the Download Views data export form
- */
- function tripal_views_data_export_download_form_submit($form, &$form_state) {
- $urls = $form_state['storage']['urls'];
- $display_id = $form_state['values']['file_type'];
- drupal_goto($urls[$display_id]['path'], $urls[$display_id]['query']);
- }
|