Quellcode durchsuchen

Fixed problem where data from file uploads weren't being passed along to the filters for the data exports

stephen vor 13 Jahren
Ursprung
Commit
2691a3677d

+ 4 - 0
base/tripal_views/tripal_views.module

@@ -2,6 +2,7 @@
 
 require_once "tripal_views_integration.inc";
 require_once "tripal_views.views.inc";
+require_once "tripal_views_form_elements.inc";
 
 /**
  * Implements hook_menu()
@@ -100,5 +101,8 @@ function tripal_views_theme () {
          'arguments' => array('form' => NULL),
          'template'  => 'tripal_views_data_export_download_form',
 	   ),
+      'file_upload_combo' => array(
+        'arguments' => array('element' => NULL)
+      ),
    );
 }

+ 20 - 6
base/tripal_views/tripal_views.views.inc

@@ -197,6 +197,12 @@ function tripal_views_views_pre_render	(&$view) {
 		// @see file: tripal_views.views.inc
 		tripal_views_add_node_ids_to_view ($view);
 		
+   // 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;
 }
 
 /**
@@ -517,7 +523,6 @@ function tripal_views_views_data(){
         }
       }
     }
-//dpm($data);
     return $data;
 }
 /**
@@ -631,15 +636,18 @@ function tripal_views_views_pre_view(&$view,&$display_id,&$args){
    // 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;
-}
+}*/
 /**
  * 
  */
@@ -657,8 +665,14 @@ function tripal_views_data_export_download_form(&$form_state, $view,$display_id,
          if(!$default){
             $default = $display->id;
          }
-         // add the data export URL to the URLs array
-         $query = $view->get_exposed_input();
+         // add the data export URL to the URLs array.  We need to first 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);
+         $query = $view->get_exposed_input();  // retrieves elements in $_GET array
+
          $path = $display->display_options['path'];
          $urls[$display->id]['path'] = $path;
          $urls[$display->id]['query'] = $query;

+ 22 - 24
base/tripal_views/views/handlers/views_handler_filter_file_upload.inc

@@ -25,22 +25,15 @@ class views_handler_filter_file_upload extends views_handler_filter {
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
     
-    // we'll provide a single text area for this field.
-    // in the exposed_form function we'll add in the file upload button
-    $form['value'] = array(
-       '#type' => 'textarea',
+    $this->value_form = array(
+       '#type' => 'file_upload_combo',
        '#title' => $this->options['expose']['label'],
        '#default_value' => $this->value,
        '#multiple' => FALSE,
        '#description' => t('Provide search values for ' . $this->options['expose']['label'] . 
          '. Please place each search item on a separate line or separated by commas.'),
-    ); 
-    $form[$this->options['field'] . '_upload'] = array(
-      '#type' => 'file',
-      '#title' => $this->options['expose']['label'] . ' File upload',
-      '#description' => t('Upload a file to provide search values for ' . $this->options['expose']['label'] . 
-         '. Please place each search item on a separate line.'),
     );
+    $form['value'] = &$this->value_form;
   }
 
   /**
@@ -81,40 +74,45 @@ class views_handler_filter_file_upload extends views_handler_filter {
    *
    */
   function query() {
-    $this->ensure_my_table();
-
+     $this->ensure_my_table();
      $field = "$this->table.$this->real_field";
+
+     // get the form element value
+     $value = $this->value[0];
+
+     // the form element value has sub values, so get those
+     $items =  $value['items'];
+     $file_path = $value['file_path'];
+
      $holders = array();
      $values = array();
 
      // get the file upload content if one has been provided
-     $file = file_save_upload($this->field.'_upload',array());
-     if($file){
-        $fh = fopen($file->filepath,'r');
-
+     if($file_path){
+        $fh = fopen($file_path,'r');
         while($line = fgets($fh)){
           $line = trim($line);
           $values[] = $line;
         }
      } 
      // if a file upload has not been provided then use the value in the textarea
-     if($this->value[0]){
-        $items = $this->value[0];
+     if($items){
+
         // remove extra spaces and new lines
         $items = preg_replace("/\s+,/",",",$items);
         $items = preg_replace("/\s+\n/","\n",$items);
         $items = preg_replace("/,\n/","\n",$items);
-        // add to the array of values
+
+        // in the event the user uploaded a file and provided items in the
+        // textbox then we need to merge these two lists
         $vals = preg_split("/[\n,]+/",$items);
         $values = array_merge($values,$vals);
      }
+     // iterate through all of the values and generate the corresponding
+     // sprintf style holders
      for($i = 0 ; $i < count($values); $i++){
         $values[$i] = trim($values[$i]);
-        if (preg_match('/^[\d\.]+$/',$values[$i])) {
-           $holders[] = '%d';
-        } else {
-           $holders[] = "'%s'";
-        }
+        $holders[] = "'%s'";
      }
      // if we have any values supplied then update the where clause for
      // the views query