Browse Source

Added filter_file_upload handler to tripal core

stephen 13 years ago
parent
commit
eea29cfd38

+ 3 - 0
base/tripal_core/tripal_core.views.inc

@@ -147,6 +147,9 @@ function tripal_core_views_handlers() {
      'chado_views_handler_filter_numeric' => array(
       'parent' => 'views_handler_filter_numeric',
      ),
+     'views_handler_filter_file_upload' => array(
+      'parent' => 'views_handler_filter',
+     ),
      // Sort Handlers
      'chado_views_handler_sort' => array(
       'parent' => 'views_handler_sort'

+ 1 - 1
base/tripal_core/views/handlers/views_handler_filter_chado_select_string.inc

@@ -155,4 +155,4 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
       }
     }
   }
-}
+}

+ 73 - 0
base/tripal_core/views/handlers/views_handler_filter_file_upload.inc

@@ -0,0 +1,73 @@
+<?php
+
+/**
+ * Purpose: This Handler provides a file upload field.
+ *
+ * @ingroup views_filter_handlers
+ * @ingroup tripal_core
+ */
+class views_handler_filter_file_upload extends views_handler_filter {
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+  }
+  
+ /**
+  * Defines the value field in both the views filter options form
+  *   and the exposed form
+  */
+  function value_form(&$form, &$form_state) {
+    parent::value_form($form, $form_state);
+    
+    // add the file upload form element and set the encoding type for the
+    // form to be multipart/form-data
+    $form['value'] = array(
+      '#type' => 'file',
+      '#title' => $this->options['expose']['label'],
+    );
+    $form['#attributes']['enctype'] = 'multipart/form-data';
+    $form['#method'] = 'POST';
+  }
+
+ /**
+  * Ensures the select list gets rendered when the filter is exposed
+  */
+  function exposed_form(&$form, &$form_state) {
+    if (empty($this->options['exposed'])) {
+      return;
+    }
+    $value = $this->options['expose']['identifier'];
+    $this->value_form($form, $form_state);
+    $form[$value] = $form['value'];
+    unset($form[$value]['#title']);
+
+    $this->exposed_translate($form[$value], 'value');
+  }
+
+ /**
+  *
+  */
+  function query() {
+     $file = file_save_upload($this->field,array());
+     $field = "$this->table.$this->real_field";
+
+     if($file){
+        $fh = fopen($file->filepath,'r');
+        $holders = array();
+        $values = array();
+        while($line = fgets($fh)){
+          $line = trim($line);
+          if (preg_match('/^[\d\.]+$/',$v)) {
+            $holders[] = '%d';
+          } else {
+            $holders[] = "'%s'";
+          }
+          // don't include duplicates
+          $values[] = $line;
+        }
+        $where = "$field IN (".implode(", ",$holders).")";
+        $this->query->add_where($this->options['group'], $where, $values);
+     }
+  }
+}

+ 5 - 1
base/tripal_core/views/handlers/views_handler_join_chado_through_linking.inc

@@ -1,5 +1,9 @@
 <?php
 
+include_once("/var/www/sites/all/modules/views/includes/base.inc");
+include_once("/var/www/sites/all/modules/views/includes/handlers.inc");
+
+
 /**
  * Handler to allow joins between records via a linking table
  *
@@ -109,4 +113,4 @@ class views_handler_join_chado_through_linking extends views_join {
     return $output;
   }
  
-}
+}