Browse Source

Updated Views Query for filtering by TripalFieldQuery class

Stephen Ficklin 8 years ago
parent
commit
f19427a2b8

+ 0 - 13
tripal/includes/TripalField.inc

@@ -637,18 +637,5 @@ class TripalField {
   public static function viewsDataAlter(&$data, $field, $entity_info) {
 
   }
-  
-  /**
-   * Sort data by the field
-   *
-   * This function takes an array of data and performs sorting by the
-   * specified field
-   * 
-   * @return
-   * 
-   */
-  public static function sort(&$data, $criteria = 'ASC') {
-  
-  }
 
 }

+ 2 - 0
tripal/includes/TripalFieldQuery.inc

@@ -18,6 +18,8 @@ class TripalFieldQuery {
   protected $fs_order = array();
   // An associative array of the filters to apply.
   protected $conditions = array();
+  // An associative array of the sorting.
+  protected $orderBy = array();
 
   /**
    *

+ 5 - 14
tripal/tripal_views_query.inc

@@ -35,6 +35,9 @@ class tripal_views_query extends views_plugin_query {
     // must be with the content_type field.
     $query = new TripalFieldQuery();
     $query->fieldCondition('content_type', $bundle->id);
+    foreach ($view->filter as $field_name => $handler) {
+      $query->fieldCondition($field_name, $handler->value, $handler->operator);
+    }
 
     $results = $query->execute();
     foreach ($results['TripalEntity'] as $entity_id => $stub) {
@@ -45,10 +48,6 @@ class tripal_views_query extends views_plugin_query {
       $entity = tripal_load_entity('TripalEntity', array('id' => $entity_id));
       $entity = reset($entity);
 
-      // Get the filters
-      $filters = $view->filter;
-      $exclude = FALSE;
-      
       // Iterate through the fields that are added to the view and attach those
       // to the entity.  After attaching we can get the value and include
       // it in the output results.
@@ -59,21 +58,13 @@ class tripal_views_query extends views_plugin_query {
         $items = field_get_items('TripalEntity', $entity, $field_name);
         $value = $items[0]['value'];
 
-        // Filter the $value here
-        $filter = key_exists($field_name, $filters) ? $filters[$field_name] : NULL;
-        if ($filter && trim($filter->value)) {
-          $exclude = $filter->exclude($value);
-          continue;
-        }
-        
         $row->entity = $entity;
         $row->$field_name = $value;
       }
 
       // Add the row to the results list.
-      if (!$exclude) {
-        $view->result[] = $row;
-      }
+      $view->result[] = $row;
+
     }
 
     $view->total_rows = count($view->result);

+ 0 - 25
tripal/views_handlers/tripal_views_handler_filter_entity_string.inc

@@ -244,29 +244,4 @@ class tripal_views_handler_filter_entity_string extends views_handler_filter {
 
   function op_empty($field) {
   }
-
-  function exclude ($value) {
-    $op = $this->operator;
-    $input = $this->value;
-    switch ($op) {
-      case '=':
-        return $value == $input ? FALSE : TRUE;
-      case '!=':
-        return $value != $input ? FALSE : TRUE;
-      case 'contains':
-        return preg_match("/$input/", $value) ? FALSE : TRUE;
-      case 'not':
-        return preg_match("/$input/", $value) ? TRUE : FALSE;
-      case 'starts':
-        return preg_match("/^$input/", $value) ? FALSE : TRUE;
-      case 'not_starts':
-        return preg_match("/^$input/", $value) ? TRUE : FALSE;
-      case 'ends':
-        return preg_match("/$input$/", $value) ? FALSE : TRUE;
-      case 'not_ends':
-        return preg_match("/$input$/", $value) ? TRUE : FALSE;
-        
-      return FALSE;
-    }
-  }
 }

+ 10 - 0
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -365,6 +365,14 @@ class chado_base__organism_id extends TripalField {
     return $element;
   }
 
+  /**
+   *
+   * @param unknown $data
+   * @param string $criteria
+   */
+  public static function sort(&$data, $criteria = 'ASC') {
+
+  }
 }
 
 
@@ -391,4 +399,6 @@ function chado_base__organism_id_widget_validate($element, &$form_state) {
   if (!$organism_id) {
     form_error($element, t("Please specify an organism."));
   }
+
+
 }

+ 0 - 9
tripal_chado/views_handlers/chado_views_handler_field_chado_base__organism_id.inc

@@ -1,9 +0,0 @@
-<?php
-class chado_views_handler_field_chado_base__organism_id extends views_handler_field {
-
-  function render($values) {
-    $value = $this->get_value($values);
-
-    return $value['label'];
-  }
-}